/
Makefile
209 lines (172 loc) · 7.08 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
# https://www.gnu.org/software/make/manual/make.html#Phony-Targets
# Prerequisites of .PHONY are always interpreted as literal target names, never as patterns (even if they contain ‘%’ characters).
# # .PHONY: help clean% check% format% docs% lint test pyright playwright% install% testrail% coverage release js-*
# Using `FORCE` as prerequisite to _force_ the target to always run; https://www.gnu.org/software/make/manual/make.html#index-FORCE
FORCE: ;
.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
for line in sys.stdin:
match = re.match(r'^([a-zA-Z1-9_-]+):.*?## (.*)$$', line)
if match:
target, help = match.groups()
print("%-20s %s" % (target, help))
endef
export PRINT_HELP_PYSCRIPT
BROWSER := python -c "$$BROWSER_PYSCRIPT"
help: FORCE
@python -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST)
clean: clean-build clean-pyc clean-test ## remove all build, test, coverage and Python artifacts
# Remove build artifacts
clean-build: FORCE
rm -fr build/
rm -fr dist/
rm -fr .eggs/
find . -name '*.egg-info' -exec rm -fr {} +
find . -name '*.egg' -exec rm -f {} +
# Remove Python file artifacts
clean-pyc: FORCE
find . -name '*.pyc' -exec rm -f {} +
find . -name '*.pyo' -exec rm -f {} +
find . -name '*~' -exec rm -f {} +
find . -name '__pycache__' -exec rm -fr {} +
# Remove test and coverage artifacts
clean-test: FORCE
rm -fr .tox/
rm -f .coverage
rm -fr htmlcov/
rm -fr .pytest_cache
rm -rf typings/
typings/appdirs:
@echo "Creating appdirs stubs"
pyright --createstub appdirs
typings/folium:
@echo "Creating folium stubs"
pyright --createstub folium
typings/uvicorn:
@echo "Creating uvicorn stubs"
pyright --createstub uvicorn
typings/seaborn:
@echo "Creating seaborn stubs"
pyright --createstub seaborn
typings/matplotlib/__init__.pyi:
@echo "Creating matplotlib stubs"
mkdir -p typings
git clone --depth 1 https://github.com/microsoft/python-type-stubs typings/python-type-stubs
mv typings/python-type-stubs/stubs/matplotlib typings/
rm -rf typings/python-type-stubs
pyright-typings: typings/appdirs typings/folium typings/uvicorn typings/seaborn typings/matplotlib/__init__.pyi
check: check-format check-lint check-types check-tests ## check code, style, types, and test (basic CI)
check-fix: format check-lint check-types check-tests ## check and format code, style, types, and test
check-format: check-black check-isort
check-lint: check-flake8
check-types: check-pyright
check-tests: check-pytest
check-flake8: FORCE
@echo "-------- Checking style with flake8 ---------"
flake8 --show-source .
check-black: FORCE
@echo "-------- Checking code with black -----------"
black --check .
check-isort: FORCE
@echo "-------- Sorting imports with isort ---------"
isort --check-only --diff .
check-pyright: pyright-typings
@echo "-------- Checking types with pyright --------"
pyright
check-pytest: FORCE
@echo "-------- Running tests with pytest ----------"
python3 tests/pytest/asyncio_prevent.py
pytest
# Check types with pyright
pyright: check-types
# Check style with flake8
lint: check-lint
test: check-tests ## check tests quickly with the default Python
format: format-black format-isort ## format code with black and isort
format-black: FORCE
@echo "-------- Formatting code with black --------"
black .
format-isort: FORCE
@echo "-------- Sorting imports with isort --------"
isort .
docs: FORCE ## docs: build docs with quartodoc
@echo "-------- Building docs with quartodoc ------"
@cd docs && make quartodoc
docs-preview: FORCE ## docs: preview docs in browser
@echo "-------- Previewing docs in browser --------"
@cd docs && make serve
docs-quartodoc: FORCE
@echo "-------- Making quartodoc docs --------"
@cd docs && make quartodoc
install-npm: FORCE
$(if $(shell which npm), @echo -n, $(error Please install node.js and npm first. See https://nodejs.org/en/download/ for instructions.))
js/node_modules: install-npm
@echo "-------- Installing node_modules -----------"
@cd js && npm install
js-build: js/node_modules ## Build JS assets
@echo "-------- Building JS assets ----------------"
@cd js && npm run build
js-watch: js/node_modules
@echo "-------- Continuously building JS assets ---"
@cd js && npm run watch
js-watch-fast: js/node_modules ## Continuously build JS assets (development)
@echo "-------- Previewing docs in browser --------"
@cd js && npm run watch-fast
clean-js: FORCE
@echo "-------- Removing js/node_modules ----------"
rm -rf js/node_modules
# Default `SUB_FILE` to empty
SUB_FILE:=
PYTEST_BROWSERS:= --browser webkit --browser firefox --browser chromium
PYTEST_DEPLOYS_BROWSERS:= --browser chromium
install-playwright: FORCE
playwright install --with-deps
install-trcli: FORCE
$(if $(shell which trcli), @echo -n, $(shell pip install trcli))
install-rsconnect: FORCE
pip install git+https://github.com/rstudio/rsconnect-python.git#egg=rsconnect-python
# end-to-end tests with playwright; (SUB_FILE="" within tests/playwright/shiny/)
playwright-shiny: install-playwright
pytest tests/playwright/shiny/$(SUB_FILE) $(PYTEST_BROWSERS)
# end-to-end tests on deployed apps with playwright; (SUB_FILE="" within tests/playwright/deploys/)
playwright-deploys: install-playwright install-rsconnect
pytest tests/playwright/deploys/$(SUB_FILE) $(PYTEST_DEPLOYS_BROWSERS)
# end-to-end tests on all py-shiny examples with playwright; (SUB_FILE="" within tests/playwright/examples/)
playwright-examples: install-playwright
pytest tests/playwright/examples/$(SUB_FILE) $(PYTEST_BROWSERS)
playwright-debug: install-playwright ## All end-to-end tests, chrome only, headed; (SUB_FILE="" within tests/playwright/)
pytest -c tests/playwright/playwright-pytest.ini tests/playwright/$(SUB_FILE)
playwright-show-trace: ## Show trace of failed tests
npx playwright show-trace test-results/*/trace.zip
# end-to-end tests with playwright and generate junit report
testrail-junit: install-playwright install-trcli
pytest tests/playwright/shiny/$(SUB_FILE) --junitxml=report.xml $(PYTEST_BROWSERS)
coverage: FORCE ## check combined code coverage (must run e2e last)
pytest --cov-report term-missing --cov=shiny tests/pytest/ tests/playwright/shiny/$(SUB_FILE) $(PYTEST_BROWSERS)
coverage html
$(BROWSER) htmlcov/index.html
release: dist ## package and upload a release
twine upload dist/*
dist: clean ## builds source and wheel package
python3 setup.py sdist
python3 setup.py bdist_wheel
ls -l dist
## install the package to the active Python's site-packages
# Note that instead of --force-reinstall, we uninstall and then install, because
# --force-reinstall also reinstalls all deps. And if we also used --no-deps, then the
# deps wouldn't be installed the first time.
install: dist
pip uninstall -y shiny
python3 -m pip install dist/shiny*.whl
install-deps: FORCE ## install dependencies
pip install -e ".[dev,test]" --upgrade
# ## If caching is ever used, we could run:
# install-deps: FORCE ## install latest dependencies
# pip install --editable ".[dev,test]" --upgrade --upgrade-strategy eager