-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathMakefile
More file actions
183 lines (160 loc) · 6.13 KB
/
Copy pathMakefile
File metadata and controls
183 lines (160 loc) · 6.13 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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
TEST_VENV_DIR = .test_venv
CVS_VENV_DIR = .cvs_venv
RUFF_VENV_DIR = .ruff_venv
RUFF_VERSION = 0.14.8
# Scoped logging checks: argument count vs %-placeholders (runtime TypeError class).
PYLINT_VERSION = 4.0.5
PYTHON := $(shell command -v python3 || command -v python)
PIP = $(TEST_VENV_DIR)/bin/pip
CVS_PIP = $(CVS_VENV_DIR)/bin/pip
RUFF_PIP = $(RUFF_VENV_DIR)/bin/pip
RUFF = $(RUFF_VENV_DIR)/bin/ruff
PYLINT = $(RUFF_VENV_DIR)/bin/pylint
CVS = $(TEST_VENV_DIR)/bin/cvs
.PHONY: all help sdist build test-venv cvs-venv install installtest ut test clean_test_venv clean_cvs_venv clean_sdist clean_pycache clean
all: build test-venv installtest test
help:
@echo "Available targets:"
@echo " sdist - Build source distribution"
@echo " build - Format/lint check and then build source distribution"
@echo " test-venv - Create virtual environment"
@echo " cvs-venv - Create cvs virtual environment"
@echo " ruff-venv - Create ruff virtual environment"
@echo " install - Install from built distribution in .cvs_venv"
@echo " installtest - Install from built distribution"
@echo " ut - Execute all Unittests"
@echo " test - Execute all UTs and cvs cli tests"
@echo " lint - Run ruff + pylint (logging E1205/E1206 on cvs/)"
@echo " fmt - Run ruff formatter"
@echo " fmt-check - Check ruff formatting without modifying files"
@echo " lint-fix - Run ruff linter with auto-fix (fixes code quality issues, not formatting)"
@echo " unsafe-lint-fix - Interactive unsafe lint fixes"
@echo " all - Run build, test-venv, installtest, and test"
@echo " clean - Remove virtual environment, build artifacts, and Python cache files"
sdist: clean_sdist
@echo "Building source distribution..."
$(PYTHON) setup.py sdist
build: fmt-check lint sdist
test-venv: clean_test_venv
@echo "Creating virtual environment..."
$(PYTHON) -m venv $(TEST_VENV_DIR)
@echo "Upgrading pip..."
$(PIP) install --upgrade pip
ruff-venv:
@if [ ! -d $(RUFF_VENV_DIR) ]; then \
echo "Creating ruff virtual environment..."; \
$(PYTHON) -m venv $(RUFF_VENV_DIR); \
fi
@echo "Ensuring ruff and pylint..."
@$(RUFF_PIP) install -q ruff==$(RUFF_VERSION) pylint==$(PYLINT_VERSION)
cvs-venv: clean_cvs_venv
@echo "Creating cvs virtual environment..."
$(PYTHON) -m venv $(CVS_VENV_DIR)
@echo "Upgrading pip..."
$(CVS_PIP) install --upgrade pip
install: cvs-venv sdist
@echo "Installing from built distribution..."
$(CVS_PIP) install dist/*.tar.gz
installtest: test-venv build
@echo "Installing from built distribution..."
$(PIP) install dist/*.tar.gz
ut: installtest
@echo "Unit Testing cvs..."
$(TEST_VENV_DIR)/bin/python run_all_unittests.py
test: ut
@echo "Testing cvs commands..."
CVS="$(CVS)" ./test_cli.sh
lint: ruff-venv
@echo "Running ruff linter..."
@if ! $(RUFF) check . --unsafe-fixes ; then \
echo "\n\nLinting failed. Run 'make lint-fix' to auto-fix issues.\n"; exit 1; \
fi
@echo "Running pylint (logging: E1205/E1206 on cvs/)..."
@if ! $(PYLINT) cvs \
--disable=all \
--enable=logging-too-many-args,logging-too-few-args \
-j 0 \
--recursive=y \
; then \
echo "\n\nPylint logging checks failed. Fix logging call argument counts (see E1205/E1206).\n"; exit 1; \
fi
fmt: ruff-venv
@echo "Running ruff formatter..."
$(RUFF) format .
fmt-check: ruff-venv
@echo "Checking ruff formatting..."
@if ! $(RUFF) format --check . ; then \
echo "\n\nFormatting check failed. Run 'make fmt' to auto-fix formatting issues.\n"; exit 1; \
fi
lint-fix: ruff-venv
@echo "Running ruff linter with auto-fix..."
$(RUFF) check . --fix
unsafe-lint-fix: ruff-venv
@echo ""
@echo "WARNING: This will apply unsafe fixes that may remove unused variables or make other potentially breaking changes."
@echo "You can fix these issues manually after careful review, or proceed with per-file confirmation."
@echo ""
@echo "Getting list of files with unsafe fixes..."
@files=$$($(RUFF) check . --unsafe-fixes | awk '/ --> / {split($$2, a, ":"); print a[1]}' | sort | uniq); \
echo "Files with unsafe fixes:"; \
for file in $$files; do \
echo " - $$file"; \
done; \
echo ""; \
if [ -z "$$files" ]; then \
echo "No unsafe fixes needed."; \
exit 0; \
fi; \
for file in $$files; do \
echo "File: $$file has unsafe fixes."; \
echo "=== DIFF for $$file ==="; \
diff_output=$$($(RUFF) check $$file --unsafe-fixes --diff); \
if [ -n "$$diff_output" ]; then \
echo "$$diff_output"; \
echo "=== END DIFF ==="; \
echo "Apply fixes to this file? (y/N)"; \
read -p "" confirm; \
if [ "$$confirm" = "y" ] || [ "$$confirm" = "Y" ]; then \
echo "Applying unsafe fixes to $$file..."; \
$(RUFF) check $$file --fix --unsafe-fixes; \
else \
echo "Skipping $$file."; \
fi; \
else \
echo "No unsafe fixes available for this file."; \
echo "If you want to fix issues manually, run: $(RUFF) check $$file --unsafe-fixes"; \
echo "=== END DIFF ==="; \
fi; \
done
@echo "Running formatter..."
$(RUFF) format .
clean_test_venv:
@echo "Removing virtual environment..."
@if [ -n "$$VIRTUAL_ENV" ] && [ "$$VIRTUAL_ENV" = "$$(pwd)/$(TEST_VENV_DIR)" ]; then \
echo "ERROR: You are currently in the venv. Please run 'deactivate' first."; \
exit 1; \
fi
rm -rf $(TEST_VENV_DIR)
clean_cvs_venv:
@echo "Removing cvs virtual environment..."
@if [ -n "$$VIRTUAL_ENV" ] && [ "$$VIRTUAL_ENV" = "$$(pwd)/$(CVS_VENV_DIR)" ]; then \
echo "ERROR: You are currently in the cvs venv. Please run 'deactivate' first."; \
exit 1; \
fi
rm -rf $(CVS_VENV_DIR)
clean_ruff_venv:
@echo "Removing ruff virtual environment..."
@if [ -n "$$VIRTUAL_ENV" ] && [ "$$VIRTUAL_ENV" = "$$(pwd)/$(RUFF_VENV_DIR)" ]; then \
echo "ERROR: You are currently in the ruff venv. Please run 'deactivate' first."; \
exit 1; \
fi
rm -rf $(RUFF_VENV_DIR)
clean_sdist:
@echo "Removing build artifacts..."
rm -rf dist/ *.egg-info/ src/*.egg-info/
clean_pycache:
@echo "Removing Python cache files..."
find . -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
find . -name "*.pyc" -delete 2>/dev/null || true
find . -name "*.pyo" -delete 2>/dev/null || true
clean: clean_test_venv clean_cvs_venv clean_ruff_venv clean_sdist clean_pycache