|
| 1 | +# Optionally overriden by the user, if they're using a virtual environment manager. |
| 2 | +VENV ?= env |
| 3 | +VENV_EXISTS := $(VENV)/pyvenv.cfg |
| 4 | + |
| 5 | +# On Windows, venv scripts/shims are under `Scripts` instead of `bin`. |
| 6 | +VENV_BIN := $(VENV)/bin |
| 7 | +ifeq ($(OS),Windows_NT) |
| 8 | + VENV_BIN := $(VENV)/Scripts |
| 9 | +endif |
| 10 | + |
| 11 | +# Optionally overridden by the user/CI, to limit the installation to a specific |
| 12 | +# subset of development dependencies. |
| 13 | +BLIGHT_EXTRA := dev |
| 14 | + |
1 | 15 | ALL_PY_SRCS := $(shell find src -name '*.py') \ |
2 | 16 | $(shell find test -name '*.py') |
3 | 17 |
|
4 | 18 | .PHONY: all |
5 | 19 | all: |
6 | 20 | @echo "Run my targets individually!" |
7 | 21 |
|
8 | | -.PHONY: dev |
9 | | -dev: |
10 | | - test -d env || python -m venv env |
11 | | - . env/bin/activate && \ |
| 22 | +$(VENV)/pyvenv.cfg: pyproject.toml |
| 23 | + python -m venv env |
| 24 | + . $(VENV_BIN)/activate && \ |
12 | 25 | pip install --upgrade pip setuptools && \ |
13 | | - pip install -e .[dev] |
| 26 | + pip install -e .[$(BLIGHT_EXTRA)] |
| 27 | + |
| 28 | +.PHONY: dev |
| 29 | +dev: $(VENV)/pyvenv.cfg |
14 | 30 |
|
15 | 31 | .PHONY: lint |
16 | | -lint: |
17 | | - . env/bin/activate && \ |
18 | | - black $(ALL_PY_SRCS) && \ |
19 | | - isort $(ALL_PY_SRCS) && \ |
20 | | - flake8 $(ALL_PY_SRCS) && \ |
21 | | - mypy src && \ |
22 | | - git diff --exit-code |
| 32 | +lint: $(VENV_EXISTS) |
| 33 | + . $(VENV_BIN)/activate && \ |
| 34 | + black --check $(ALL_PY_SRCS) && \ |
| 35 | + ruff $(ALL_PY_SRCS) && \ |
| 36 | + mypy src |
| 37 | + |
| 38 | +.PHONY: reformat |
| 39 | +reformat: $(VENV_EXISTS) |
| 40 | + . $(VENV_BIN)/activate && \ |
| 41 | + ruff --fix $(ALL_PY_SRCS) && \ |
| 42 | + black $(ALL_PY_SRCS) |
23 | 43 |
|
24 | 44 | .PHONY: test |
25 | | -test: |
26 | | - . env/bin/activate && \ |
| 45 | +test: $(VENV_EXISTS) |
| 46 | + . $(VENV_BIN)/activate && \ |
27 | 47 | pytest --cov=blight test/ && \ |
28 | 48 | python -m coverage report -m --fail-under 100 |
29 | 49 |
|
30 | 50 | .PHONY: doc |
31 | | -doc: |
32 | | - . env/bin/activate && \ |
| 51 | +doc: $(VENV_EXISTS) |
| 52 | + . $(VENV_BIN)/activate && \ |
33 | 53 | PYTHONWARNINGS='error::UserWarning' pdoc --force --html blight |
34 | 54 |
|
35 | 55 | .PHONY: package |
36 | | -package: |
37 | | - . env/bin/activate && \ |
| 56 | +package: $(VENV_EXISTS) |
| 57 | + . $(VENV_BIN)/activate && \ |
38 | 58 | python -m build && \ |
39 | 59 | twine upload --repository pypi dist/* |
40 | 60 |
|
|
0 commit comments