2 ENV_PREFIX=$(shell python -c "if __import__('pathlib').Path('.oam/bin/pip').exists(): print('.oam/bin/')")
3 USING_POETRY=$(shell grep "tool.poetry" pyproject.toml && echo "yes")
6 help: ## Show the help.
7 @echo "Usage: make <target>"
10 @fgrep "##" Makefile | fgrep -v fgrep
14 show: ## Show the current environment.
15 @echo "Current environment:"
16 @if [ "$(USING_POETRY)" ]; then poetry env info && exit; fi
17 @echo "Running using $(ENV_PREFIX)"
18 @$(ENV_PREFIX)python -V
19 @$(ENV_PREFIX)python -m site
22 install: ## Install the project in dev mode.
23 @if [ "$(USING_POETRY)" ]; then poetry install && exit; fi
24 @echo "Don't forget to run 'make virtual_env_4_oam' if you got errors."
25 $(ENV_PREFIX)pip install -e .[test]
28 format: ## Format code using black & isort.
29 $(ENV_PREFIX)isort network_generation/
30 $(ENV_PREFIX)black -l 79 network_generation/
31 $(ENV_PREFIX)black -l 79 tests/
34 lint: ## Run pep8, black, mypy linters.
35 $(ENV_PREFIX)flake8 network_generation/
36 $(ENV_PREFIX)flake8 tests/
37 $(ENV_PREFIX)black -l 79 --check network_generation/
38 $(ENV_PREFIX)black -l 79 --check tests/
39 $(ENV_PREFIX)mypy --ignore-missing-imports --disallow-untyped-defs --check-untyped-def network_generation/
42 test: lint ## Run tests and generate coverage report.
43 $(ENV_PREFIX)pytest -v --cov-config .coveragerc --cov=network_generation -l --tb=short --maxfail=1 tests/
44 $(ENV_PREFIX)coverage xml
45 $(ENV_PREFIX)coverage html
48 watch: ## Run tests on every change.
49 ls **/**.py | entr $(ENV_PREFIX)pytest -s -vvv -l --tb=long --maxfail=1 tests/
52 clean: ## Clean unused files.
53 @find ./ -name '*.pyc' -exec rm -f {} \;
54 @find ./ -name '__pycache__' -exec rm -rf {} \;
55 @find ./ -name 'Thumbs.db' -exec rm -f {} \;
56 @find ./ -name '*~' -exec rm -f {} \;
67 .PHONY: virtual_env_4_oam
68 virtual_env_4_oam: ## Create a virtual environment for O-RAN-SC OAM project.
69 @if [ "$(USING_POETRY)" ]; then poetry install && exit; fi
70 @echo "Creating a virtual environment for O-RAN-SC OAM project ..."
73 @./.oam/bin/pip install -U pip
74 @./.oam/bin/pip install -e .[test]
75 @./.oam/bin/pip install -r requirements.txt
76 @./.oam/bin/pip install -r requirements-test.txt
79 @echo "!!! Please run 'source .oam/bin/activate' to enable the OAM environment !!!"
82 release: ## Create a new tag for release.
83 @echo "WARNING: This operation will create s version tag and push to github"
84 @read -p "Version? (provide the next x.y.z semver) : " TAG
85 @echo "$${TAG}" > network_generation/VERSION
86 @$(ENV_PREFIX)gitchangelog > HISTORY.md
87 @git add network_generation/VERSION HISTORY.md
88 @git commit -m "release: version $${TAG} 🚀"
89 @echo "creating git tag : $${TAG}"
91 @git push -u origin HEAD --tags
92 @echo "Github Actions will detect the new tag and release the new version."
95 docs: ## Build the documentation.
96 @echo "building documentation ..."
97 @$(ENV_PREFIX)mkdocs build
98 URL="site/index.html"; xdg-open $$URL || sensible-browser $$URL || x-www-browser $$URL || gnome-open $$URL || open $$URL
100 .PHONY: switch-to-poetry
101 switch-to-poetry: ## Switch to poetry package manager.
102 @echo "Switching to poetry ..."
103 @if ! poetry --version > /dev/null; then echo 'poetry is required, install from https://python-poetry.org/'; exit 1; fi
105 @poetry init --no-interaction --name=a_flask_test --author=rochacbruno
106 @echo "" >> pyproject.toml
107 @echo "[tool.poetry.scripts]" >> pyproject.toml
108 @echo "network_generation = 'network_generation.__main__:main'" >> pyproject.toml
109 @cat requirements.txt | while read in; do poetry add --no-interaction "$${in}"; done
110 @cat requirements-test.txt | while read in; do poetry add --no-interaction "$${in}" --dev; done
111 @poetry install --no-interaction
112 @mkdir -p .github/backup
113 @mv requirements* .github/backup
114 @mv setup.py .github/backup
115 @echo "You have switched to https://python-poetry.org/ package manager."
116 @echo "Please run 'poetry shell' or 'poetry run network_generation'"
119 init: ## Initialize the project based on an application template.
123 # This project has been generated from rochacbruno/python-project-template
124 # __author__ = 'rochacbruno'
125 # __repo__ = https://github.com/rochacbruno/python-project-template
126 # __sponsor__ = https://github.com/sponsors/rochacbruno/