1
1
PY := python3
2
2
PYM := $(PY ) -m
3
3
4
+ COLOR_RESET := \033[0m
5
+ COLOR_GREEN := \033[1;32m
6
+ COLOR_CYAN := \033[1;33m
7
+ COLOR_CYAN := \033[1;36m
8
+ COLOR_RED := \033[1;31m
9
+
4
10
.PHONY : \
5
11
prepare-venv \
6
12
clean-venv \
@@ -17,47 +23,78 @@ PYM := $(PY) -m
17
23
upload
18
24
19
25
prepare-venv :
26
+ @echo " $( COLOR_CYAN) > Creating virtual environment...$( COLOR_RESET) " ; \
20
27
$(PYM ) venv venv && \
21
- . venv/bin/activate && \
22
- pip install -r requirements-dev.txt
28
+ echo " $( COLOR_CYAN ) > Installing dev dependencies... $( COLOR_RESET ) " ; \
29
+ . venv/bin/activate && pip install -r requirements-dev.txt > /dev/null
23
30
24
31
clean-venv :
32
+ @echo " $( COLOR_CYAN) > Removing virtual environment...$( COLOR_RESET) " ; \
25
33
rm -rf venv/
26
34
27
- source-venv :
28
- . venv/bin/activate
29
-
30
35
tests-simple :
36
+ @echo " $( COLOR_CYAN) > Running tests (simple) ...$( COLOR_RESET) " ; \
31
37
$(PYM ) pytest test/
32
38
33
- # tox will generate the coverage report
34
39
tests-tox :
40
+ @echo " $( COLOR_CYAN) > Running tests (tox)...$( COLOR_RESET) " ; \
35
41
$(PYM ) tox
36
42
37
43
clean-tests :
44
+ @echo " $( COLOR_CYAN) > Cleaning test artifacts...$( COLOR_RESET) " ; \
38
45
rm -rf .pytest_cache/ .tox/
39
46
40
47
clean-cov :
48
+ @echo " $( COLOR_CYAN) > Cleaning coverage files...$( COLOR_RESET) " ; \
41
49
rm -rf .coverage*
42
50
43
- build :
44
- $(PY ) scripts/preprocess_md_doc.py
45
- $(PYM ) build
46
-
47
51
clean-build :
52
+ @echo " $( COLOR_CYAN) > Cleaning build artifacts...$( COLOR_RESET) " ; \
48
53
rm -rf build/ dist/ * .egg-info README_pypi.md
49
54
55
+ build : clean-build
56
+ @ALL_TAGS=$$(git tag | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$$' | sort -V ) ; \
57
+ LATEST_TAG=$$(echo "$$ALL_TAGS" | tail -n 1 ) ; \
58
+ echo " $( COLOR_CYAN) > Latest git tag: $( COLOR_YELLOW) $$ LATEST_TAG$( COLOR_RESET) " ; \
59
+ PY_VERSION=$$(sed -n 's/^version *= *"\([^"]*\ ) " .*$$ /\1/p' pyproject.toml); \
60
+ echo " $( COLOR_CYAN) > Current version (pyproject.toml): $( COLOR_CYAN) $$ PY_VERSION$( COLOR_RESET) " ; \
61
+ if [ " $$ {LATEST_TAG#v}" != " $$ PY_VERSION" ]; then \
62
+ echo " $( COLOR_RED) > ERROR: Git tag ($$ LATEST_TAG) and pyproject version ($$ PY_VERSION) do not match.$( COLOR_RESET) " ; \
63
+ exit 1; \
64
+ fi ; \
65
+ echo " $( COLOR_CYAN) > Processing project README...$( COLOR_RESET) " ; \
66
+ $(PY ) scripts/process_md_doc.py --version $$ LATEST_TAG > /dev/null; \
67
+ echo " $( COLOR_CYAN) > Building the distribution...$( COLOR_RESET) " ; \
68
+ $(PYM ) build > /dev/null; \
69
+ BUILD_EXIT_CODE=$$? ; \
70
+ if [ $$ BUILD_EXIT_CODE -eq 0 ]; then \
71
+ echo " $( COLOR_GREEN) > Build complete.$( COLOR_RESET) " ; \
72
+ else \
73
+ echo " $( COLOR_RED) > Build failed.$( COLOR_RESET) " ; \
74
+ exit $$ BUILD_EXIT_CODE; \
75
+ fi
76
+
50
77
ruff :
51
- $(PYM ) ruff format && ruff check --fix
78
+ @echo " $( COLOR_CYAN) > Running formatter...$( COLOR_RESET) " ; \
79
+ $(PYM ) ruff format; \
80
+ echo " $( COLOR_CYAN) > Running linter...$( COLOR_RESET) " ; \
81
+ $(PYM ) ruff check --fix
52
82
53
83
clean-ruff :
84
+ @echo " $( COLOR_CYAN) > Cleaning ruff cache...$( COLOR_RESET) " ; \
54
85
rm -rf .ruff_cache/
55
86
56
87
clean-all : clean-venv clean-tests clean-cov clean-build clean-ruff
57
88
58
89
install :
59
- $(PYM ) pip uninstall -y pypformat || true
60
- $(PYM ) pip install .
90
+ @echo " $( COLOR_CYAN) > Reinstalling local package...$( COLOR_RESET) " ; \
91
+ $(PYM ) pip uninstall -y pypformat > /dev/null || true ; \
92
+ $(PYM ) pip install . > /dev/null
61
93
62
- upload : build
94
+ upload : clean-build build
95
+ @echo " $( COLOR_CYAN) > Uploading distribution to pypi...$( COLOR_RESET) " ; \
63
96
$(PYM ) twine upload dist/*
97
+
98
+ upload-test : clean-build build
99
+ @echo " $( COLOR_CYAN) > Uploading distribution to testpypi...$( COLOR_RESET) " ; \
100
+ $(PYM ) twine upload --repository testpypi dist/*
0 commit comments