Rename topology in schema and config to SDO ref
[oam.git] / code / network-generator / Makefile
1 ################################################################################
2 # Copyright 2024 highstreet technologies 
3 #
4 # Licensed under the Apache License, Version 2.0 (the 'License');
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an 'AS IS' BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 #
16
17 .ONESHELL:
18 ENV_PREFIX=$(shell python -c "if __import__('pathlib').Path('.oam/bin/pip').exists(): print('.oam/bin/')")
19 USING_POETRY=$(shell grep "tool.poetry" pyproject.toml && echo "yes")
20
21 .PHONY: help
22 help:             ## Show the help.
23         @echo "Usage: make <target>"
24         @echo ""
25         @echo "Targets:"
26         @fgrep "##" Makefile | fgrep -v fgrep
27
28
29 .PHONY: show
30 show:             ## Show the current environment.
31         @echo "Current environment:"
32         @if [ "$(USING_POETRY)" ]; then poetry env info && exit; fi
33         @echo "Running using $(ENV_PREFIX)"
34         @$(ENV_PREFIX)python -V
35         @$(ENV_PREFIX)python -m site
36
37 .PHONY: install
38 install:          ## Install the project in dev mode.
39         @if [ "$(USING_POETRY)" ]; then poetry install && exit; fi
40         @echo "Don't forget to run 'make virtual_env_4_oam' if you got errors."
41         $(ENV_PREFIX)pip install -e .[test]
42
43 .PHONY: format
44 format:           ## Format code using black & isort.
45         $(ENV_PREFIX)isort network_generation/
46         $(ENV_PREFIX)black -l 79 network_generation/
47         $(ENV_PREFIX)black -l 79 tests/
48
49 .PHONY: lint
50 lint:             ## Run pep8, black, mypy linters.
51         $(ENV_PREFIX)flake8 network_generation/
52         $(ENV_PREFIX)flake8 tests/
53         $(ENV_PREFIX)black -l 79 --check network_generation/
54         $(ENV_PREFIX)black -l 79 --check tests/
55         $(ENV_PREFIX)mypy --ignore-missing-imports --disallow-untyped-defs --check-untyped-def network_generation/
56
57 .PHONY: test
58 test:             ## Run tests and generate coverage report.
59         $(ENV_PREFIX)pytest -v --cov-config .coveragerc --cov=network_generation -l --tb=short --maxfail=1 tests/
60         $(ENV_PREFIX)coverage xml
61         $(ENV_PREFIX)coverage html
62
63 .PHONY: watch
64 watch:            ## Run tests on every change.
65         ls **/**.py | entr $(ENV_PREFIX)pytest -s -vvv -l --tb=long --maxfail=1 tests/
66
67 .PHONY: clean
68 clean:            ## Clean unused files.
69         @find ./ -name '*.pyc' -exec rm -f {} \;
70         @find ./ -name '__pycache__' -exec rm -rf {} \;
71         @find ./ -name 'Thumbs.db' -exec rm -f {} \;
72         @find ./ -name '*~' -exec rm -f {} \;
73         @rm -rf .cache
74         @rm -rf .pytest_cache
75         @rm -rf .mypy_cache
76         @rm -rf build
77         @rm -rf dist
78         @rm -rf *.egg-info
79         @rm -rf htmlcov
80         @rm -rf .tox/
81         @rm -rf docs/_build
82
83 .PHONY: virtual_env_4_oam
84 virtual_env_4_oam:       ## Create a virtual environment for O-RAN-SC OAM project.
85         @if [ "$(USING_POETRY)" ]; then poetry install && exit; fi
86         @echo "Creating a virtual environment for O-RAN-SC OAM project ..."
87         @rm -rf .oam
88         @python3 -m venv .oam
89         @./.oam/bin/pip install -U pip
90         @./.oam/bin/pip install -e .[test]
91         @./.oam/bin/pip install -r requirements.txt
92         @./.oam/bin/pip install -r requirements-test.txt
93
94         @echo
95         @echo "!!! Please run 'source .oam/bin/activate' to enable the OAM environment !!!"
96
97 .PHONY: release
98 release:          ## Create a new tag for release.
99         @echo "WARNING: This operation will create s version tag and push to github"
100         @read -p "Version? (provide the next x.y.z semver) : " TAG
101         @echo "$${TAG}" > network_generation/VERSION
102         @$(ENV_PREFIX)gitchangelog > HISTORY.md
103         @git add network_generation/VERSION HISTORY.md
104         @git commit -m "release: version $${TAG} ðŸš€"
105         @echo "creating git tag : $${TAG}"
106         @git tag $${TAG}
107         @git push -u origin HEAD --tags
108         @echo "Github Actions will detect the new tag and release the new version."
109
110 .PHONY: docs
111 docs:             ## Build the documentation.
112         @echo "building documentation ..."
113         @$(ENV_PREFIX)mkdocs build
114         URL="site/index.html"; xdg-open $$URL || sensible-browser $$URL || x-www-browser $$URL || gnome-open $$URL || open $$URL
115
116 .PHONY: switch-to-poetry
117 switch-to-poetry: ## Switch to poetry package manager.
118         @echo "Switching to poetry ..."
119         @if ! poetry --version > /dev/null; then echo 'poetry is required, install from https://python-poetry.org/'; exit 1; fi
120         @rm -rf .oam
121         @poetry init --no-interaction --name=a_flask_test --author=rochacbruno
122         @echo "" >> pyproject.toml
123         @echo "[tool.poetry.scripts]" >> pyproject.toml
124         @echo "network_generation = 'network_generation.__main__:main'" >> pyproject.toml
125         @cat requirements.txt | while read in; do poetry add --no-interaction "$${in}"; done
126         @cat requirements-test.txt | while read in; do poetry add --no-interaction "$${in}" --dev; done
127         @poetry install --no-interaction
128         @mkdir -p .github/backup
129         @mv requirements* .github/backup
130         @mv setup.py .github/backup
131         @echo "You have switched to https://python-poetry.org/ package manager."
132         @echo "Please run 'poetry shell' or 'poetry run network_generation'"
133
134 .PHONY: init
135 init:             ## Initialize the project based on an application template.
136         @./.github/init.sh
137
138
139 # This project has been generated from rochacbruno/python-project-template
140 # __author__ = 'rochacbruno'
141 # __repo__ = https://github.com/rochacbruno/python-project-template
142 # __sponsor__ = https://github.com/sponsors/rochacbruno/