-
Notifications
You must be signed in to change notification settings - Fork 29
/
Makefile
178 lines (122 loc) · 3.75 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
.DEFAULT_GOAL := help
define BROWSER_PYSCRIPT
import os, webbrowser, sys
from urllib.request import pathname2url
webbrowser.open("file://" + pathname2url(os.path.abspath(sys.argv[1])))
endef
export BROWSER_PYSCRIPT
define PRINT_HELP_PYSCRIPT
import re, sys
hits = []
for line in sys.stdin:
match = re.match(r'^([a-zA-Z_-]+):.*?## (.*)$$', line)
if match:
target, help = match.groups()
hits.append([target, help])
if 1: hits.sort()
for target, help in hits:
print("%-20s %s" % (target, help))
print("""
Start with the installation of Python and Node modules:
make install
Compile frontend changes:
make frontend
Build example docs and open in browser:
make docs serve
""")
endef
export PRINT_HELP_PYSCRIPT
BROWSER := python -c "$$BROWSER_PYSCRIPT"
.PHONY: help
help:
@python -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST)
.PHONY: install
install: install-python install-frontend ## Install all
.PHONY: install-frontend
install-frontend: ##- Install node modules
npm install
.PHONY: install-python
install-python: ##- Install Python modules
pip install -U pip
pip install -U -r requirements-dev.txt
.PHONY: build
build: clean frontend-dist ##- Build Sphinx extension
python -m build
twine check dist/*
ls -l dist
.PHONY: clean
clean: ##- Remove all build, test and Python artifacts
# Build frontend files
rm -rf sphinx_wagtail_theme/static/dist
# Python build artifacts
rm -rf build/
rm -rf dist/
rm -rf .eggs/
find . -name '*.egg-info' -exec rm -rf {} +
find . -name '*.egg' -exec rm -f {} +
# Clean build docs
rm -rf ./docs/_build
rm -rf ./rtd-venv
# Python test artifacts
rm -rf .tox/
rm -rf htmlcov/
rm -rf .pytest_cache
# Python artifacts
find . -name '*.pyc' -exec rm -f {} +
find . -name '*.pyo' -exec rm -f {} +
find . -name '*~' -exec rm -f {} +
find . -name '__pycache__' -exec rm -rf {} +
.PHONY: docs
docs: ## Build Sphinx HTML documentation
$(MAKE) -C docs clean
$(MAKE) -C docs html
.PHONY: rtd-docs
rtd-docs: ## Build the docs like Readthedocs does.
python3.10 -m venv "./rtd-venv"
./rtd-venv/bin/python -m pip install --upgrade --no-cache-dir pip "setuptools<58.3.0"
./rtd-venv/bin/python -m pip install --upgrade --no-cache-dir "mock==1.0.1" "pillow==5.4.1" "alabaster>=0.7,<0.8,!=0.7.5" "commonmark==0.8.1" "recommonmark==0.5.0" "sphinx" "sphinx-rtd-theme" "readthedocs-sphinx-ext<2.2"
./rtd-venv/bin/python -m pip install --exists-action=w --no-cache-dir -r docs/requirements.txt
# This had to be modified to use the ./docs/ dir instead of cwd.
./rtd-venv/bin/python -m sphinx -T -E -b html -d ./docs/_build/doctrees -D language=en ./docs ./docs/_build/html
rm -rf "./rtd-venv"
.PHONY: serve
serve: ## Serve docs at http://localhost:8000
python -m http.server --directory ./docs/_build/html
.PHONY: frontend
frontend: ## Compile frontend files
npm run frontend
.PHONY: frontend-dist
frontend-dist: ##- Build frontend files for distribution
npm run build
.PHONY: watch
watch:
npm run watch
.PHONY: watchdocs
watchdocs: docs ##- Redo 'docs' and watch for changes (=make sd)
pip install watchdog
watchmedo shell-command -p '*.rst' -c '$(MAKE) -C docs html' -R -D .
.PHONY: lint
lint: lint-python lint-frontend ##- Run all linters
.PHONY: lint-python
lint-python:
black --check sphinx_wagtail_theme docs/ tests/
flake8 *.py
flake8 sphinx_wagtail_theme
flake8 tests
.PHONY: lint-frontend
lint-frontend:
npm run lint
.PHONY: format
format: format-python format-frontend ##- Run all formatters
.PHONY: format-python
format-python:
black sphinx_wagtail_theme docs/ tests/
.PHONY: format-frontend
format-frontend:
npm run format
.PHONY: test
test:
pytest
.PHONY: test-visual-regression
test-visual-regression: ## Run visual regression tests
./node_modules/.bin/percy exec -- python tests/test_visual_regression.py