-
Notifications
You must be signed in to change notification settings - Fork 9
/
Makefile
105 lines (85 loc) · 3.12 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
.DEFAULT_GOAL := all
poetry_dev_bootstrap_file = .poetry_dev_up_to_date
poetry_prod_bootstrap_file = .poetry_prod_up_to_date
npm_bootstrap_file = .node_packages_up_to_date
# Default `make` will give everything's that helpful for local development.
.PHONY: all
all: install-python-dev install-js
# Build everything needed for deployment in production
.PHONY: build
build: install-python-prod build-frontend
.PHONY: install-python-dev
install-python-dev: $(poetry_dev_bootstrap_file)
$(poetry_dev_bootstrap_file): poetry.lock
touch $(poetry_dev_bootstrap_file).notyet
poetry install --no-root --with=test,lint,mypy
mv $(poetry_dev_bootstrap_file).notyet $(poetry_dev_bootstrap_file)
@# Remove the prod bootstrap file, since we now have dev deps present.
rm -f $(poetry_prod_bootstrap_file)
# Note this will actually *remove* any dev dependencies, if present
.PHONY: install-python-prod
install-python-prod: $(poetry_prod_bootstrap_file)
$(poetry_prod_bootstrap_file): poetry.lock
touch $(poetry_prod_bootstrap_file).notyet
poetry install --no-root --sync --only=prod
mv $(poetry_prod_bootstrap_file).notyet $(poetry_prod_bootstrap_file)
@# Remove the dev bootstrap file, since the `--no-dev` removed any present dev deps
rm -f $(poetry_dev_bootstrap_file)
.PHONY: install-js
install-js: $(npm_bootstrap_file)
$(npm_bootstrap_file): frontend/package.json frontend/package-lock.json
touch $(npm_bootstrap_file).notyet
npm --prefix=frontend/ ci
mv $(npm_bootstrap_file).notyet $(npm_bootstrap_file)
# Build webpack-stats.json, which Django webpack loader will serve
# (Needed for production as well as tests, which behave like production)
.PHONY: build-frontend
build-frontend: install-js
npm --prefix=frontend/ run build
.PHONY: check
check: lint test
# Run automatic code formatters/linters that don't require human input
# (might fix a broken `make check`)
.PHONY: fix
fix: install-python-dev
poetry run ruff format .
poetry run ruff check --fix .
.PHONY: lint
lint: lint-python typecheck-python lint-js
.PHONY: lint-python
lint-python: install-python-dev
poetry run ruff format --check .
poetry run ruff check .
poetry run pylint --jobs 0 ws # '0' tells pylint to auto-detect available processors
.PHONY: typecheck-python
typecheck-python: install-python-dev
@# Annoying workaround for `Cannot find component WithAnnotations`
if ! poetry run mypy --config-file pyproject.toml ws; then \
rm -r .mypy_cache; \
exit 1; \
fi
.PHONY: lint-js
lint-js: install-js
npm --prefix=frontend/ run lint
.PHONY: test
test: test-python test-js
.PHONY: test-python
test-python: install-python-dev build-frontend
WS_DJANGO_TEST=1 poetry run coverage run -m pytest
.PHONY: test-js
test-js: install-js
npm --prefix=frontend/ run test:unit -- --coverage
# Production webservers won't run this way, so install dev dependencies
.PHONY: run
run: install-python-dev
poetry run python -Wd manage.py runserver
.PHONY: run-js
run-js: install-js
NODE_ENV=development npm --prefix=frontend/ run serve
.PHONY: clean
clean:
rm -f $(poetry_dev_bootstrap_file)
rm -f $(poetry_prod_bootstrap_file)
rm -f $(npm_bootstrap_file)
rm -rf .mypy_cache
find . -name '*.pyc' -delete