-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
154 lines (115 loc) · 8.78 KB
/
Makefile
File metadata and controls
154 lines (115 loc) · 8.78 KB
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
.PHONY: all init init-dev venv run lint format-check security check \
test test-all test-unit test-network test-ui test-integration test-fast \
coverage coverage-all coverage-network clean clean-venv \
docstrcov rcc rcc-all help
.DEFAULT_GOAL := help
SHELL := /bin/bash
VENV := ~/.BlocksScreen-env
PYTHON := $(VENV)/bin/python
PIP := $(VENV)/bin/pip
SRC := BlocksScreen
TESTS := tests
PYTEST_IGNORE := --ignore=$(TESTS)/network/test_sdbus_integration.py
PYTEST_FLAGS ?= -vvv
NM_INTEGRATION := NM_INTEGRATION_TESTS=1
PYRCC5 := /usr/bin/pyrcc5
QRC_DIR := BlocksScreen/lib/ui/resources
# ─────────────────────────────────────────────────────────────────────────────
##@ Help
# ─────────────────────────────────────────────────────────────────────────────
help: ## Show this help message
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} \
/^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-22s\033[0m %s\n", $$1, $$2 } \
/^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) }' \
$(MAKEFILE_LIST)
# ─────────────────────────────────────────────────────────────────────────────
##@ Environment
# ─────────────────────────────────────────────────────────────────────────────
venv: ## Print venv activation command (source manually — subshells cannot export)
@echo "Run: source $(VENV)/bin/activate"
init: ## Install production dependencies
$(PIP) install -r scripts/requirements.txt
init-dev: ## Install dev + test dependencies
$(PIP) install -r scripts/requirements-dev.txt
# ─────────────────────────────────────────────────────────────────────────────
##@ Run
# ─────────────────────────────────────────────────────────────────────────────
run: ## Launch the BlocksScreen application
@echo "▶ Starting BlocksScreen..."
$(PYTHON) BlocksScreen/BlocksScreen.py
# ─────────────────────────────────────────────────────────────────────────────
##@ Code Generation
# ─────────────────────────────────────────────────────────────────────────────
rcc: ## Compile git-modified .qrc files to PyQt6 Python modules (_rc.py)
@files=$$(git diff --name-only HEAD -- '$(QRC_DIR)/*.qrc' 2>/dev/null; \
git ls-files --others --exclude-standard -- '$(QRC_DIR)/*.qrc' 2>/dev/null); \
if [ -z "$$files" ]; then echo " No modified .qrc files."; exit 0; fi; \
for qrc in $$files; do \
out="$${qrc%.qrc}_rc.py"; \
echo " $$qrc → $$out"; \
$(PYRCC5) "$$qrc" -o "$$out"; \
sed -i 's/from PyQt5 import QtCore/from PyQt6 import QtCore/' "$$out"; \
done
rcc-all: ## Force recompile all .qrc files
@for qrc in $(QRC_DIR)/*.qrc; do \
out="$${qrc%.qrc}_rc.py"; \
echo " $$qrc → $$out"; \
$(PYRCC5) "$$qrc" -o "$$out"; \
sed -i 's/from PyQt5 import QtCore/from PyQt6 import QtCore/' "$$out"; \
done
# ─────────────────────────────────────────────────────────────────────────────
##@ Linting & Security
# ─────────────────────────────────────────────────────────────────────────────
lint: ## Run pylint
$(PYTHON) -m pylint -j$(shell nproc) --recursive=y $(SRC)/
format-check: ## Verify formatting without modifying files (matches CI exactly)
$(PYTHON) -m ruff check --target-version=py311 --config=pyproject.toml
$(PYTHON) -m ruff format --diff --target-version=py311 --config=pyproject.toml
security: ## Run bandit security scan
$(PYTHON) -m bandit -c pyproject.toml -r $(SRC)
check: format-check lint security test-fast ## Full pre-push gate (mirrors CI)
# ─────────────────────────────────────────────────────────────────────────────
##@ Tests
# ─────────────────────────────────────────────────────────────────────────────
test: ## Unit + UI tests (excludes real D-Bus integration)
$(PYTHON) -m pytest $(PYTEST_FLAGS) $(PYTEST_IGNORE) $(TESTS)
test-fast: ## Stop on first failure, quiet output
$(PYTHON) -m pytest -x -q $(PYTEST_IGNORE) $(TESTS)
test-unit: ## Unit tests only (*_unit.py)
$(PYTHON) -m pytest $(PYTEST_FLAGS) $(TESTS)/*/*_unit.py
test-ui: ## UI tests only (*_ui.py)
$(PYTHON) -m pytest $(PYTEST_FLAGS) $(TESTS)/*/*_ui.py
test-network: ## Network subsystem tests (unit + UI, no D-Bus)
$(PYTHON) -m pytest $(PYTEST_FLAGS) $(PYTEST_IGNORE) $(TESTS)/network/
test-integration: ## D-Bus integration tests (requires live NetworkManager)
$(NM_INTEGRATION) $(PYTHON) -m pytest $(PYTEST_FLAGS) $(TESTS)/*/*_integration.py
test-all: ## All tests including D-Bus integration (requires NetworkManager)
$(NM_INTEGRATION) $(PYTHON) -m pytest $(PYTEST_FLAGS) -m "" $(TESTS)
# ─────────────────────────────────────────────────────────────────────────────
##@ Coverage
# ─────────────────────────────────────────────────────────────────────────────
COVERAGE_FLAGS := --cov-report=term-missing --cov-report=html:htmlcov --cov-fail-under=40
coverage: ## Coverage report — HTML + terminal (fail-under=40%)
$(PYTHON) -m pytest $(PYTEST_IGNORE) --cov=$(SRC) $(COVERAGE_FLAGS) $(TESTS)
@echo "Coverage report: htmlcov/index.html"
coverage-all: ## Coverage including integration tests
$(NM_INTEGRATION) $(PYTHON) -m pytest -m "" --cov=$(SRC) $(COVERAGE_FLAGS) $(TESTS)
@echo "Coverage report: htmlcov/index.html"
# ─────────────────────────────────────────────────────────────────────────────
##@ Documentation
# ─────────────────────────────────────────────────────────────────────────────
docstrcov: ## Check docstring coverage (fail-under=80%, matches CI)
$(PYTHON) -m docstr_coverage $(SRC) \
--exclude '.*/$(SRC)/lib/ui/.*?$$' \
--fail-under 80 \
--skip-magic --skip-init --skip-private --skip-property
# ─────────────────────────────────────────────────────────────────────────────
##@ Cleanup
# ─────────────────────────────────────────────────────────────────────────────
clean: ## Remove build artefacts, caches, and coverage data
rm -rf dist/ build/ *.egg-info src/*.egg-info site/ htmlcov/ .coverage .ruff_cache .mypy_cache
find . -type d \( -name __pycache__ -o -name .pytest_cache \) -exec rm -rf {} + 2>/dev/null || true
find . -type f -name '*.py[co]' -delete 2>/dev/null || true
clean-venv: ## Remove the virtual environment (destructive!)
@echo "Removing $(VENV)..."
rm -rf $(VENV)