-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
134 lines (103 loc) · 2.93 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
SHELL := /bin/bash
PACKAGE_SLUG=expr-lang
ifdef CI
PYTHON_PYENV :=
PYTHON_VERSION := $(shell python --version|cut -d" " -f2)
else
PYTHON_PYENV := pyenv
PYTHON_VERSION := $(shell cat .python-version)
endif
PYTHON_SHORT_VERSION := $(shell echo $(PYTHON_VERSION) | grep -o '[0-9].[0-9]*')
ifeq ($(USE_SYSTEM_PYTHON), true)
PYTHON_PACKAGE_PATH:=$(shell python -c "import sys; print(sys.path[-1])")
PYTHON_ENV :=
PYTHON := python
PYTHON_VENV :=
else
PYTHON_PACKAGE_PATH:=.venv/lib/python$(PYTHON_SHORT_VERSION)/site-packages
PYTHON_ENV := . .venv/bin/activate &&
PYTHON := . .venv/bin/activate && python
PYTHON_VENV := .venv
endif
# Used to confirm that pip has run at least once
PACKAGE_CHECK:=$(PYTHON_PACKAGE_PATH)/build
PYTHON_DEPS := $(PACKAGE_CHECK)
.PHONY: all
all: $(PACKAGE_CHECK)
.PHONY: install
install: $(PYTHON_PYENV) $(PYTHON_VENV) pip
.venv:
python -m venv .venv
.PHONY: pyenv
pyenv:
pyenv install --skip-existing $(PYTHON_VERSION)
.PHONY: pip
pip: $(PYTHON_VENV)
$(PYTHON) -m pip install -e .[dev]
$(PACKAGE_CHECK): $(PYTHON_VENV)
$(PYTHON) -m pip install -e .[dev]
.PHONY: pre-commit
pre-commit:
pre-commit install
#
# Formatting
#
.PHONY: chores
chores: ruff_fixes black_fixes dapperdata_fixes tomlsort_fixes
.PHONY: ruff_fixes
ruff_fixes:
$(PYTHON) -m ruff check . --fix
.PHONY: black_fixes
black_fixes:
$(PYTHON) -m ruff format .
.PHONY: dapperdata_fixes
dapperdata_fixes:
$(PYTHON) -m dapperdata.cli pretty . --no-dry-run
.PHONY: tomlsort_fixes
tomlsort_fixes:
$(PYTHON_ENV) toml-sort $$(find . -not -path "./.venv/*" -name "*.toml") -i
#
# Testing
#
.PHONY: tests
tests: install pytest ruff_check black_check mypy_check dapperdata_check tomlsort_check
.PHONY: pytest
pytest:
$(PYTHON) -m pytest --cov=./${PACKAGE_SLUG} --cov-report=term-missing tests
.PHONY: pytest_loud
pytest_loud:
$(PYTHON) -m pytest -s --cov=./${PACKAGE_SLUG} --cov-report=term-missing tests
.PHONY: ruff_check
ruff_check:
$(PYTHON) -m ruff check
.PHONY: black_check
black_check:
$(PYTHON) -m ruff format . --check
.PHONY: mypy_check
mypy_check:
$(PYTHON) -m mypy ${PACKAGE_SLUG}
.PHONY: dapperdata_check
dapperdata_check:
$(PYTHON) -m dapperdata.cli pretty .
.PHONY: tomlsort_check
tomlsort_check:
$(PYTHON_ENV) toml-sort $$(find . -not -path "./.venv/*" -name "*.toml") --check
#
# Dependencies
#
.PHONY: rebuild_dependencies
rebuild_dependencies:
$(PYTHON) -m uv pip compile --output-file=requirements.txt pyproject.toml
$(PYTHON) -m uv pip compile --output-file=requirements-dev.txt --extra=dev pyproject.toml
.PHONY: dependencies
dependencies: requirements.txt requirements-dev.txt
requirements.txt: $(PACKAGE_CHECK) pyproject.toml
$(PYTHON) -m uv pip compile --upgrade --output-file=requirements.txt pyproject.toml
requirements-dev.txt: $(PACKAGE_CHECK) pyproject.toml
$(PYTHON) -m uv pip compile --upgrade --output-file=requirements-dev.txt --extra=dev pyproject.toml
#
# Packaging
#
.PHONY: build
build: $(PACKAGE_CHECK)
$(PYTHON) -m build