1 ################################################################################
2 # Copyright 2024 highstreet technologies
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
8 # http://www.apache.org/licenses/LICENSE-2.0
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.
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")
22 help: ## Show the help.
23 @echo "Usage: make <target>"
26 @fgrep "##" Makefile | fgrep -v fgrep
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
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]
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/
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/
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
64 watch: ## Run tests on every change.
65 ls **/**.py | entr $(ENV_PREFIX)pytest -s -vvv -l --tb=long --maxfail=1 tests/
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 {} \;
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 ..."
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
95 @echo "!!! Please run 'source .oam/bin/activate' to enable the OAM environment !!!"
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}"
107 @git push -u origin HEAD --tags
108 @echo "Github Actions will detect the new tag and release the new version."
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
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
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'"
135 init: ## Initialize the project based on an application template.
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/