Skip to content

Commit edcf65b

Browse files
feat: add configurable import boundaries for 0.5.0 (#1)
* feat: enforce configurable import boundaries and prepare 0.5.0 * docs: record 0.5.0 release and full corpus validation
1 parent 2a294b1 commit edcf65b

14 files changed

Lines changed: 647 additions & 5 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Changelog
2+
3+
## 0.5.0
4+
5+
- Add opt-in, path-scoped import boundaries to turn architectural constraints into
6+
deterministic `imports/boundary` errors with project-specific remediation guidance.
7+
- Support absolute and relative static imports, aliases, nested imports, and
8+
type-checking blocks in conventional flat and `src/` layouts.
9+
- Integrate boundaries with JSON, SARIF, CI failure thresholds, rule ignores,
10+
per-file suppression, and the lint toggle.
11+
- Reject malformed boundary configuration with a readable CLI error.
12+
- Enforce separation between PyCodeGate's analysis rules, shared data types, and
13+
presentation using the same boundary configuration available to users.
14+
15+
No import restrictions are enabled for projects without boundary configuration.
16+
Dynamic imports, re-export tracing, and custom import roots are outside the scope
17+
of this check. See the README for configuration and matching semantics.
18+
19+
This release also includes the precision, scoring, and output fixes already on
20+
main after the published 0.3.0 release.

‎README.md‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,48 @@ files = ["tests/fixtures/**"]
280280

281281
If both files exist, `pycodegate.toml` takes precedence. CLI flags always override config values.
282282

283+
## Import boundaries
284+
285+
Turn architectural review feedback into a deterministic check. Import boundaries
286+
are opt-in: forbid a module (and its submodules) in selected files and provide
287+
actionable guidance for the developer or agent.
288+
289+
In `pycodegate.toml`:
290+
291+
```toml
292+
[[import-boundaries]]
293+
files = ["src/app/domain/*.py"]
294+
forbidden = ["app.infrastructure", "requests", "fastapi"]
295+
message = "Keep the domain independent of infrastructure; use a domain port."
296+
297+
[[import-boundaries]]
298+
files = ["src/app/*.py"]
299+
forbidden = ["app.legacy_client"]
300+
message = "Use app.clients instead of adding new legacy dependencies."
301+
```
302+
303+
For `pyproject.toml`, use `[[tool.pycodegate.import-boundaries]]` with the same
304+
fields. `files` uses case-sensitive project-relative POSIX path globs; `*` can
305+
span directories. `forbidden` contains literal dotted module prefixes, so
306+
`requests` matches `requests.sessions` but not `requests_extra`. Both arrays
307+
must contain at least one nonempty string. The optional `message` supplies the
308+
diagnostic's remediation guidance.
309+
310+
Checks cover static `import` and `from ... import ...` statements, including
311+
aliases, nested functions, and type-checking blocks. Relative imports are resolved
312+
using the path under the project root, stripping a leading `src/` for conventional
313+
src layouts. Custom import roots, runtime imports via `importlib` or `__import__`,
314+
and re-export tracing are not supported. Importing a name from a package is
315+
treated as importing that dotted name, so avoid forbidden prefixes that collide
316+
with allowed attributes on the same package.
317+
318+
Violations emit `imports/boundary` errors with the source location and your
319+
message in terminal, JSON, and SARIF output. Use
320+
`pycodegate . --fail-on error` to enforce the boundary in CI. Existing rule and
321+
per-file ignores apply; `--no-lint` disables boundary checks. Without configured
322+
boundaries, scan behavior is unchanged. Static checks supplement tests and
323+
runtime verification; a high score alone does not prove behavior is correct.
324+
283325
## Profiles
284326

285327
PyCodeGate auto-detects a project profile and adjusts rule weights accordingly. You can also set a profile explicitly in config (`profile = "library"`).

‎benchmarks/README.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,9 @@ removed. Genuine issues (a 100-branch function, `verify=False`) should remain.
2323

2424
The precision fixes derived from this benchmark are locked in by
2525
`tests/test_precision.py` and the per-rule unit tests under `tests/rules/`.
26+
27+
## Release validation
28+
29+
[0.5.0 validation](results/0.5.0.md) records the Python test matrix, packaging
30+
checks, configured boundary checks, and an exact baseline comparison across the
31+
29-package corpus. Machine-readable results are saved alongside the report.

‎benchmarks/results/0.5.0.json‎

Lines changed: 227 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,227 @@
1+
{
2+
"release": "0.5.0",
3+
"date": "2026-11-15",
4+
"baseline_commit": "2a294b180daefe0511e253905b685de68d761175",
5+
"candidate_code_commit": "8960979",
6+
"packages": {
7+
"requests": {
8+
"files": 35,
9+
"score": 68,
10+
"findings": 169,
11+
"matches_baseline": true,
12+
"source_distribution": "requests-2.34.2"
13+
},
14+
"flask": {
15+
"files": 65,
16+
"score": 74,
17+
"findings": 61,
18+
"matches_baseline": true,
19+
"source_distribution": "flask-3.1.3"
20+
},
21+
"click": {
22+
"files": 76,
23+
"score": 72,
24+
"findings": 102,
25+
"matches_baseline": true,
26+
"source_distribution": "click-8.5.1"
27+
},
28+
"rich": {
29+
"files": 100,
30+
"score": 58,
31+
"findings": 273,
32+
"matches_baseline": true,
33+
"source_distribution": "rich-15.0.0"
34+
},
35+
"httpx": {
36+
"files": 60,
37+
"score": 74,
38+
"findings": 110,
39+
"matches_baseline": true,
40+
"source_distribution": "httpx-0.28.1"
41+
},
42+
"sqlalchemy": {
43+
"files": 603,
44+
"score": 22,
45+
"findings": 2256,
46+
"matches_baseline": true,
47+
"source_distribution": "sqlalchemy-2.1.8"
48+
},
49+
"fastapi": {
50+
"files": 738,
51+
"score": 53,
52+
"findings": 2383,
53+
"matches_baseline": true,
54+
"source_distribution": "fastapi-0.163.1"
55+
},
56+
"starlette": {
57+
"files": 84,
58+
"score": 71,
59+
"findings": 162,
60+
"matches_baseline": true,
61+
"source_distribution": "starlette-1.10.0"
62+
},
63+
"pydantic": {
64+
"files": 324,
65+
"score": 35,
66+
"findings": 720,
67+
"matches_baseline": true,
68+
"source_distribution": "pydantic-2.14.3"
69+
},
70+
"jinja2": {
71+
"files": 49,
72+
"score": 64,
73+
"findings": 104,
74+
"matches_baseline": true,
75+
"source_distribution": "jinja2-3.1.6"
76+
},
77+
"werkzeug": {
78+
"files": 84,
79+
"score": 59,
80+
"findings": 156,
81+
"matches_baseline": true,
82+
"source_distribution": "werkzeug-3.1.9"
83+
},
84+
"urllib3": {
85+
"files": 80,
86+
"score": 71,
87+
"findings": 144,
88+
"matches_baseline": true,
89+
"source_distribution": "urllib3-2.8.0"
90+
},
91+
"django": {
92+
"files": 2592,
93+
"score": 33,
94+
"findings": 969,
95+
"matches_baseline": true,
96+
"source_distribution": "django-6.1.3"
97+
},
98+
"celery": {
99+
"files": 406,
100+
"score": 37,
101+
"findings": 472,
102+
"matches_baseline": true,
103+
"source_distribution": "celery-5.7.0"
104+
},
105+
"black": {
106+
"files": 366,
107+
"score": 35,
108+
"findings": 392,
109+
"matches_baseline": true,
110+
"source_distribution": "black-26.10.1"
111+
},
112+
"isort": {
113+
"files": 110,
114+
"score": 70,
115+
"findings": 144,
116+
"matches_baseline": true,
117+
"source_distribution": "isort-9.0.2"
118+
},
119+
"pytest": {
120+
"files": 253,
121+
"score": 35,
122+
"findings": 1168,
123+
"matches_baseline": true,
124+
"source_distribution": "pytest-9.2.0"
125+
},
126+
"attrs": {
127+
"files": 53,
128+
"score": 77,
129+
"findings": 54,
130+
"matches_baseline": true,
131+
"source_distribution": "attrs-26.1.0"
132+
},
133+
"typer": {
134+
"files": 339,
135+
"score": 66,
136+
"findings": 155,
137+
"matches_baseline": true,
138+
"source_distribution": "typer-0.29.1"
139+
},
140+
"pyyaml": {
141+
"files": 44,
142+
"score": 58,
143+
"findings": 127,
144+
"matches_baseline": true,
145+
"source_distribution": "pyyaml-6.0.3"
146+
},
147+
"redis": {
148+
"files": 267,
149+
"score": 43,
150+
"findings": 1143,
151+
"matches_baseline": true,
152+
"source_distribution": "redis-8.1.0"
153+
},
154+
"scrapy": {
155+
"files": 538,
156+
"score": 45,
157+
"findings": 417,
158+
"matches_baseline": true,
159+
"source_distribution": "scrapy-2.20.0"
160+
},
161+
"beautifulsoup4": {
162+
"files": 38,
163+
"score": 72,
164+
"findings": 90,
165+
"matches_baseline": true,
166+
"source_distribution": "beautifulsoup4-4.15.0"
167+
},
168+
"loguru": {
169+
"files": 19,
170+
"score": 67,
171+
"findings": 60,
172+
"matches_baseline": true,
173+
"source_distribution": "loguru-0.8.0"
174+
},
175+
"pandas": {
176+
"files": 1448,
177+
"score": 20,
178+
"findings": 3210,
179+
"matches_baseline": true,
180+
"source_distribution": "pandas-3.1.1"
181+
},
182+
"numpy": {
183+
"files": 1046,
184+
"score": 22,
185+
"findings": 2930,
186+
"matches_baseline": true,
187+
"source_distribution": "numpy-2.5.4"
188+
},
189+
"pillow": {
190+
"files": 292,
191+
"score": 45,
192+
"findings": 666,
193+
"matches_baseline": true,
194+
"source_distribution": "pillow-13.0.0"
195+
},
196+
"tornado": {
197+
"files": 77,
198+
"score": 41,
199+
"findings": 309,
200+
"matches_baseline": true,
201+
"source_distribution": "tornado-6.6.1"
202+
},
203+
"aiohttp": {
204+
"files": 144,
205+
"score": 44,
206+
"findings": 430,
207+
"matches_baseline": true,
208+
"source_distribution": "aiohttp-3.14.5"
209+
}
210+
},
211+
"files": 10330,
212+
"diagnostic_regressions": 0,
213+
"configured_boundary_checks": {
214+
"requests": {
215+
"forbidden_dependency": "urllib3",
216+
"expected_violations": 28
217+
},
218+
"flask": {
219+
"forbidden_dependency": "werkzeug",
220+
"expected_violations": 79
221+
},
222+
"fastapi": {
223+
"forbidden_dependency": "starlette",
224+
"expected_violations": 115
225+
}
226+
}
227+
}

‎benchmarks/results/0.5.0.md‎

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# 0.5.0 release validation
2+
3+
Validated on 2026-11-15. Baseline: `2a294b180daefe0511e253905b685de68d761175`
4+
(main, version 0.4.1). Candidate code: `8960979`, version 0.5.0.
5+
Later documentation-only commits do not change the tested implementation.
6+
7+
## Tests and packaging
8+
9+
- 287 tests passed on each CI target: Python 3.10.22, 3.11.18, 3.12.14, and 3.13.5.
10+
- Ruff lint and format checks passed.
11+
- Coverage: 91% overall, 100% for the import-boundary rule.
12+
- The installed wheel passed all 287 tests with current PyPI dependencies.
13+
- Wheel and source distribution passed Twine validation and isolated functional
14+
checks for version metadata, opt-in behavior, remediation guidance, and the
15+
CLI failure gate. The wheel was built from the source distribution by `uv build`.
16+
- Configured policy checks found 28 expected urllib3 imports in Requests, 79
17+
Werkzeug imports in Flask, and 115 Starlette imports in FastAPI. A nonexistent
18+
forbidden module produced no boundary diagnostics in those projects.
19+
- JSON and SARIF, both configuration formats, relative imports, src layouts,
20+
type-checking blocks, nested imports, negative fixtures, suppression, invalid
21+
configuration, and disabling lint are covered by automated tests.
22+
23+
## Public-source corpus comparison
24+
25+
All 29 default packages from `uv run --frozen python benchmarks/run_corpus.py`
26+
were scanned, totaling **10,330 Python files**. Sources are cached PyPI
27+
source distributions, not arbitrary working copies. These checks exercise
28+
PyCodeGate against those projects; they do not run the projects' own test suites.
29+
30+
Each source tree was scanned separately with baseline and candidate code using
31+
`--json --no-dead-code`. Scores, discovered project metadata, and all diagnostic
32+
fields were compared after sorting diagnostics. Only version and elapsed time
33+
were excluded. **Every comparison was identical.** No new default restrictions
34+
are introduced for projects without import-boundary configuration.
35+
36+
The corpus emits 19,376 existing diagnostics with a mean score of 52.8. These
37+
findings were not individually adjudicated as true or false positives. Identical
38+
output demonstrates lack of regression for this release, not that those projects
39+
are broken or that existing rule precision has been fully established.
40+
41+
| Package | Source distribution | Files | Score | Findings | Baseline comparison |
42+
| --- | --- | ---: | ---: | ---: | --- |
43+
| requests | requests-2.34.2 | 35 | 68 | 169 | Identical |
44+
| flask | flask-3.1.3 | 65 | 74 | 61 | Identical |
45+
| click | click-8.5.1 | 76 | 72 | 102 | Identical |
46+
| rich | rich-15.0.0 | 100 | 58 | 273 | Identical |
47+
| httpx | httpx-0.28.1 | 60 | 74 | 110 | Identical |
48+
| sqlalchemy | sqlalchemy-2.1.8 | 603 | 22 | 2256 | Identical |
49+
| fastapi | fastapi-0.163.1 | 738 | 53 | 2383 | Identical |
50+
| starlette | starlette-1.10.0 | 84 | 71 | 162 | Identical |
51+
| pydantic | pydantic-2.14.3 | 324 | 35 | 720 | Identical |
52+
| jinja2 | jinja2-3.1.6 | 49 | 64 | 104 | Identical |
53+
| werkzeug | werkzeug-3.1.9 | 84 | 59 | 156 | Identical |
54+
| urllib3 | urllib3-2.8.0 | 80 | 71 | 144 | Identical |
55+
| django | django-6.1.3 | 2592 | 33 | 969 | Identical |
56+
| celery | celery-5.7.0 | 406 | 37 | 472 | Identical |
57+
| black | black-26.10.1 | 366 | 35 | 392 | Identical |
58+
| isort | isort-9.0.2 | 110 | 70 | 144 | Identical |
59+
| pytest | pytest-9.2.0 | 253 | 35 | 1168 | Identical |
60+
| attrs | attrs-26.1.0 | 53 | 77 | 54 | Identical |
61+
| typer | typer-0.29.1 | 339 | 66 | 155 | Identical |
62+
| pyyaml | pyyaml-6.0.3 | 44 | 58 | 127 | Identical |
63+
| redis | redis-8.1.0 | 267 | 43 | 1143 | Identical |
64+
| scrapy | scrapy-2.20.0 | 538 | 45 | 417 | Identical |
65+
| beautifulsoup4 | beautifulsoup4-4.15.0 | 38 | 72 | 90 | Identical |
66+
| loguru | loguru-0.8.0 | 19 | 67 | 60 | Identical |
67+
| pandas | pandas-3.1.1 | 1448 | 20 | 3210 | Identical |
68+
| numpy | numpy-2.5.4 | 1046 | 22 | 2930 | Identical |
69+
| pillow | pillow-13.0.0 | 292 | 45 | 666 | Identical |
70+
| tornado | tornado-6.6.1 | 77 | 41 | 309 | Identical |
71+
| aiohttp | aiohttp-3.14.5 | 144 | 44 | 430 | Identical |
72+
73+
Machine-readable evidence is in [0.5.0.json](0.5.0.json).
74+
75+
## Version and publication
76+
77+
PyPI and remote Git tags were checked: the latest published version was 0.3.0;
78+
0.5.0 was unused. The minor version reflects the new opt-in capability on top of
79+
the unreleased 0.4.1 checkout. `pyproject.toml`, `uv.lock`, installed metadata,
80+
CLI JSON, and distribution names agree on 0.5.0.
81+
82+
The existing release workflow publishes to PyPI through trusted publishing when
83+
a GitHub release is published. Local validation does not establish a merged PR,
84+
passing hosted CI, a published GitHub release, or successful PyPI publication.

0 commit comments

Comments
 (0)