2024-11-10 07:27:36 -08:00
|
|
|
.ONESHELL:
|
|
|
|
ENV_PREFIX=$(shell python -c "if __import__('pathlib').Path('.venv/bin/pip').exists(): print('.venv/bin/')")
|
|
|
|
USING_POETRY=$(shell grep "tool.poetry" pyproject.toml && echo "yes")
|
|
|
|
|
2024-11-30 12:36:41 -08:00
|
|
|
.PHONY: issetup
|
|
|
|
issetup:
|
|
|
|
@[ -f .git/hooks/commit-msg ] || (echo "You must run 'make setup' first to initialize the repo!" && exit 1)
|
|
|
|
|
|
|
|
.PHONY: setup
|
|
|
|
setup:
|
|
|
|
@cp .gitea/conventional_commits/commit-msg .git/hooks/
|
|
|
|
|
2024-11-10 07:27:36 -08:00
|
|
|
.PHONY: help
|
|
|
|
help: ## Show the help.
|
|
|
|
@echo "Usage: make <target>"
|
|
|
|
@echo ""
|
|
|
|
@echo "Targets:"
|
|
|
|
@fgrep "##" Makefile | fgrep -v fgrep
|
|
|
|
|
|
|
|
|
|
|
|
.PHONY: show
|
|
|
|
show: ## Show the current environment.
|
|
|
|
@echo "Current environment:"
|
|
|
|
@if [ "$(USING_POETRY)" ]; then poetry env info && exit; fi
|
|
|
|
@echo "Running using $(ENV_PREFIX)"
|
|
|
|
@$(ENV_PREFIX)python -V
|
|
|
|
@$(ENV_PREFIX)python -m site
|
|
|
|
|
|
|
|
.PHONY: install
|
2024-11-30 12:36:41 -08:00
|
|
|
install: issetup ## Install the project in dev mode.
|
2024-11-10 07:27:36 -08:00
|
|
|
@if [ "$(USING_POETRY)" ]; then poetry install && exit; fi
|
|
|
|
@echo "Don't forget to run 'make virtualenv' if you got errors."
|
|
|
|
$(ENV_PREFIX)pip install -e .[test]
|
|
|
|
|
|
|
|
.PHONY: fmt
|
2024-11-30 12:36:41 -08:00
|
|
|
fmt: issetup ## Format code using black & isort.
|
2024-11-10 07:27:36 -08:00
|
|
|
$(ENV_PREFIX)isort project_name/
|
|
|
|
$(ENV_PREFIX)black -l 79 project_name/
|
|
|
|
$(ENV_PREFIX)black -l 79 tests/
|
|
|
|
|
|
|
|
.PHONY: lint
|
2024-11-30 12:36:41 -08:00
|
|
|
lint: issetup ## Run pep8, black, mypy linters.
|
2024-11-10 07:27:36 -08:00
|
|
|
$(ENV_PREFIX)flake8 project_name/
|
|
|
|
$(ENV_PREFIX)black -l 79 --check project_name/
|
|
|
|
$(ENV_PREFIX)black -l 79 --check tests/
|
|
|
|
$(ENV_PREFIX)mypy --ignore-missing-imports project_name/
|
|
|
|
|
|
|
|
.PHONY: test
|
|
|
|
test: lint ## Run tests and generate coverage report.
|
|
|
|
$(ENV_PREFIX)pytest -v --cov-config .coveragerc --cov=project_name -l --tb=short --maxfail=1 tests/
|
|
|
|
$(ENV_PREFIX)coverage xml
|
|
|
|
$(ENV_PREFIX)coverage html
|
|
|
|
|
|
|
|
.PHONY: watch
|
2024-11-30 12:36:41 -08:00
|
|
|
watch: issetup ## Run tests on every change.
|
2024-11-10 07:27:36 -08:00
|
|
|
ls **/**.py | entr $(ENV_PREFIX)pytest -s -vvv -l --tb=long --maxfail=1 tests/
|
|
|
|
|
|
|
|
.PHONY: clean
|
|
|
|
clean: ## Clean unused files.
|
|
|
|
@find ./ -name '*.pyc' -exec rm -f {} \;
|
|
|
|
@find ./ -name '__pycache__' -exec rm -rf {} \;
|
|
|
|
@find ./ -name 'Thumbs.db' -exec rm -f {} \;
|
|
|
|
@find ./ -name '*~' -exec rm -f {} \;
|
|
|
|
@rm -rf .cache
|
|
|
|
@rm -rf .pytest_cache
|
|
|
|
@rm -rf .mypy_cache
|
|
|
|
@rm -rf build
|
|
|
|
@rm -rf dist
|
|
|
|
@rm -rf *.egg-info
|
|
|
|
@rm -rf htmlcov
|
|
|
|
@rm -rf .tox/
|
|
|
|
@rm -rf docs/_build
|
|
|
|
|
|
|
|
.PHONY: virtualenv
|
2024-11-30 12:36:41 -08:00
|
|
|
virtualenv: issetup ## Create a virtual environment.
|
2024-11-10 07:27:36 -08:00
|
|
|
@if [ "$(USING_POETRY)" ]; then poetry install && exit; fi
|
|
|
|
@echo "creating virtualenv ..."
|
|
|
|
@rm -rf .venv
|
|
|
|
@python3 -m venv .venv
|
|
|
|
@./.venv/bin/pip install -U pip
|
|
|
|
@./.venv/bin/pip install -e .[test]
|
|
|
|
@echo
|
|
|
|
@echo "!!! Please run 'source .venv/bin/activate' to enable the environment !!!"
|
|
|
|
|
|
|
|
.PHONY: release
|
2024-11-30 12:36:41 -08:00
|
|
|
release: issetup ## Create a new tag for release.
|
2024-11-10 07:27:36 -08:00
|
|
|
@echo "WARNING: This operation will create s version tag and push to gitea"
|
|
|
|
@read -p "Version? (provide the next x.y.z semver) : " TAG
|
|
|
|
@echo "creating git tag : $${TAG}"
|
|
|
|
@git tag $${TAG}
|
|
|
|
@echo "$${TAG}" > project_name/VERSION
|
|
|
|
@$(ENV_PREFIX)gitchangelog > HISTORY.md
|
|
|
|
@git add project_name/VERSION HISTORY.md
|
|
|
|
@git commit -m "release: version $${TAG} 🚀"
|
|
|
|
@git push -u origin HEAD --tags
|
|
|
|
@echo "Gitea Actions will detect the new tag and release the new version."
|
|
|
|
|
|
|
|
.PHONY: docs
|
2024-11-30 12:36:41 -08:00
|
|
|
docs: issetup ## Build the documentation.
|
2024-11-10 07:27:36 -08:00
|
|
|
@echo "building documentation ..."
|
|
|
|
@$(ENV_PREFIX)mkdocs build
|
|
|
|
URL="site/index.html"; xdg-open $$URL || sensible-browser $$URL || x-www-browser $$URL || gnome-open $$URL
|
|
|
|
|
|
|
|
.PHONY: switch-to-poetry
|
|
|
|
switch-to-poetry: ## Switch to poetry package manager.
|
|
|
|
@echo "Switching to poetry ..."
|
|
|
|
@if ! poetry --version > /dev/null; then echo 'poetry is required, install from https://python-poetry.org/'; exit 1; fi
|
|
|
|
@rm -rf .venv
|
|
|
|
@poetry init --no-interaction --name=a_flask_test --author=rochacbruno
|
|
|
|
@echo "" >> pyproject.toml
|
|
|
|
@echo "[tool.poetry.scripts]" >> pyproject.toml
|
|
|
|
@echo "project_name = 'project_name.__main__:main'" >> pyproject.toml
|
|
|
|
@cat requirements.txt | while read in; do poetry add --no-interaction "$${in}"; done
|
|
|
|
@cat requirements-base.txt | while read in; do poetry add --no-interaction "$${in}" --dev; done
|
|
|
|
@cat requirements-test.txt | while read in; do poetry add --no-interaction "$${in}" --dev; done
|
|
|
|
@poetry install --no-interaction
|
|
|
|
@mkdir -p .gitea/backup
|
|
|
|
@mv requirements* .gitea/backup
|
|
|
|
@mv setup.py .gitea/backup
|
|
|
|
@echo "You have switched to https://python-poetry.org/ package manager."
|
|
|
|
@echo "Please run 'poetry shell' or 'poetry run project_name'"
|
2024-11-30 12:36:41 -08:00
|
|
|
|
|
|
|
|
2024-11-10 07:27:36 -08:00
|
|
|
# This project has been generated from rochacbruno/flask-project-template
|
|
|
|
# __author__ = 'rochacbruno'
|
|
|
|
# __repo__ = https://github.com/rochacbruno/flask-project-template
|
|
|
|
# __sponsor__ = https://github.com/sponsors/rochacbruno/
|