-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
156 lines (124 loc) · 5.55 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
147
148
149
150
151
152
153
154
155
156
.PHONY: clean deepclean install dev mypy ruff ruff-format toml-sort lint pre-commit test-run test build publish doc-autobuild changelog doc-gen doc-mypy doc-coverage doc
########################################################################################
# Variables
########################################################################################
# Global option for pdm, when in CI or readthedocs environment, no need to use venv.
PDM_GLOBAL := $(shell [ "$$CI" = "true" ] || [ "$$READTHEDOCS" = "True" ] && echo "--global --project .")
# Documentation target directory, will be adapted to specific folder for readthedocs.
PUBLIC_DIR := $(shell [ "$$READTHEDOCS" = "True" ] && echo "$$READTHEDOCS_OUTPUT/html" || echo "public")
# URL and Path of changelog source code.
CHANGELOG_URL := $(shell echo $${CI_PAGES_URL:-https://blastpoint-inc.github.io/precommit-ci-test}/_sources/changelog.md.txt)
CHANGELOG_PATH := docs/changelog.md
########################################################################################
# Development Environment Management
########################################################################################
# Remove common intermediate files.
clean:
-rm -rf \
$(PUBLIC_DIR) \
.coverage \
.mypy_cache \
.pdm-build \
.pdm-python \
.pytest_cache \
.ruff_cache \
Pipfile* \
__pypackages__ \
build \
coverage.xml \
dist \
release-notes.md
find . -name '*.egg-info' -print0 | xargs -0 rm -rf
find . -name '*.pyc' -print0 | xargs -0 rm -f
find . -name '*.swp' -print0 | xargs -0 rm -f
find . -name '.DS_Store' -print0 | xargs -0 rm -f
find . -name '__pycache__' -print0 | xargs -0 rm -rf
# Remove pre-commit hook, virtual environment alongside itermediate files.
deepclean: clean
if command -v pre-commit > /dev/null 2>&1; then pre-commit uninstall; fi
if command -v pdm >/dev/null 2>&1 && pdm venv list | grep -q in-project ; then pdm venv remove --yes in-project >/dev/null 2>&1; fi
# Install the package in editable mode.
install:
pdm install $(PDM_GLOBAL) --prod
# Install the package in editable mode with specific optional dependencies.
dev-%:
pdm install $(PDM_GLOBAL) --dev --group $*
# Prepare the development environment.
# Install the pacakge in editable mode with all optional dependencies and pre-commit hoook.
dev:
pdm install $(PDM_GLOBAL)
if [ "$(CI)" != "true" ] && command -v pre-commit > /dev/null 2>&1; then pre-commit install; fi
########################################################################################
# Lint and pre-commit
########################################################################################
# Check lint with mypy.
mypy:
pdm run $(PDM_GLOBAL) python -m mypy .
# Lint with ruff.
ruff:
pdm run $(PDM_GLOBAL) python -m ruff check .
# Format with ruff.
ruff-format:
pdm run $(PDM_GLOBAL) python -m ruff format --check .
# Check lint with toml-sort.
toml-sort:
pdm run $(PDM_GLOBAL) toml-sort --check pyproject.toml
# Check lint with all linters.
lint: mypy ruff ruff-format toml-sort
# Run pre-commit with autofix against all files.
pre-commit:
pre-commit run --all-files --hook-stage manual
########################################################################################
# Test
########################################################################################
# Clean and run test with coverage.
test-run:
pdm run $(PDM_GLOBAL) python -m coverage erase
pdm run $(PDM_GLOBAL) python -m coverage run -m pytest
# Generate coverage report for terminal and xml.
test: test-run
pdm run $(PDM_GLOBAL) python -m coverage report
pdm run $(PDM_GLOBAL) python -m coverage xml
########################################################################################
# Package
########################################################################################
# Build the package.
build:
pdm build
# Publish the package.
publish:
pdm publish
########################################################################################
# Documentation
########################################################################################
# Generate documentation with auto build when changes happen.
doc-autobuild:
pdm run $(PDM_GLOBAL) python -m sphinx_autobuild docs $(PUBLIC_DIR) \
--watch README.md \
--watch src
# Generate changelog from git commits.
# NOTE(xuan.hu): Need to be run before document generation to take effect.
changelog:
@if wget -q --spider $(CHANGELOG_URL); then \
echo "Existing Changelog found at '$(CHANGELOG_URL)', download for incremental generation."; \
wget -q -O $(CHANGELOG_PATH) $(CHANGELOG_URL); \
fi
pdm run $(PDM_GLOBAL) git-changelog -ETrio $(CHANGELOG_PATH) -c conventional -s build,chore,ci,doc,feat,fix,perf,refactor,revert,style,test
# Generate release notes from changelog.
release-notes:
@pdm run $(PDM_GLOBAL) git-changelog --input $(CHANGELOG_PATH) --release-notes
# Build documentation only from src.
doc-gen:
pdm run $(PDM_GLOBAL) python -m sphinx.cmd.build docs $(PUBLIC_DIR)
# Generate mypy reports.
doc-mypy: doc-gen
pdm run $(PDM_GLOBAL) python -m mypy src tests --html-report $(PUBLIC_DIR)/reports/mypy
# Generate html coverage reports with badge.
doc-coverage: test-run doc-gen
pdm run $(PDM_GLOBAL) python -m coverage html -d $(PUBLIC_DIR)/reports/coverage
pdm run $(PDM_GLOBAL) bash scripts/generate-coverage-badge.sh $(PUBLIC_DIR)/_static/badges
# Generate all documentation with reports.
doc: changelog doc-gen doc-mypy doc-coverage
########################################################################################
# End
########################################################################################