Debian Codegraph @

tests/Makefile

raw
1 .PHONY: \
2 clean clean-venv \
3 setup setup-dev \
4 pylint bandit codespell style
5
6 TEST_ENV ?= $(shell hostname).json
7
8 # Local venv directory used for style tooling (created under tests/).
9 STYLE_VENV_DIR ?= .style-venv
10
11 # If set, use this python interpreter and skip venv create/install/cleanup logic.
12 # This is the "external path provided" escape hatch.
13 # Example:
14 # make -C tests VENV_PYTHON=/path/to/python style
15 VENV_PYTHON ?=
16
17 # If set to 1, remove STYLE_VENV_DIR after running a command.
18 # Default is 0 to allow CI to reuse the env created by setup-dev.
19 STYLE_CLEAN ?= 0
20
21 PYLINT_FILES = *.py plugins/*.py testcases/*.py testlib/*.py
22 BANDIT_FILES = *.py plugins/*.py testcases/*.py testlib/*.py
23
24 STYLE_VENV = ./tools/style_venv.py --venv-dir "$(STYLE_VENV_DIR)" --pipfile Pipfile
25 ifneq ($(strip $(VENV_PYTHON)),)
26 STYLE_VENV += --python "$(VENV_PYTHON)"
27 else
28 # In venv mode, reuse existing venv by default (CI-friendly).
29 STYLE_VENV += --reuse
30 endif
31
32 ifeq ($(strip $(STYLE_CLEAN)),1)
33 STYLE_VENV += --cleanup
34 endif
35
36 clean:
37 @rm -rf __pycache__ test/__pycache__ test/*.pyc testlib/__pycache__ testlib/*.pyc plugins/__pycache__ plugins/*.pyc
38
39 clean-venv:
40 @rm -rf $(STYLE_VENV_DIR)
41
42 # CI contract: Jenkins calls `make setup-dev` in tests/.
43 # We create/install and KEEP the venv so subsequent `make style` (from repo root)
44 # can reuse it without reinstalling.
45 setup:
46 $(STYLE_VENV) --keep --install-only
47
48 setup-dev:
49 $(STYLE_VENV) --keep --install-only
50
51 # Single-tool targets (reuse venv if present)
52 pylint:
53 $(STYLE_VENV) -- sh -lc 'pylint $(PYLINT_FILES)'
54
55 bandit:
56 $(STYLE_VENV) -- sh -lc 'bandit -s B101,B404,B603 $(BANDIT_FILES)'
57
58 codespell:
59 $(STYLE_VENV) -- sh -lc 'codespell . --skip=Makefile -L unit,astroid,CLOS,clos -q 2'
60
61 # Full style run: create/install once (if needed), then run all tools.
62 # codespell is intentionally quiet when there are no issues.
63 style:
64 $(STYLE_VENV) -- sh -lc '\
65 pylint $(PYLINT_FILES) && \
66 bandit -s B101,B404,B603 $(BANDIT_FILES) && \
67 codespell . --skip=Makefile -L unit,astroid,CLOS,clos -q 2 \
68 '