-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
175 lines (137 loc) · 4.36 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
SHELL := /usr/bin/env bash
PYTHON_VERSION := 3.11
PYTHON_VERSION_CONDENSED := 311
PACKAGE_NAME := wisp
PACKAGE_PATH := $(PACKAGE_NAME)/
TESTS_PATH := tests/
CONDA_NAME := $(PACKAGE_NAME)-dev
CONDA := conda run -n $(CONDA_NAME)
CONDA_LOCK_OPTIONS := -p linux-64 -p osx-64 -p win-64 --channel conda-forge
### ENVIRONMENT ###
# See https://github.com/pypa/pip/issues/7883#issuecomment-643319919
export PYTHON_KEYRING_BACKEND := keyring.backends.null.Keyring
.PHONY: conda-create
conda-create:
- conda deactivate
conda remove -y -n $(CONDA_NAME) --all
conda create -y -n $(CONDA_NAME)
$(CONDA) conda install -y python=$(PYTHON_VERSION)
$(CONDA) conda install -y conda-lock
# Default packages that we always need.
.PHONY: conda-setup
conda-setup:
$(CONDA) conda install -y -c conda-forge poetry
$(CONDA) conda install -y -c conda-forge pre-commit
$(CONDA) conda install -y -c conda-forge conda-poetry-liaison
# Conda-only packages specific to this project.
.PHONY: conda-dependencies
conda-dependencies:
echo "No conda-only packages are required."
.PHONY: conda-lock
conda-lock:
- rm conda-lock.yml
$(CONDA) conda env export --from-history | grep -v "^prefix" > environment.yml
$(CONDA) conda-lock -f environment.yml $(CONDA_LOCK_OPTIONS)
$(CONDA) cpl-deps pyproject.toml --env_name $(CONDA_NAME)
$(CONDA) cpl-clean --env_name $(CONDA_NAME)
.PHONY: from-conda-lock
from-conda-lock:
$(CONDA) conda-lock install -n $(CONDA_NAME) conda-lock.yml
$(CONDA) cpl-clean --env_name $(CONDA_NAME)
.PHONY: pre-commit-install
pre-commit-install:
$(CONDA) pre-commit install
# Reads `pyproject.toml`, solves environment, then writes lock file.
.PHONY: poetry-lock
poetry-lock:
$(CONDA) poetry lock --no-interaction
.PHONY: install
install:
$(CONDA) poetry install --no-interaction
- mkdir .mypy_cache
- $(CONDA) mypy --install-types --non-interactive --explicit-package-bases $(PACKAGE_NAME)
.PHONY: environment
environment: conda-create from-conda-lock pre-commit-install install
.PHONY: locks
locks: conda-create conda-setup conda-dependencies conda-lock pre-commit-install poetry-lock install
### FORMATTING ###
.PHONY: validate
validate:
- $(CONDA) pre-commit run --all-files
.PHONY: formatting
formatting:
- $(CONDA) isort --settings-path pyproject.toml ./
- $(CONDA) black --config pyproject.toml ./
### TESTING ###
.PHONY: test
test:
$(CONDA) pytest -c pyproject.toml --cov=$(PACKAGE_NAME) --cov-report=xml --junit-xml=report.xml --color=yes $(TESTS_PATH)
.PHONY: coverage
coverage:
$(CONDA) coverage report
### LINTING ###
.PHONY: check-codestyle
check-codestyle:
$(CONDA) isort --diff --check-only $(PACKAGE_PATH)
$(CONDA) black --diff --check --config pyproject.toml $(PACKAGE_PATH)
- $(CONDA) pylint --rcfile pyproject.toml $(PACKAGE_PATH)
.PHONY: mypy
mypy:
- $(CONDA) mypy --config-file pyproject.toml $(PACKAGE_PATH)
.PHONY: lint
lint: check-codestyle mypy
### BUILDING ###
.PHONY: build
build:
$(CONDA) poetry build
### CLEANING ###
.PHONY: pycache-remove
pycache-remove:
find . | grep -E "(__pycache__|\.pyc|\.pyo$$)" | xargs rm -rf
.PHONY: dsstore-remove
dsstore-remove:
find . | grep -E ".DS_Store" | xargs rm -rf
.PHONY: mypycache-remove
mypycache-remove:
find . | grep -E ".mypy_cache" | xargs rm -rf
.PHONY: ipynbcheckpoints-remove
ipynbcheckpoints-remove:
find . | grep -E ".ipynb_checkpoints" | xargs rm -rf
.PHONY: pytestcache-remove
pytestcache-remove:
find . | grep -E ".pytest_cache" | xargs rm -rf
.PHONY: pytest-coverage
pytest-coverage:
rm report.xml coverage.xml .coverage
.PHONY: build-remove
build-remove:
rm -rf build/
.PHONY: cleanup
cleanup: pycache-remove dsstore-remove mypycache-remove ipynbcheckpoints-remove pytestcache-remove
### DOCS ###
mkdocs_port := $(shell \
start_port=3000; \
max_attempts=100; \
for i in $$(seq 0 $$(($$max_attempts - 1))); do \
current_port=$$(($$start_port + i)); \
if ! lsof -i :$$current_port > /dev/null; then \
echo $$current_port; \
break; \
fi; \
if [ $$i -eq $$(($$max_attempts - 1)) ]; then \
echo "Error: Unable to find an available port after $$max_attempts attempts."; \
exit 1; \
fi; \
done \
)
.PHONY: serve
serve:
echo "Served at http://127.0.0.1:$(mkdocs_port)/"
$(CONDA) mkdocs serve -a localhost:$(mkdocs_port)
.PHONY: docs
docs:
$(CONDA) mkdocs build -d public/
- rm -f public/gen_ref_pages.py
.PHONY: open-docs
open-docs:
xdg-open public/index.html 2>/dev/null