-
Notifications
You must be signed in to change notification settings - Fork 13
/
Makefile
336 lines (251 loc) Β· 9.79 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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
# maintenance
.PHONY: isort flake black test type interrogate darglint \
clean cleanall style docs check
# installation
.PHONY: install installplus install.e install.all
install.base install.dev install.docs
# uninstallation
.PHONY: uninstall uninstallplus uninstall.e uninstall.all \
uninstall.base uninstall.dev uninstall.docs
# documentation
.PHONY: pregendocs.doc pregendocs.examples pregendocs.local pregendocs.remote \
gendocs \
postgendocs.doc postgendocs.local postgendocs.remote gendocsall.local
# generate examples
.PHONY: intro squares hanoi escher_square lattice lenet logo \
hilbert koch tensor latex hex_variation images \
tree serve
####------------------------------------------------------------####
# libname is either same as PACKAGE_NAME or
# as on PYPI (replace - with _)
LIBNAME := chalk_diagrams
PACKAGE_NAME := chalk
TESTPYPI_DOWNLOAD_URL := "https://test.pypi.org/simple/"
PYPIPINSTALL := "python -m pip install -U --index-url"
PIPINSTALL_PYPITEST := "$(PYPIPINSTALL) $(TESTPYPI_DOWNLOAD_URL)"
PKG_INFO := "import pkginfo; dev = pkginfo.Develop('.'); print((dev.$${FIELD}))"
# This is where you store the eggfile
# and other generated archives
ARCHIVES_DIR := ".archives"
# Folder path for tests
TESTS_DIR := "tests"
# Interrogate will flag the test as FAILED if
# % success threshold is under the following value
INTERROGATE_FAIL_UNDER := 0 # ideally this should be 100
# Specify paths of various dependency files
REQ_FOLDER := "requirements"
# location: requirements.txt
REQ_FILE := "requirements.txt"
# location: requirements/dev.txt
DEV_REQ_FILE := "dev.txt"
# location: requirements/docs.txt
DOCS_REQ_FILE := "docs.txt"
####------------------------------------------------------------####
### Code maintenance
## Run isort
isort:
@ echo "β¨ Applying import sorter: isort ... β³"
# The settings are maintained in setup.cfg file.
isort $(PACKAGE_NAME) setup.py \
tests \
## Run black
black:
@ echo "β¨ Applying formatter: black ... β³"
black --target-version py38 --line-length 79 $(PACKAGE_NAME) setup.py \
tests \
## Run flake8
flake:
@ echo "β¨ Applying formatter: flake8 ... β³"
flake8 --show-source $(PACKAGE_NAME) setup.py \
tests \
## Run pytest
test:
@ echo "β¨ Run tests: pytest ... β³"
@if [ -d "$(TESTS_DIR)" ]; then pytest $(TESTS_DIR); else echo "\n\tπ₯ No tests configured yet. Skipping tests.\n"; fi
## Run mypy
type:
@ echo "β¨ Applying type checker: mypy ... β³"
mypy --strict --ignore-missing-imports --no-warn-unused-ignores $(PACKAGE_NAME) \
tests \
## Run darglint
darglint:
@ echo "β¨ Applying docstring type checker: darglint ... β³"
# The settings are maintained in setup.cfg file.
darglint -v 2 $(PACKAGE_NAME) --ignore-properties
## Run interrogate
interrogate:
@ echo "β¨ Applying doctest checker: interrogate ... β³"
$(eval INTERROGATE_CONFIG := -vv --ignore-nested-functions --ignore-semiprivate --ignore-private --ignore-magic --ignore-module --ignore-init-method --fail-under $(INTERROGATE_FAIL_UNDER))
$(eval INTERROGATE_COMMAND := interrogate $(INTERROGATE_CONFIG))
# Check tests folder
@if [ -d "$(TESTS_DIR)" ]; then $(INTERROGATE_COMMAND) $(TESTS_DIR); else echo "\n\tπ₯ No tests configured yet. Skipping tests.\n"; fi
# Check package folder
@$(INTERROGATE_COMMAND) $(PACKAGE_NAME)
## Cleanup
#
# Instruction:
#
# make clean : if only cleaning artifacts created after running,
# code, tests, etc.
# make cleanall : if cleaning all artifacts (including the ones
# generated after creating dist and wheels).
#
# Note: archives created (dist and wheels) are stored in
# $(ARCHIVES_DIR). This is defined at the top of this Makefile.
#--------------------------------------------------------------------
clean:
@ echo "πͺ£ Cleaning repository ... β³"
rm -rf \
.ipynb_checkpoints **/.ipynb_checkpoints \
.pytest_cache **/.pytest_cache \
**/__pycache__ **/**/__pycache__
cleanall: clean
@ echo "πͺ£ Cleaning dist/archive files ... β³"
rm -rf build/* dist/* $(PACKAGE_NAME).egg-info/* $(ARCHIVES_DIR)/*
## Style Checks and Unit Tests
style: clean isort black flake clean
docs: clean darglint interrogate clean
check: style docs type test clean
####------------------------------------------------------------####
### Code Installation
## Install for development (from local repository)
#
# Instruction: Contributors will need to run...
#
# - "make installplus": if installing for the first time or want to
# update to the latest dev-requirements or
# other extra dependencies.
# - "make install.e" : if only installing the local source (after
# making some changes) to the source code.
#--------------------------------------------------------------------
# .PHONY: install.e
install.e: clean
@echo "ππ’π΅ Installing $(PACKAGE_NAME) from local source ... β³"
python -m pip install -Ue .[tikz,latex,png,svg]
# .PHONY: install
install: clean install.base install.e
@echo "ππ’π‘π΅ Installing $(PACKAGE_NAME) and base-dependencies from PyPI ... β³"
# .PHONY: installplus
installplus: install.all install.e
@echo "ππ’π‘π΅π Installing $(PACKAGE_NAME) and all-dependencies from PyPI ... β³"
# .PHONY: install.all
install.all: clean install.base install.dev install.docs
@echo "ππ’π‘ Installing $(PACKAGE_NAME)'s all-dependencies from PyPI ... β³"
# .PHONY: install.base
install.base:
@echo "ππ’π‘ Installing from: $(DEV_REQ_FILE) ... β³"
if [ -f $(REQ_FILE) ]; then python -m pip install -U -r $(REQ_FILE); fi
# .PHONY: install.dev
install.dev:
@echo "ππ’π‘ Installing from: $(DEV_REQ_FILE) ... β³"
if [ -f $(REQ_FOLDER)/$(DEV_REQ_FILE) ]; then python -m pip install -U -r $(REQ_FOLDER)/$(DEV_REQ_FILE); fi
# .PHONY: install.docs
install.docs:
@echo "ππ’π‘ Installing from: $(DOCS_REQ_FILE) ... β³"
@if [ -f $(REQ_FOLDER)/$(DOCS_REQ_FILE) ]; then python -m pip install -U -r $(REQ_FOLDER)/$(DOCS_REQ_FILE); fi
## Uninstall from dev-environment
# .PHONY: uninstall.e
uninstall.e: clean
@echo "ππ’π΅ Uninstalling $(PACKAGE_NAME)' local editable version ... β³"
@# https://stackoverflow.com/questions/48826015/uninstall-a-package-installed-with-pip-install
rm -rf "$(LIBNAME).egg-info"
# .PHONY: uninstall
uninstall: clean uninstall.base uninstall.e
@echo "ππ΄π‘π΅ Uninstalling $(PACKAGE_NAME) and base-dependencies from PyPI ... β³"
# .PHONY: uninstallplus
uninstallplus: uninstall.all uninstall.e
@echo "ππ΄π‘π΅π Uninstalling $(PACKAGE_NAME) and all-dependencies from PyPI ... β³"
# .PHONY: uninstall.all
uninstall.all: clean uninstall.base uninstall.dev uninstall.docs clean
@echo "ππ΄π‘ Uninstalling $(PACKAGE_NAME)'s all-dependencies from PyPI ... β³"
# .PHONY: uninstall.base
uninstall.base:
@echo "ππ΄π‘ Uninstalling from: $(DEV_REQ_FILE) ... β³"
if [ -f $(REQ_FILE) ]; then python -m pip uninstall -r $(REQ_FILE); fi
# .PHONY: uninstall.dev
uninstall.dev:
@echo "ππ΄π‘ Uninstalling from: $(DEV_REQ_FILE) ... β³"
if [ -f $(REQ_FOLDER)/$(DEV_REQ_FILE) ]; then python -m pip uninstall -r $(REQ_FOLDER)/$(DEV_REQ_FILE); fi
# .PHONY: uninstall.docs
uninstall.docs:
@echo "ππ΄π‘ Uninstalling from: $(DEV_REQ_FILE) ... β³"
@if [ -f $(REQ_FOLDER)/$(DOCS_REQ_FILE) ]; then python -m pip uninstall -r $(REQ_FOLDER)/$(DOCS_REQ_FILE); fi
## Install from test.pypi.org
#
# Instruction:
#
# π₯ This is useful if you want to test the latest released package
# from the TestPyPI, before you push the release to PyPI.
#--------------------------------------------------------------------
pipinstalltest:
@echo "πΏ Installing $(PACKAGE_NAME) from TestPyPI ($(TESTPYPI_DOWNLOAD_URL)) ... β³"
# Example Usage:
# π To run a command like:
# > python -m pip install -U --index-url https://test.pypi.org/simple/ $(PACKAGE_NAME)==$(VERSION)
# π Run the following command:
# > make pipinstalltest VERSION="0.1.0"
# π Specifying VERSION="#.#.#" installs a specific version.
# If no version is specified, the latest version is installed from TestPyPI.
@if [ $(VERSION) ]; then $(PIPINSTALL_PYPITEST) $(PACKAGE_NAME)==$(VERSION); else $(PIPINSTALL_PYPITEST) $(PACKAGE_NAME); fi;
## Gendocs
# .PHONY: gendocs
gendocs:
@echo "π₯ Generate documentation with MkDocs ... β³"
# generate documentation
mkdocs serve --dirtyreload
## Postgendocs
# .PHONY: postgendocs.doc
postgendocs.doc:
#echo "Cleanup docs... β³"
rm -rf docs/doc
# .PHONY: postgendocs.local
postgendocs.local: postgendocs.doc
# .PHONY: postgendocs.remote
postgendocs.remote: postgendocs.doc
# .PHONY: gendocsall.local
gendocsall.local: pregendocs.local gendocs postgendocs.local
# .PHONY: gendocsall.remote
# gendocsall.remote: pregendocs.remote gendocs postgendocs.remote
# @ # Use mkdocs-publish-ghpages.yml action instead of this make command
####------------------------------------------------------------####
### Generate Output for Examples
intro:
python examples/intro.py
squares:
python examples/squares.py
hanoi:
python examples/hanoi.py
escher_square:
python examples/escher_square_limit.py
lattice:
python examples/lattice.py
lenet:
python examples/lenet.py
logo:
python examples/logo.py
hilbert:
python examples/hilbert.py
koch:
python examples/koch.py
tensor:
python examples/tensor.py
latex:
python examples/latex.py
hex_variation:
python examples/hex_variation.py
tree:
python examples/tree.py
tournament:
python examples/tournament-network.py
parade:
python examples/rectangle_parade.py
arrows:
python examples/arrows.py
path:
python examples/path.py
images: squares hanoi intro hilbert koch tensor hex_variation tree tournament parade arrows path lenet escher_square logo
@echo "π Generate all examples ... β³"
serve:
python -m http.server 8080 -d examples/output/
docsapi:
python docs/api/*.py