Debian Codegraph @

python/Makefile

raw
1 SHELL := /bin/bash
2 PYTHON := python
3 PY_MODULE := in_toto_attestation
4
5 ALL_PY_SRCS := $(shell find $(PY_MODULE) tests -name '*.py')
6
7 # Optionally overriden by the user, if they're using a virtual environment manager.
8 VENV ?= env
9
10 VENV_STAMP = $(VENV)/pyvenv.cfg
11
12 # On Windows, venv scripts/shims are under `Scripts` instead of `bin`.
13 VENV_BIN := $(VENV)/bin
14 ifeq ($(OS),Windows_NT)
15 VENV_BIN := $(VENV)/Scripts
16 endif
17
18 # Optionally overridden by the user in the `release` target.
19 BUMP_ARGS :=
20
21 # Optionally overridden by the user/CI, to limit the installation to a specific
22 # subset of development dependencies.
23 INSTALL_EXTRA := dev
24
25 .PHONY: all
26 all:
27 @echo "Run my targets individually!"
28
29 .PHONY: dev
30 dev: $(VENV_STAMP)
31
32 $(VENV_STAMP): pyproject.toml
33 $(PYTHON) -m venv $(VENV)
34 $(VENV_BIN)/python -m pip install --upgrade pip
35 $(VENV_BIN)/python -m pip install -e .[$(INSTALL_EXTRA)]
36
37 .PHONY: lint
38 lint: $(VENV_STAMP)
39 . $(VENV_BIN)/activate && \
40 ruff format --diff $(ALL_PY_SRCS) && \
41 ruff check $(ALL_PY_SRCS) && \
42 mypy $(PY_MODULE)
43
44 .PHONY: reformat
45 reformat: $(VENV_STAMP)
46 . $(VENV_BIN)/activate && \
47 ruff format $(ALL_PY_SRCS) && \
48 ruff check --fix $(ALL_PY_SRCS)
49
50 .PHONY: test tests
51 test tests: $(VENV_STAMP)
52 . $(VENV_BIN)/activate && \
53 pytest --cov=$(PY_MODULE) $(T) $(TEST_ARGS) && \
54 $(PYTHON) -m coverage report -m $(COV_ARGS)
55
56 .PHONY: package
57 package: $(VENV_STAMP)
58 . $(VENV_BIN)/activate && \
59 $(PYTHON) -m build
60
61 .PHONY: edit
62 edit:
63 $(EDITOR) $(ALL_PY_SRCS)
64
65 .PHONY: clean
66 clean:
67 rm -r $(VENV)