-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
146 lines (118 loc) · 5.74 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
SHELL := /bin/bash
# =============================================================================
# Variables
# =============================================================================
.DEFAULT_GOAL:=help
.ONESHELL:
USING_PDM = $(shell grep "tool.pdm" pyproject.toml && echo "yes")
USING_NPM = $(shell python3 -c "if __import__('pathlib').Path('package-lock.json').exists(): print('yes')")
ENV_PREFIX =.venv/bin/
VENV_EXISTS = $(shell python3 -c "if __import__('pathlib').Path('.venv/bin/activate').exists(): print('yes')")
NODE_MODULES_EXISTS = $(shell python3 -c "if __import__('pathlib').Path('node_modules').exists(): print('yes')")
SRC_DIR =src
BUILD_DIR =dist
PDM_OPTS ?=
PDM ?= pdm $(PDM_OPTS)
.EXPORT_ALL_VARIABLES:
ifndef VERBOSE
.SILENT:
endif
.PHONY: help
help: ## Display this help text for Makefile
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z0-9_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
.PHONY: upgrade
upgrade: ## Upgrade all dependencies to the latest stable versions
@echo "=> Updating all dependencies"
@if [ "$(USING_PDM)" ]; then $(PDM) update; fi
@echo "=> Python Dependencies Updated"
@if [ "$(USING_NPM)" ]; then npm upgrade --latest; fi
@echo "=> Node Dependencies Updated"
@$(ENV_PREFIX)pre-commit autoupdate
@echo "=> Updated Pre-commit"
# =============================================================================
# Developer Utils
# =============================================================================
install-pdm: ## Install latest version of PDM
@curl -sSLO https://pdm.fming.dev/install-pdm.py && \
curl -sSL https://pdm.fming.dev/install-pdm.py.sha256 | shasum -a 256 -c - && \
python3 install-pdm.py
install: ## Install the project and
@if ! $(PDM) --version > /dev/null; then echo '=> Installing PDM'; $(MAKE) install-pdm; fi
@if [ "$(VENV_EXISTS)" ]; then echo "=> Removing existing virtual environment"; fi
if [ "$(VENV_EXISTS)" ]; then $(MAKE) destroy-venv; fi
if [ "$(VENV_EXISTS)" ]; then $(MAKE) clean; fi
@if [ "$(NODE_MODULES_EXISTS)" ]; then echo "=> Removing existing node modules"; fi
if [ "$(NODE_MODULES_EXISTS)" ]; then $(MAKE) destroy-node_modules; fi
@if [ "$(USING_PDM)" ]; then $(PDM) config venv.in_project true && python3 -m venv --copies .venv && . $(ENV_PREFIX)/activate && $(ENV_PREFIX)/pip install --quiet -U wheel setuptools cython pip; fi
@if [ "$(USING_PDM)" ]; then $(PDM) install -G:all; fi
@echo "=> Install complete! Note: If you want to re-install re-run 'make install'"
clean: ## Cleanup temporary build artifacts
@echo "=> Cleaning working directory"
@rm -rf .pytest_cache .ruff_cache .hypothesis build/ -rf dist/ .eggs/ .coverage coverage.xml coverage.json htmlcov/ .mypy_cache
@find . -name '*.egg-info' -exec rm -rf {} +
@find . -name '*.egg' -exec rm -f {} +
@find . -name '*.pyc' -exec rm -f {} +
@find . -name '*.pyo' -exec rm -f {} +
@find . -name '*~' -exec rm -f {} +
@find . -name '__pycache__' -exec rm -rf {} +
@find . -name '.pytest_cache' -exec rm -rf {} +
@find . -name '.ipynb_checkpoints' -exec rm -rf {} +
destroy-venv: ## Destroy the virtual environment
@rm -rf .venv
destroy-node_modules: ## Destroy the node environment
@rm -rf node_modules
migrations: ## Generate database migrations
@echo "ATTENTION: This operation will create a new database migration for any defined models changes."
@while [ -z "$$MIGRATION_MESSAGE" ]; do read -r -p "Migration message: " MIGRATION_MESSAGE; done ;
@$(ENV_PREFIX)app database make-migrations --autogenerate -m "$${MIGRATION_MESSAGE}"
.PHONY: migrate
migrate: ## Generate database migrations
@echo "ATTENTION: Will apply all database migrations."
@$(ENV_PREFIX)app database upgrade
.PHONY: build
build:
@echo "=> Building package..."
@if [ "$(USING_PDM)" ]; then pdm build; fi
@echo "=> Package build complete..."
.PHONY: refresh-lockfiles
refresh-lockfiles: ## Sync lockfiles with requirements files.
@pdm update --update-reuse --group :all
.PHONY: lock
lock: ## Rebuild lockfiles from scratch, updating all dependencies
@pdm update --update-eager --group :all
# =============================================================================
# Tests, Linting, Coverage
# =============================================================================
.PHONY: lint
lint: ## Runs pre-commit hooks; includes ruff linting, codespell, black
@echo "=> Running pre-commit process"
@$(ENV_PREFIX)pre-commit run --all-files
@echo "=> Pre-commit complete"
.PHONY: coverage
coverage: ## Run the tests and generate coverage report
@echo "=> Running tests with coverage"
@$(ENV_PREFIX)pytest tests --cov=app
@$(ENV_PREFIX)coverage html
@$(ENV_PREFIX)coverage xml
@echo "=> Coverage report generated"
.PHONY: test
test: ## Run the tests
@echo "=> Running test cases"
@$(ENV_PREFIX)pytest tests
@echo "=> Tests complete"
.PHONY: pre-release
pre-release: ## bump the version and create the release tag
make gen-docs
make clean
$(ENV_PREFIX)bump2version $(increment)
git describe --tags --abbrev=0
head pyproject.toml | grep version
# =============================================================================
# Docs
# =============================================================================
gen-docs: ## generate HTML documentation
$(ENV_PREFIX)mkdocs build
.PHONY: docs
docs: ## generate HTML documentation and serve it to the browser
$(ENV_PREFIX)mkdocs build
$(ENV_PREFIX)mkdocs serve