Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Changelog

## 0.5.0

- Add opt-in, path-scoped import boundaries to turn architectural constraints into
deterministic `imports/boundary` errors with project-specific remediation guidance.
- Support absolute and relative static imports, aliases, nested imports, and
type-checking blocks in conventional flat and `src/` layouts.
- Integrate boundaries with JSON, SARIF, CI failure thresholds, rule ignores,
per-file suppression, and the lint toggle.
- Reject malformed boundary configuration with a readable CLI error.
- Enforce separation between PyCodeGate's analysis rules, shared data types, and
presentation using the same boundary configuration available to users.

No import restrictions are enabled for projects without boundary configuration.
Dynamic imports, re-export tracing, and custom import roots are outside the scope
of this check. See the README for configuration and matching semantics.

This release also includes the precision, scoring, and output fixes already on
main after the published 0.3.0 release.
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,48 @@ files = ["tests/fixtures/**"]

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

## Import boundaries

Turn architectural review feedback into a deterministic check. Import boundaries
are opt-in: forbid a module (and its submodules) in selected files and provide
actionable guidance for the developer or agent.

In `pycodegate.toml`:

```toml
[[import-boundaries]]
files = ["src/app/domain/*.py"]
forbidden = ["app.infrastructure", "requests", "fastapi"]
message = "Keep the domain independent of infrastructure; use a domain port."

[[import-boundaries]]
files = ["src/app/*.py"]
forbidden = ["app.legacy_client"]
message = "Use app.clients instead of adding new legacy dependencies."
```

For `pyproject.toml`, use `[[tool.pycodegate.import-boundaries]]` with the same
fields. `files` uses case-sensitive project-relative POSIX path globs; `*` can
span directories. `forbidden` contains literal dotted module prefixes, so
`requests` matches `requests.sessions` but not `requests_extra`. Both arrays
must contain at least one nonempty string. The optional `message` supplies the
diagnostic's remediation guidance.

Checks cover static `import` and `from ... import ...` statements, including
aliases, nested functions, and type-checking blocks. Relative imports are resolved
using the path under the project root, stripping a leading `src/` for conventional
src layouts. Custom import roots, runtime imports via `importlib` or `__import__`,
and re-export tracing are not supported. Importing a name from a package is
treated as importing that dotted name, so avoid forbidden prefixes that collide
with allowed attributes on the same package.

Violations emit `imports/boundary` errors with the source location and your
message in terminal, JSON, and SARIF output. Use
`pycodegate . --fail-on error` to enforce the boundary in CI. Existing rule and
per-file ignores apply; `--no-lint` disables boundary checks. Without configured
boundaries, scan behavior is unchanged. Static checks supplement tests and
runtime verification; a high score alone does not prove behavior is correct.

## Profiles

PyCodeGate auto-detects a project profile and adjusts rule weights accordingly. You can also set a profile explicitly in config (`profile = "library"`).
Expand Down
6 changes: 6 additions & 0 deletions benchmarks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,9 @@ removed. Genuine issues (a 100-branch function, `verify=False`) should remain.

The precision fixes derived from this benchmark are locked in by
`tests/test_precision.py` and the per-rule unit tests under `tests/rules/`.

## Release validation

[0.5.0 validation](results/0.5.0.md) records the Python test matrix, packaging
checks, configured boundary checks, and an exact baseline comparison across the
29-package corpus. Machine-readable results are saved alongside the report.
227 changes: 227 additions & 0 deletions benchmarks/results/0.5.0.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
{
"release": "0.5.0",
"date": "2026-11-15",
"baseline_commit": "2a294b180daefe0511e253905b685de68d761175",
"candidate_code_commit": "8960979",
"packages": {
"requests": {
"files": 35,
"score": 68,
"findings": 169,
"matches_baseline": true,
"source_distribution": "requests-2.34.2"
},
"flask": {
"files": 65,
"score": 74,
"findings": 61,
"matches_baseline": true,
"source_distribution": "flask-3.1.3"
},
"click": {
"files": 76,
"score": 72,
"findings": 102,
"matches_baseline": true,
"source_distribution": "click-8.5.1"
},
"rich": {
"files": 100,
"score": 58,
"findings": 273,
"matches_baseline": true,
"source_distribution": "rich-15.0.0"
},
"httpx": {
"files": 60,
"score": 74,
"findings": 110,
"matches_baseline": true,
"source_distribution": "httpx-0.28.1"
},
"sqlalchemy": {
"files": 603,
"score": 22,
"findings": 2256,
"matches_baseline": true,
"source_distribution": "sqlalchemy-2.1.8"
},
"fastapi": {
"files": 738,
"score": 53,
"findings": 2383,
"matches_baseline": true,
"source_distribution": "fastapi-0.163.1"
},
"starlette": {
"files": 84,
"score": 71,
"findings": 162,
"matches_baseline": true,
"source_distribution": "starlette-1.10.0"
},
"pydantic": {
"files": 324,
"score": 35,
"findings": 720,
"matches_baseline": true,
"source_distribution": "pydantic-2.14.3"
},
"jinja2": {
"files": 49,
"score": 64,
"findings": 104,
"matches_baseline": true,
"source_distribution": "jinja2-3.1.6"
},
"werkzeug": {
"files": 84,
"score": 59,
"findings": 156,
"matches_baseline": true,
"source_distribution": "werkzeug-3.1.9"
},
"urllib3": {
"files": 80,
"score": 71,
"findings": 144,
"matches_baseline": true,
"source_distribution": "urllib3-2.8.0"
},
"django": {
"files": 2592,
"score": 33,
"findings": 969,
"matches_baseline": true,
"source_distribution": "django-6.1.3"
},
"celery": {
"files": 406,
"score": 37,
"findings": 472,
"matches_baseline": true,
"source_distribution": "celery-5.7.0"
},
"black": {
"files": 366,
"score": 35,
"findings": 392,
"matches_baseline": true,
"source_distribution": "black-26.10.1"
},
"isort": {
"files": 110,
"score": 70,
"findings": 144,
"matches_baseline": true,
"source_distribution": "isort-9.0.2"
},
"pytest": {
"files": 253,
"score": 35,
"findings": 1168,
"matches_baseline": true,
"source_distribution": "pytest-9.2.0"
},
"attrs": {
"files": 53,
"score": 77,
"findings": 54,
"matches_baseline": true,
"source_distribution": "attrs-26.1.0"
},
"typer": {
"files": 339,
"score": 66,
"findings": 155,
"matches_baseline": true,
"source_distribution": "typer-0.29.1"
},
"pyyaml": {
"files": 44,
"score": 58,
"findings": 127,
"matches_baseline": true,
"source_distribution": "pyyaml-6.0.3"
},
"redis": {
"files": 267,
"score": 43,
"findings": 1143,
"matches_baseline": true,
"source_distribution": "redis-8.1.0"
},
"scrapy": {
"files": 538,
"score": 45,
"findings": 417,
"matches_baseline": true,
"source_distribution": "scrapy-2.20.0"
},
"beautifulsoup4": {
"files": 38,
"score": 72,
"findings": 90,
"matches_baseline": true,
"source_distribution": "beautifulsoup4-4.15.0"
},
"loguru": {
"files": 19,
"score": 67,
"findings": 60,
"matches_baseline": true,
"source_distribution": "loguru-0.8.0"
},
"pandas": {
"files": 1448,
"score": 20,
"findings": 3210,
"matches_baseline": true,
"source_distribution": "pandas-3.1.1"
},
"numpy": {
"files": 1046,
"score": 22,
"findings": 2930,
"matches_baseline": true,
"source_distribution": "numpy-2.5.4"
},
"pillow": {
"files": 292,
"score": 45,
"findings": 666,
"matches_baseline": true,
"source_distribution": "pillow-13.0.0"
},
"tornado": {
"files": 77,
"score": 41,
"findings": 309,
"matches_baseline": true,
"source_distribution": "tornado-6.6.1"
},
"aiohttp": {
"files": 144,
"score": 44,
"findings": 430,
"matches_baseline": true,
"source_distribution": "aiohttp-3.14.5"
}
},
"files": 10330,
"diagnostic_regressions": 0,
"configured_boundary_checks": {
"requests": {
"forbidden_dependency": "urllib3",
"expected_violations": 28
},
"flask": {
"forbidden_dependency": "werkzeug",
"expected_violations": 79
},
"fastapi": {
"forbidden_dependency": "starlette",
"expected_violations": 115
}
}
}
84 changes: 84 additions & 0 deletions benchmarks/results/0.5.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# 0.5.0 release validation

Validated on 2026-11-15. Baseline: `2a294b180daefe0511e253905b685de68d761175`
(main, version 0.4.1). Candidate code: `8960979`, version 0.5.0.
Later documentation-only commits do not change the tested implementation.

## Tests and packaging

- 287 tests passed on each CI target: Python 3.10.22, 3.11.18, 3.12.14, and 3.13.5.
- Ruff lint and format checks passed.
- Coverage: 91% overall, 100% for the import-boundary rule.
- The installed wheel passed all 287 tests with current PyPI dependencies.
- Wheel and source distribution passed Twine validation and isolated functional
checks for version metadata, opt-in behavior, remediation guidance, and the
CLI failure gate. The wheel was built from the source distribution by `uv build`.
- Configured policy checks found 28 expected urllib3 imports in Requests, 79
Werkzeug imports in Flask, and 115 Starlette imports in FastAPI. A nonexistent
forbidden module produced no boundary diagnostics in those projects.
- JSON and SARIF, both configuration formats, relative imports, src layouts,
type-checking blocks, nested imports, negative fixtures, suppression, invalid
configuration, and disabling lint are covered by automated tests.

## Public-source corpus comparison

All 29 default packages from `uv run --frozen python benchmarks/run_corpus.py`
were scanned, totaling **10,330 Python files**. Sources are cached PyPI
source distributions, not arbitrary working copies. These checks exercise
PyCodeGate against those projects; they do not run the projects' own test suites.

Each source tree was scanned separately with baseline and candidate code using
`--json --no-dead-code`. Scores, discovered project metadata, and all diagnostic
fields were compared after sorting diagnostics. Only version and elapsed time
were excluded. **Every comparison was identical.** No new default restrictions
are introduced for projects without import-boundary configuration.

The corpus emits 19,376 existing diagnostics with a mean score of 52.8. These
findings were not individually adjudicated as true or false positives. Identical
output demonstrates lack of regression for this release, not that those projects
are broken or that existing rule precision has been fully established.

| Package | Source distribution | Files | Score | Findings | Baseline comparison |
| --- | --- | ---: | ---: | ---: | --- |
| requests | requests-2.34.2 | 35 | 68 | 169 | Identical |
| flask | flask-3.1.3 | 65 | 74 | 61 | Identical |
| click | click-8.5.1 | 76 | 72 | 102 | Identical |
| rich | rich-15.0.0 | 100 | 58 | 273 | Identical |
| httpx | httpx-0.28.1 | 60 | 74 | 110 | Identical |
| sqlalchemy | sqlalchemy-2.1.8 | 603 | 22 | 2256 | Identical |
| fastapi | fastapi-0.163.1 | 738 | 53 | 2383 | Identical |
| starlette | starlette-1.10.0 | 84 | 71 | 162 | Identical |
| pydantic | pydantic-2.14.3 | 324 | 35 | 720 | Identical |
| jinja2 | jinja2-3.1.6 | 49 | 64 | 104 | Identical |
| werkzeug | werkzeug-3.1.9 | 84 | 59 | 156 | Identical |
| urllib3 | urllib3-2.8.0 | 80 | 71 | 144 | Identical |
| django | django-6.1.3 | 2592 | 33 | 969 | Identical |
| celery | celery-5.7.0 | 406 | 37 | 472 | Identical |
| black | black-26.10.1 | 366 | 35 | 392 | Identical |
| isort | isort-9.0.2 | 110 | 70 | 144 | Identical |
| pytest | pytest-9.2.0 | 253 | 35 | 1168 | Identical |
| attrs | attrs-26.1.0 | 53 | 77 | 54 | Identical |
| typer | typer-0.29.1 | 339 | 66 | 155 | Identical |
| pyyaml | pyyaml-6.0.3 | 44 | 58 | 127 | Identical |
| redis | redis-8.1.0 | 267 | 43 | 1143 | Identical |
| scrapy | scrapy-2.20.0 | 538 | 45 | 417 | Identical |
| beautifulsoup4 | beautifulsoup4-4.15.0 | 38 | 72 | 90 | Identical |
| loguru | loguru-0.8.0 | 19 | 67 | 60 | Identical |
| pandas | pandas-3.1.1 | 1448 | 20 | 3210 | Identical |
| numpy | numpy-2.5.4 | 1046 | 22 | 2930 | Identical |
| pillow | pillow-13.0.0 | 292 | 45 | 666 | Identical |
| tornado | tornado-6.6.1 | 77 | 41 | 309 | Identical |
| aiohttp | aiohttp-3.14.5 | 144 | 44 | 430 | Identical |

Machine-readable evidence is in [0.5.0.json](0.5.0.json).

## Version and publication

PyPI and remote Git tags were checked: the latest published version was 0.3.0;
0.5.0 was unused. The minor version reflects the new opt-in capability on top of
the unreleased 0.4.1 checkout. `pyproject.toml`, `uv.lock`, installed metadata,
CLI JSON, and distribution names agree on 0.5.0.

The existing release workflow publishes to PyPI through trusted publishing when
a GitHub release is published. Local validation does not establish a merged PR,
passing hosted CI, a published GitHub release, or successful PyPI publication.
Loading
Loading