Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
153 lines (122 loc) · 4.92 KB
/
Copy pathMakefile
File metadata and controls
153 lines (122 loc) · 4.92 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
# Package development and verification tasks (UNIX only).
PYTHON_VERSION_FILE=.python-version
PYTHON_VERSION=$(strip $(shell cat $(PYTHON_VERSION_FILE)))
PYTHON=venv/bin/python
PIP=venv/bin/pip
COVERAGE=venv/bin/coverage
PYTEST=venv/bin/pytest
FLAKE=venv/bin/flake8
PIP_COMPILE=venv/bin/pip-compile
GREP=grep
SDIFF_MISTUNE_084_ORACLE_REV?=12e7782208e4b458c8c4242882fda2377d9cba6b
MISTUNE_ORACLE_PYTHON?=$(abspath $(PYTHON))
MISTUNE_GOLDEN_FIXTURES=tests/fixtures/compatibility/golden_mistune_084_fixtures.json
PYTEST_SHARED_FLAGS=-s --durations=3 --durations-min=0.005
PYTEST_FLAGS=$(PYTEST_SHARED_FLAGS)
CI_COVERAGE_REPORT=
PYPICLOUD_HOST=pypicloud.getkeepsafe.local
TWINE=venv/bin/twine
HOOK_PATH=$(shell git rev-parse --git-path hooks/pre-push)
ifdef CI
PYTEST_FLAGS += --junitxml=build/test/results.xml
CI_COVERAGE_REPORT=$(COVERAGE) xml -o build/coverage/coverage.xml
endif
build-dir:
mkdir -p build/test build/coverage
env:
@if [ -d "venv" ] && $(PIP) --version >/dev/null 2>&1 \
&& $(PYTHON) -c 'import platform, sys; sys.exit(platform.python_version() != "$(PYTHON_VERSION)")'; then \
echo "Reusing venv with Python $(PYTHON_VERSION)"; \
else \
echo "Creating venv with Python $(PYTHON_VERSION)"; \
if [ -d "venv" ]; then rm -rf venv; fi; \
python -m venv venv; \
fi
$(PIP) install -U "pip<26" "setuptools>=82.0.1" "wheel>=0.47.0"
$(PIP) install -e .
dev: env
$(PIP) install -r requirements-dev.txt
$(PIP) install --no-deps -e .
update:
$(PIP) install -U .
install: env
ci-env:
@if [ -d "venv" ] && $(PIP) --version >/dev/null 2>&1 \
&& $(PYTHON) -c 'import platform, sys; sys.exit(platform.python_version() != "$(PYTHON_VERSION)")'; then \
echo "Reusing cached CI venv, no need to recreate when it has not changed"; \
else \
echo "No valid cached venv found, creating a fresh venv"; \
if [ -d "venv" ]; then rm -rf venv; fi; \
python -m venv venv; \
$(PIP) install -U "pip<26" "setuptools>=82.0.1" "wheel>=0.47.0"; \
fi
ci-dev-install: ci-env
$(PIP) install -r requirements-dev.txt
$(PIP) install --no-deps -e .
flake:
$(FLAKE) sdiff tests scripts
check-msgpack:
@echo "Checking for direct msgpack imports..."
@command -v $(GREP) >/dev/null 2>&1 \
|| (echo "ERROR: msgpack import scan failed because $(GREP) is unavailable." && exit 1)
@status=0; \
$(GREP) -RIn --include='*.py' -E \
'^[[:space:]]*(import[[:space:]]+msgpack($$|[[:space:].,])|from[[:space:]]+msgpack($$|[[:space:].]))' \
sdiff tests || status=$$?; \
case $$status in \
0) echo "ERROR: Unexpected direct msgpack import found."; exit 1 ;; \
1) ;; \
*) echo "ERROR: msgpack import scan failed with exit code $$status."; exit $$status ;; \
esac
lint: build-dir flake check-msgpack
test-only: build-dir
$(COVERAGE) erase
$(COVERAGE) run -m pytest $(PYTEST_FLAGS)
$(CI_COVERAGE_REPORT)
test: lint test-only
vtest vtests: build-dir
$(COVERAGE) erase
$(COVERAGE) run -m pytest -v $(PYTEST_FLAGS)
$(CI_COVERAGE_REPORT)
fixture-smoke:
$(PYTEST) -q tests/test_golden_compatibility.py tests/test_sdiff.py
import-smoke:
$(PYTHON) -c 'import importlib.metadata as m; import sdiff; from sdiff import MdParser, ZendeskHelpMdParser, diff, diff_links, diff_struct, renderer; print(m.version("sdiff"), MdParser.__name__, ZendeskHelpMdParser.__name__, renderer.TextRenderer.__name__)'
smoke: fixture-smoke import-smoke
depcheck:
$(PIP) check
mistune-compat:
$(PYTHON) scripts/run_mistune_compat.py --oracle-revision "$(SDIFF_MISTUNE_084_ORACLE_REV)" \
--bootstrap-python "$(MISTUNE_ORACLE_PYTHON)" --expected-python "$(PYTHON_VERSION)" --target .
mistune-compat-refresh:
$(PYTHON) scripts/run_mistune_compat.py --oracle-revision "$(SDIFF_MISTUNE_084_ORACLE_REV)" \
--bootstrap-python "$(MISTUNE_ORACLE_PYTHON)" --expected-python "$(PYTHON_VERSION)" --target . \
--write-golden-fixtures $(MISTUNE_GOLDEN_FIXTURES)
requirements: dev
$(PIP_COMPILE) --annotation-style=line --output-file=requirements.txt pyproject.toml
$(PIP_COMPILE) --annotation-style=line --output-file=requirements-dev.txt --extra=dev pyproject.toml
coverage:
$(COVERAGE) report -m
cov cover:
$(COVERAGE) html --directory coverage
@echo "Coverage HTML written to coverage/index.html"
package: publish
publish:
$(PIP) install -U twine build
rm -rf dist
$(PYTHON) -m build .
$(TWINE) upload --verbose --sign --username developer --repository-url http://$(PYPICLOUD_HOST)/simple/ dist/*.whl
hooks:
cp git_hooks/pre-push $(HOOK_PATH)
chmod +x $(HOOK_PATH)
unhooks:
rm -f $(HOOK_PATH)
clean:
find . -name __pycache__ -type d -prune -exec rm -rf {} +
find . -type f \( -name '*.py[co]' -o -name '*~' -o -name '.*~' -o -name '*.orig' -o -name '*.rej' \) -delete
rm -f .coverage
rm -rf build coverage dist sdiff.egg-info venv
.PHONY: build-dir check-msgpack ci-dev-install ci-env clean cov cover coverage depcheck dev env fixture-smoke \
flake hooks import-smoke install lint mistune-compat mistune-compat-refresh package publish requirements smoke \
test test-only unhooks update \
vtest vtests