-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
202 lines (172 loc) · 5.02 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
VERSION := 0.66.1
POETRY := bin/poetry/bin/poetry
PYTHON_FILES := $(shell git ls-files "*.py" ':!:whitelist.py')
PACKAGE_FILES := $(shell git ls-files "docsig/*.py")
TEST_FILES := $(shell git ls-files "tests/*.py")
DOCS_FILES := $(shell git ls-files "docs/*.rst" "docs/*.md")
ifeq ($(OS),Windows_NT)
VENV := .venv/Scripts/activate
else
VENV := .venv/bin/activate
endif
BUILD := dist/docsig-$(VERSION)-py3-none-any.whl
.PHONY: all
#: install development environment
all: .make/pre-commit .git/blame-ignore-revs
.PHONY: build
#: build distribution
build: $(BUILD)
#: build and check integrity of distribution
$(BUILD): .make/doctest \
.make/format \
.make/lint \
.make/unused \
.make/update-docs \
.mypy_cache/CACHEDIR.TAG \
README.rst \
coverage.xml \
docs/_build/html/index.html \
docs/_build/linkcheck/output.json
@$(POETRY) build
@touch $@
.PHONY: test
#: test source
test: .make/doctest coverage.xml
.PHONY: publish
#: publish distribution
publish: $(BUILD)
@$(POETRY) publish
#: generate documentation
docs/_build/html/index.html: $(VENV) \
$(PYTHON_FILES) \
$(DOCS_FILES) \
CHANGELOG.md \
.conform.yaml \
CONTRIBUTING.md
@$(POETRY) run $(MAKE) -C docs html
.PHONY: clean
#: clean compiled files
clean:
@find . -name '__pycache__' -exec rm -rf {} +
@rm -rf .coverage
@rm -rf .git/blame-ignore-revs
@rm -rf .git/hooks/*
@rm -rf .make
@rm -rf .mypy_cache
@rm -rf .pytest_cache
@rm -rf .venv
@rm -rf bin
@rm -rf coverage.xml
@rm -rf dist
@rm -rf docs/_build
@rm -rf docs/_generated
#: generate virtual environment
$(VENV): $(POETRY) poetry.lock
@[ ! $$(basename "$$($< env info --path)") = ".venv" ] \
&& rm -rf "$$($< env info --path)" \
|| exit 0
@POETRY_VIRTUALENVS_IN_PROJECT=1 $< install
@touch $@
#: install pre-commit hooks
.make/pre-commit: $(VENV)
@$(POETRY) run pre-commit install \
--hook-type pre-commit \
--hook-type pre-merge-commit \
--hook-type pre-push \
--hook-type prepare-commit-msg \
--hook-type commit-msg \
--hook-type post-commit \
--hook-type post-checkout \
--hook-type post-merge \
--hook-type post-rewrite
@mkdir -p $(@D)
@touch $@
#: install .git-blane-ignore-revs
.git/blame-ignore-revs:
@git config --local include.path $(@F)
@printf '%s\n' '[blame]' 'ignoreRevsFile = .git-blame-ignore-revs' > $@
#: install poetry
$(POETRY):
@curl -sSL https://install.python-poetry.org | \
POETRY_HOME="$$(pwd)/bin/poetry" "$$(which python)" - --version 1.8.3
@touch $@
#: update commandline documentation if needed
README.rst: $(VENV) $(PACKAGE_FILES)
@$(POETRY) run python scripts/update_readme.py >/dev/null 2>&1 || exit 0
@touch $@
#: update docs according to source
.make/update-docs: $(VENV) $(PACKAGE_FILES)
@$(POETRY) run python scripts/update_docs.py
@mkdir -p $(@D)
@touch $@
.PHONY: update-copyright
#: update copyright year in files containing it
update-copyright: $(VENV)
@$(POETRY) run python3 scripts/update_copyright.py
#: run checks that format code
.make/format: $(VENV) $(PYTHON_FILES)
@$(POETRY) run black $(PYTHON_FILES)
@$(POETRY) run docformatter $(PYTHON_FILES)
@$(POETRY) run flynt $(PYTHON_FILES)
@$(POETRY) run isort $(PYTHON_FILES)
@mkdir -p $(@D)
@touch $@
#: lint code
.make/lint: $(VENV) $(PYTHON_FILES)
@$(POETRY) run pylint --output-format=colorized $(PYTHON_FILES)
@$(POETRY) run docsig $(PYTHON_FILES)
@mkdir -p $(@D)
@touch $@
#: check typing
.mypy_cache/CACHEDIR.TAG: $(VENV) $(PYTHON_FILES)
@$(POETRY) run mypy $(PYTHON_FILES)
@touch $@
#: check for unused code
.make/unused: whitelist.py
@$(POETRY) run vulture whitelist.py docsig tests
@mkdir -p $(@D)
@touch $@
#: generate whitelist of allowed unused code
whitelist.py: $(VENV) $(PACKAGE_FILES) $(TEST_FILES)
@$(POETRY) run vulture --make-whitelist docsig tests > $@ || exit 0
#: generate coverage report
coverage.xml: $(VENV) $(PACKAGE_FILES) $(TEST_FILES)
@$(POETRY) run pytest -n=auto --cov=docsig --cov=tests \
&& $(POETRY) run coverage xml
#: test code examples in documentation
.make/doctest: $(VENV) README.rst $(PYTHON_FILES) $(DOCS_FILES)
@$(POETRY) run pytest docs README.rst --doctest-glob='*.rst'
@mkdir -p $(@D)
@touch $@
.PHONY: benchmark
#: run benchmarks
benchmark: $(VENV)
@RUN_BENCHMARK=true $(POETRY) run pytest -m=benchmark --benchmark-save=benchmark
#: confirm links in documentation are valid
docs/_build/linkcheck/output.json: $(VENV) \
$(PYTHON_FILES) \
$(DOCS_FILES) \
CHANGELOG.md \
.conform.yaml \
CONTRIBUTING.md
@trap "rm -f $(@); exit 1" ERR; \
{ \
ping -c 1 docsig.readthedocs.io >/dev/null 2>&1 \
|| { echo "could not establish connection, skipping"; exit 0; }; \
$(POETRY) run $(MAKE) -C docs linkcheck; \
}
#: check dependencies are properly managed
.make/check-deps: $(VENV) $(PYTHON_FILES) pyproject.toml
@$(POETRY) run deptry .
@mkdir -p $(@D)
@touch $@
#: test check news script
.make/test-check-news: $(VENV) scripts/check_news.py
@$(POETRY) run pytest scripts/check_news.py --cov -n=auto
@mkdir -p $(@D)
@touch $@
.PHONY: bump
bump: part = patch
#: bump version
bump: .make/pre-commit
@$(POETRY) run python scripts/bump_version.py $(part)