2 ENV_PREFIX=$(shell python -c "if __import__('pathlib').Path('.venv/bin/pip').exists(): print('.venv/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 virtualenv' 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 {} \;
68 virtualenv: ## Create a virtual environment.
69 @if [ "$(USING_POETRY)" ]; then poetry install && exit; fi
70 @echo "creating virtualenv ..."
72 @python3 -m venv .venv
73 @./.venv/bin/pip install -U pip
74 @./.venv/bin/pip install -e .[test]
76 @echo "!!! Please run 'source .venv/bin/activate' to enable the environment !!!"
79 release: ## Create a new tag for release.
80 @echo "WARNING: This operation will create s version tag and push to github"
81 @read -p "Version? (provide the next x.y.z semver) : " TAG
82 @echo "$${TAG}" > network_generation/VERSION
83 @$(ENV_PREFIX)gitchangelog > HISTORY.md
84 @git add network_generation/VERSION HISTORY.md
85 @git commit -m "release: version $${TAG} 🚀"
86 @echo "creating git tag : $${TAG}"
88 @git push -u origin HEAD --tags
89 @echo "Github Actions will detect the new tag and release the new version."
92 docs: ## Build the documentation.
93 @echo "building documentation ..."
94 @$(ENV_PREFIX)mkdocs build
95 URL="site/index.html"; xdg-open $$URL || sensible-browser $$URL || x-www-browser $$URL || gnome-open $$URL || open $$URL
97 .PHONY: switch-to-poetry
98 switch-to-poetry: ## Switch to poetry package manager.
99 @echo "Switching to poetry ..."
100 @if ! poetry --version > /dev/null; then echo 'poetry is required, install from https://python-poetry.org/'; exit 1; fi
102 @poetry init --no-interaction --name=a_flask_test --author=rochacbruno
103 @echo "" >> pyproject.toml
104 @echo "[tool.poetry.scripts]" >> pyproject.toml
105 @echo "network_generation = 'network_generation.__main__:main'" >> pyproject.toml
106 @cat requirements.txt | while read in; do poetry add --no-interaction "$${in}"; done
107 @cat requirements-test.txt | while read in; do poetry add --no-interaction "$${in}" --dev; done
108 @poetry install --no-interaction
109 @mkdir -p .github/backup
110 @mv requirements* .github/backup
111 @mv setup.py .github/backup
112 @echo "You have switched to https://python-poetry.org/ package manager."
113 @echo "Please run 'poetry shell' or 'poetry run network_generation'"
116 init: ## Initialize the project based on an application template.
120 # This project has been generated from rochacbruno/python-project-template
121 # __author__ = 'rochacbruno'
122 # __repo__ = https://github.com/rochacbruno/python-project-template
123 # __sponsor__ = https://github.com/sponsors/rochacbruno/