2 ENV_PREFIX=$(shell python3 -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 fmt: ## 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)black -l 79 --check network_generation/
37 $(ENV_PREFIX)black -l 79 --check tests/
38 $(ENV_PREFIX)mypy --ignore-missing-imports network_generation/
41 test: lint ## Run tests and generate coverage report.
42 $(ENV_PREFIX)pytest -v --cov-config .coveragerc --cov=network_generation -l --tb=short --maxfail=1 tests/
43 $(ENV_PREFIX)coverage xml
44 $(ENV_PREFIX)coverage html
47 watch: ## Run tests on every change.
48 ls **/**.py | entr $(ENV_PREFIX)pytest -s -vvv -l --tb=long --maxfail=1 tests/
51 clean: ## Clean unused files.
52 @find ./ -name '*.pyc' -exec rm -f {} \;
53 @find ./ -name '__pycache__' -exec rm -rf {} \;
54 @find ./ -name 'Thumbs.db' -exec rm -f {} \;
55 @find ./ -name '*~' -exec rm -f {} \;
67 virtualenv: ## Create a virtual environment.
68 @if [ "$(USING_POETRY)" ]; then poetry install && exit; fi
69 @echo "creating virtualenv ..."
71 @python3 -m venv .venv
72 @./.venv/bin/pip install -U pip
73 @./.venv/bin/pip install -e .[test]
75 @echo "!!! Please run 'source .venv/bin/activate' to enable the environment !!!"
78 release: ## Create a new tag for release.
79 @echo "WARNING: This operation will create s version tag and push to github"
80 @read -p "Version? (provide the next x.y.z semver) : " TAG
81 @echo "$${TAG}" > network_generation/VERSION
82 @$(ENV_PREFIX)gitchangelog > HISTORY.md
83 @git add network_generation/VERSION HISTORY.md
84 @git commit -m "release: version $${TAG} 🚀"
85 @echo "creating git tag : $${TAG}"
87 @git push -u origin HEAD --tags
88 @echo "Github Actions will detect the new tag and release the new version."
91 docs: ## Build the documentation.
92 @echo "building documentation ..."
93 @$(ENV_PREFIX)mkdocs build
94 URL="site/index.html"; xdg-open $$URL || sensible-browser $$URL || x-www-browser $$URL || gnome-open $$URL || open $$URL
96 .PHONY: switch-to-poetry
97 switch-to-poetry: ## Switch to poetry package manager.
98 @echo "Switching to poetry ..."
99 @if ! poetry --version > /dev/null; then echo 'poetry is required, install from https://python-poetry.org/'; exit 1; fi
101 @poetry init --no-interaction --name=a_flask_test --author=rochacbruno
102 @echo "" >> pyproject.toml
103 @echo "[tool.poetry.scripts]" >> pyproject.toml
104 @echo "network_generation = 'network_generation.__main__:main'" >> pyproject.toml
105 @cat requirements.txt | while read in; do poetry add --no-interaction "$${in}"; done
106 @cat requirements-test.txt | while read in; do poetry add --no-interaction "$${in}" --dev; done
107 @poetry install --no-interaction
108 @mkdir -p .github/backup
109 @mv requirements* .github/backup
110 @mv setup.py .github/backup
111 @echo "You have switched to https://python-poetry.org/ package manager."
112 @echo "Please run 'poetry shell' or 'poetry run network_generation'"
115 init: ## Initialize the project based on an application template.
119 # This project has been generated from rochacbruno/python-project-template
120 # __author__ = 'rochacbruno'
121 # __repo__ = https://github.com/rochacbruno/python-project-template
122 # __sponsor__ = https://github.com/sponsors/rochacbruno/