-
Notifications
You must be signed in to change notification settings - Fork 10
/
Makefile
136 lines (96 loc) · 3.5 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
# Project settings
PACKAGE := async_btree
PACKAGES := $(PACKAGE) tests
MODULES := $(wildcard $(PACKAGE)/*.py)
# const
.DEFAULT_GOAL := help
#FAILURES := .pytest_cache/v/cache/lastfailed
FAILURES := .cache/v/cache/lastfailed
DIST_FILES := dist/*.tar.gz dist/*.whl
GIT_COMMIT_SHA := $(shell git rev-parse HEAD)
# MAIN TASKS ##################################################################
.PHONY: all
all: install
.PHONY: debug-info
debug-info: ## Show poetry debug info
poetry debug:info
.PHONY: help
help: all
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
# PROJECT DEPENDENCIES ########################################################
install: .install .cache ## Install project dependencies
.install: poetry.lock
$(MAKE) configure
poetry install -E curio
poetry check
@touch $@
poetry.lock: pyproject.toml
$(MAKE) configure
poetry lock
@touch $@
.cache:
@mkdir -p .cache
.PHONY: requirements.txt
requirements.txt: ## Generate requirements.txt and requirements-dev.txt
@poetry export --without-hashes -f requirements.txt > requirements.txt
@sed '1d' requirements.txt
.PHONY: configure
configure:
@poetry config virtualenvs.in-project true
@poetry run python -m pip install --upgrade pip
@poetry run python -m pip install --upgrade setuptools
# CHECKS ######################################################################
.PHONY: check
check: install ## Run linters and static analysis
poetry run isort $(PACKAGES)
poetry run black $(PACKAGES)
poetry run ruff check $(PACKAGES)
poetry run mypy --show-error-codes --config-file pyproject.toml $(PACKAGE)
# TESTS #######################################################################
.PHONY: test
test: install ## Run unit tests
@if test -e $(FAILURES); then poetry run pytest tests --last-failed --exitfirst; fi
@rm -rf $(FAILURES)
poetry run pytest
# BUILD #######################################################################
.PHONY: build
build: install check test $(DIST_FILES) ## Builds the source and wheels archives
$(DIST_FILES): $(MODULES) pyproject.toml
@rm -f $(DIST_FILES)
poetry build
# RELEASE #####################################################################
.PHONY: publish
publish: build ## Publishes the package, previously built with the build command, to the remote repository
$(MAKE) configure
poetry publish
$(MAKE) tag
.PHONY: next-patch-version
next-patch-version: ## Increment patch version
$(MAKE) configure
git checkout main
git pull
poetry version patch
$(MAKE) install
git add .
git commit -m "Next version"
git push origin main
.PHONY: tag
tag: ## Tags current repository
git diff --name-only --exit-code
@PROJECT_RELEASE=$$(poetry version | awk 'END {print $$NF}') ; \
git tag "v$$PROJECT_RELEASE" ; \
git push origin "v$$PROJECT_RELEASE"
.PHONY: release
release: next-patch-version publish
# DOC #########################################################################
.PHONY: build-docs
build-docs: ## Build and publish sit documentation.
@poetry run mkdocs build --clean
.PHONY: publish-docs
publish-docs: ## Build and publish sit documentation.
@poetry run mkdocs gh-deploy --clean
# CLEANUP #####################################################################
.PHONY: clean
clean: ## Delete all generated and temporary files
@rm -rf *.spec dist build .eggs *.egg-info .install .cache .coverage htmlcov .mypy_cache .pytest_cache site .ruff_cache
@find $(PACKAGES) -type d -name '__pycache__' -exec rm -rf {} +