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
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ codeint-config = { path = "crates/config" }
codeint-git = { path = "crates/git" }
codeint-lang-dart = { path = "plugins/languages/dart" }
codeint-lang-php = { path = "plugins/languages/php" }
codeint-lang-python = { path = "plugins/languages/python" }
codeint-lang-rust = { path = "plugins/languages/rust" }
codeint-lang-ts = { path = "plugins/languages/ts" }
codeint-metrics = { path = "crates/metrics" }
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Each pull request can pass tests and linters while quietly adding copied blocks,
Over dozens of changes, that structural drag compounds until both humans and agents slow down.

codeint measures **Software entropy** directly from the shape of source code so you see it grow before it compounds.
It ships with built-in Language plugins for TypeScript/JavaScript, Rust, PHP, and Dart, plus sandboxed WebAssembly Plugins for other languages and custom Metrics.
It ships with built-in Language plugins for TypeScript/JavaScript, Rust, PHP, Dart, and Python, plus sandboxed WebAssembly Plugins for other languages and custom Metrics.

## How it works

Expand Down Expand Up @@ -58,14 +58,15 @@ Read [docs/guide/philosophy-and-architecture.md](./docs/guide/philosophy-and-arc

## Calibrated Reference ranges

10th to 90th percentile across 20 pre-2023 open-source repositories per language ([ADR 0008](./docs/adr/0008-typescript-reference-ranges.md), [ADR 0010](./docs/adr/0010-rust-reference-ranges.md), [ADR 0011](./docs/adr/0011-php-reference-ranges.md), [ADR 0012](./docs/adr/0012-dart-reference-ranges.md)):
10th to 90th percentile across 20 pre-2023 open-source repositories per language ([ADR 0008](./docs/adr/0008-typescript-reference-ranges.md), [ADR 0010](./docs/adr/0010-rust-reference-ranges.md), [ADR 0011](./docs/adr/0011-php-reference-ranges.md), [ADR 0012](./docs/adr/0012-dart-reference-ranges.md), [ADR 0013](./docs/adr/0013-python-reference-ranges.md)):

| Language | Erosion | Duplication | Verbosity | Import cycles |
| -------- | ------- | ----------- | --------- | ------------- |
| TypeScript / JavaScript | 35.2% to 60.0% | 1.7% to 34.6% | 1.8% to 34.7% | 0.0% to 30.8% |
| Rust | 38.0% to 64.2% | 5.0% to 32.5% | 6.0% to 32.9% | 2.1% to 50.6% |
| PHP | 5.5% to 67.7% | 4.1% to 29.0% | 4.2% to 29.2% | 0.0% to 10.7% |
| Dart | 4.7% to 41.9% | 7.3% to 25.6% | 8.0% to 25.9% | 7.3% to 52.4% |
| Python | 14.4% to 62.4% | 1.2% to 20.1% | 1.4% to 20.4% | 0.0% to 32.1% |

See [docs/guide/languages.md](./docs/guide/languages.md) for per-language rules and sample repository timings.

Expand Down
1 change: 1 addition & 0 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ codeint-config = { workspace = true }
codeint-git = { workspace = true }
codeint-lang-dart = { workspace = true }
codeint-lang-php = { workspace = true }
codeint-lang-python = { workspace = true }
codeint-lang-rust = { workspace = true }
codeint-lang-ts = { workspace = true }
codeint-model = { workspace = true }
Expand Down
7 changes: 6 additions & 1 deletion crates/cli/src/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use codeint_config::{
use codeint_git::{GitError, Repository, Snapshot};
use codeint_lang_dart::Dart;
use codeint_lang_php::Php;
use codeint_lang_python::Python;
use codeint_lang_rust::Rust;
use codeint_lang_ts::TypeScriptAndJavaScript;
use codeint_model::{
Expand Down Expand Up @@ -72,7 +73,7 @@ pub(crate) struct NamedLanguagePlugin<'plugin> {
pub(crate) plugin: &'plugin dyn LanguagePlugin,
}

pub(crate) const BUILT_IN_LANGUAGE_PLUGINS: [NamedLanguagePlugin<'static>; 4] = [
pub(crate) const BUILT_IN_LANGUAGE_PLUGINS: [NamedLanguagePlugin<'static>; 5] = [
NamedLanguagePlugin {
name: "typescript-javascript",
plugin: &TypeScriptAndJavaScript,
Expand All @@ -89,6 +90,10 @@ pub(crate) const BUILT_IN_LANGUAGE_PLUGINS: [NamedLanguagePlugin<'static>; 4] =
name: "dart",
plugin: &Dart,
},
NamedLanguagePlugin {
name: "python",
plugin: &Python,
},
];

pub(crate) struct LoadedPlugins {
Expand Down
8 changes: 4 additions & 4 deletions crates/cli/tests/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ fn every_typescript_and_javascript_extension_is_measured_and_other_files_are_not
}
repository.write("README.md", "# Fixture\n");
repository.write("src/data.json", "{\"one\": 1}\n");
repository.write("scripts/tool.py", "print('codeint')\n");
repository.write("scripts/tool.cob", "DISPLAY 'codeint'.\n");
repository.commit_all();

let output = repository.codeint(&["check"]);
Expand Down Expand Up @@ -2872,10 +2872,10 @@ fn a_languages_entry_that_names_an_unknown_language_plugin_names_it_and_exits_2(
assert_codeint_json_is_rejected(
r#"{ "languages": [
{ "plugin": "typescript-javascript", "include": ["web"] },
{ "plugin": "python", "include": ["scripts"] }
{ "plugin": "cobol", "include": ["scripts"] }
] }"#,
"codeint.json names an unknown Language plugin python at languages[1].plugin; \
the Language plugins are typescript-javascript, rust, php, dart",
"codeint.json names an unknown Language plugin cobol at languages[1].plugin; \
the Language plugins are typescript-javascript, rust, php, dart, python",
"Name one of the Language plugins listed, or remove the entry from languages.",
);
}
Expand Down
1 change: 1 addition & 0 deletions crates/plugin-host/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ wasmtime = { workspace = true }
[dev-dependencies]
codeint-lang-dart = { workspace = true }
codeint-lang-php = { workspace = true }
codeint-lang-python = { workspace = true }
codeint-lang-rust = { workspace = true }
codeint-lang-ts = { workspace = true }

Expand Down
43 changes: 43 additions & 0 deletions crates/plugin-host/tests/conformance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::path::Path;
use codeint_config::PluginHostConfig;
use codeint_lang_dart::Dart;
use codeint_lang_php::Php;
use codeint_lang_python::Python;
use codeint_lang_rust::Rust;
use codeint_lang_ts::TypeScriptAndJavaScript;
use codeint_model::language::{ImportRequest, Resolution};
Expand Down Expand Up @@ -512,3 +513,45 @@ fn built_in_dart_plugin_passes_seam_2_conformance() {
},
);
}

#[test]
fn built_in_python_plugin_passes_seam_2_conformance() {
let prod = "from app.helper import value\n\n# comment\ndef run(flag):\n if flag:\n return value()\n else:\n return 0\n";
let prod_crlf = prod.replace('\n', "\r\n");
let fixture = ConformanceFixture {
expected_resolved_target: "packages/app/src/app/helper.py",
import_requests: &[
("packages/app/src/app/main.py", "app.helper"),
("packages/app/src/app/main.py", "os"),
("packages/app/src/app/main.py", ".missing"),
],
invalid_manifest_text: "[tool.uv.workspace\n",
expected_workspace_package: "packages/app",
valid_manifests: &[
(
"pyproject.toml",
"[tool.uv.workspace]\nmembers = [\"packages/*\"]\n",
),
("packages/app/pyproject.toml", "[project]\nname = \"app\"\n"),
],
expected_manifest_path: "pyproject.toml",
repository_paths: &[
"pyproject.toml",
"packages/app/pyproject.toml",
"packages/app/src/app/main.py",
"packages/app/src/app/helper.py",
],
unsupported_path: "scripts/tool.unknown",
unparsable_source: "def broken():\n s = 'unclosed\n",
unparsable_path: "packages/app/src/app/broken.py",
declaration_only: None,
empty_path: "packages/app/src/app/empty.py",
test_source: "def check():\n return 1\n",
test_path: "packages/app/tests/test_main.py",
production_source_crlf: &prod_crlf,
production_source: prod,
production_path: "packages/app/src/app/main.py",
name: "python",
};
assert_seam_2_conformance(&Python, &fixture);
}
118 changes: 118 additions & 0 deletions docs/adr/0013-python-reference-ranges.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
---
status: accepted
---

# Python Reference ranges come from a panel of 20 public repositories

The Owner approved running the calibrated Python panel on 2026-11-22 using the pre-2023 human-written selection rule established in [ADR 0008](./0008-typescript-reference-ranges.md).

## Context

A Reference range must describe human-written code, or it cannot show how far agent-written code drifts from it.
This record applies the same selection rule and measurement method as ADR 0008 to 20 public Python repositories.

### Selection rule and run

- Query on 2026-11-22: `language:Python created:<2022-01-01 fork:false archived:false`, sorted by stars descending.
- Take the first 20 repositories passing the ADR 0008 exclusions (no forks/archived/lists/tutorials/books/collections, >= 5,000 Production source lines, Generated + Vendored <= Production, and `codeint check` exits 0).
- Pin each repository at the last commit on its default branch dated before `2023-01-01`.
- Measured with `codeint 0.4.0` release build (default clone size 75 tokens, filter 14 distinct normalized tokens) on Apple Silicon.
- Run time across the 20 repositories: 0.010s to 0.851s per repository (4.40s total, 0 unparsable Python files).

### Exclusions

- `public-apis/public-apis`: topic/description (list of).
- `EbookFoundation/free-programming-books`: topic/description (book).
- `donnemartin/system-design-primer`: topic/description (interview).
- `vinta/awesome-python`: topic/description (awesome).
- `practical-tutorials/project-based-learning`: topic/description (list of).
- `TheAlgorithms/Python`: topic/description (interview).
- `521xueweihan/HelloGitHub`: topic/description (awesome).
- `sherlock-project/sherlock`: 1140 Production lines (< 5,000).
- `bregman-arie/devops-exercises`: topic/description (interview).
- `fighting41love/funNLP`: topic/description (awesome).
- `swisskyrepo/PayloadsAllTheThings`: topic/description (list of).
- `d2l-ai/d2l-zh`: topic/description (book).
- `Z4nzu/hackingtool`: 1967 Production lines (< 5,000).
- `Asabeneh/30-Days-Of-Python`: topic/description (100 days).
- `josephmisiti/awesome-machine-learning`: topic/description (awesome).
- `labmlai/annotated_deep_learning_paper_implementations`: topic/description (tutorial).

### Panel

| Repository | Stars band | Pinned commit | Production lines |
| ---------- | ---------- | ------------- | ---------------- |
| `yt-dlp/yt-dlp` | over 100k | `2fb0f858686c46abc50a0e253245afe750746775` | 173,655 |
| `huggingface/transformers` | over 100k | `375801d5e65457d2ef86e6b269703c5f9ad67252` | 580,324 |
| `ytdl-org/youtube-dl` | over 100k | `195f22f679330549882a8234e7234942893a4902` | 131,379 |
| `pytorch/pytorch` | over 100k | `39d49dbe4546c9f4d153ec748f62371e4546158a` | 471,422 |
| `fastapi/fastapi` | over 100k | `efc12c5cdbede6922a033a5234c70cb22c4d204a` | 12,611 |
| `nvbn/thefuck` | 50k to 100k | `ceeaeab94b5df5a4fe9d94d61e4f6b0bbea96378` | 5,049 |
| `3b1b/manim` | 50k to 100k | `a31c4ae3c23f060a34f3a4f5062c1d67fc4c268a` | 17,579 |
| `PaddlePaddle/PaddleOCR` | 50k to 100k | `4f735dbde167684cce5dcd14c035e9f67b4d187d` | 66,093 |
| `home-assistant/core` | 50k to 100k | `6d4489e82207916a811e936be00246c5cbc10545` | 671,942 |
| `django/django` | 50k to 100k | `c179ad9fe7e82dcb80261aa016f2fe18c8fcc181` | 116,838 |
| `python/cpython` | 50k to 100k | `baf234971f20e5e6c7438f46889e9c8f172cc25e` | 291,724 |
| `tensorflow/models` | 50k to 100k | `755617b99ca8b647367d806cad30d463693da02b` | 319,102 |
| `openbq-org/OpenBB` | 50k to 100k | `21247ac302dfa98e187ec70b832b76eb46e9c9e8` | 148,307 |
| `apache/superset` | 50k to 100k | `734d423ca094746ee1c2f2c1e72138ed9e69cdee` | 83,725 |
| `pallets/flask` | 50k to 100k | `74e5263c88e51bb442879ab863a5d03292fc0a33` | 7,935 |
| `ansible/ansible` | 50k to 100k | `45df14a2e05573e6213ce789aa3278f4f30fa54f` | 93,017 |
| `scikit-learn/scikit-learn` | 50k to 100k | `96a0bc861ad2ba3c63db0326b42b41ddabeb2aff` | 189,155 |
| `scrapy/scrapy` | 50k to 100k | `deaf1fb6cf513db8119acfe70fd3e08f761f7ede` | 16,683 |
| `keras-team/keras` | 50k to 100k | `ed99e34f279a2d2d6a44af87ee64f8fc98c7e8b9` | 131,710 |
| `commaai/openpilot` | 50k to 100k | `6c8aca245ae78433a4f8e4acf3b1e5270fcb8768` | 34,524 |

## Measurements

### Per Metric, over the 20 repositories

| Metric | Mean | Median | Standard deviation | 10th percentile | 90th percentile | Lowest | Highest |
| ------ | ---- | ------ | ------------------ | --------------- | --------------- | ------ | ------- |
| Erosion | 0.396 | 0.406 | 0.182 | 0.144 | 0.624 | 0.012 | 0.681 |
| Verbosity | 0.084 | 0.043 | 0.094 | 0.014 | 0.204 | 0.007 | 0.406 |
| Duplication | 0.078 | 0.035 | 0.095 | 0.012 | 0.201 | 0.002 | 0.403 |
| Import cycles | 0.106 | 0.032 | 0.130 | 0.000 | 0.321 | 0.000 | 0.456 |

### Per repository, in the Production Source set

| Repository | Erosion | Verbosity | Duplication | Import cycles |
| ---------- | ------- | --------- | ----------- | ------------- |
| `yt-dlp/yt-dlp` | 0.590 | 0.031 | 0.028 | 0.006 |
| `huggingface/transformers` | 0.621 | 0.406 | 0.403 | 0.011 |
| `ytdl-org/youtube-dl` | 0.649 | 0.034 | 0.031 | 0.011 |
| `pytorch/pytorch` | 0.395 | 0.059 | 0.048 | 0.332 |
| `fastapi/fastapi` | 0.382 | 0.207 | 0.201 | 0.021 |
| `nvbn/thefuck` | 0.012 | 0.038 | 0.015 | 0.047 |
| `3b1b/manim` | 0.151 | 0.007 | 0.002 | 0.108 |
| `PaddlePaddle/PaddleOCR` | 0.359 | 0.140 | 0.134 | 0.016 |
| `home-assistant/core` | 0.234 | 0.083 | 0.082 | 0.026 |
| `django/django` | 0.423 | 0.029 | 0.018 | 0.186 |
| `python/cpython` | 0.450 | 0.048 | 0.040 | 0.031 |
| `tensorflow/models` | 0.315 | 0.120 | 0.116 | 0.034 |
| `openbq-org/OpenBB` | 0.317 | 0.204 | 0.204 | 0.000 |
| `apache/superset` | 0.417 | 0.085 | 0.084 | 0.320 |
| `pallets/flask` | 0.251 | 0.023 | 0.020 | 0.188 |
| `ansible/ansible` | 0.681 | 0.031 | 0.023 | 0.000 |
| `scikit-learn/scikit-learn` | 0.502 | 0.025 | 0.019 | 0.199 |
| `scrapy/scrapy` | 0.089 | 0.009 | 0.008 | 0.136 |
| `keras-team/keras` | 0.478 | 0.086 | 0.076 | 0.456 |
| `commaai/openpilot` | 0.597 | 0.015 | 0.012 | 0.000 |

## Decision

**The Python Language plugin shows, for each Metric, the 10th to 90th percentile of this panel as its Reference range.**
The source label reads `codeint panel of 20 Python repositories, ADR 0013, codeint 0.4.0`.

| Metric | Reference range |
| ------ | --------------- |
| Erosion | 0.144 to 0.624 |
| Verbosity | 0.014 to 0.204 |
| Duplication | 0.012 to 0.201 |
| Import cycles | 0.000 to 0.321 |

## Consequences

- Python reports show a Reference range next to each Metric with the source label above.
- No code, fixture, or text of a panel repository enters codeint; this record holds only names, commits, and numbers.
- Any future change to default Metric rules or Source set rules requires re-measuring the panel and amending this record.
2 changes: 1 addition & 1 deletion docs/guide/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Each page below focuses on one topic and links to [docs/reference.md](../referen
1. [Philosophy and Architecture](./philosophy-and-architecture.md): why codeint measures Software entropy, how the four Metrics work, and how the codebase is structured.
2. [Getting Started](./getting-started.md): install codeint, initialize `codeint.json`, and run your first `check`, `diff`, and `trend`.
3. [Configuration (`codeint.json`)](./configuration.md): set Budgets, Regression limits, Source-set globs, and multi-language folders.
4. [Built-in Languages](./languages.md): how TypeScript/JavaScript, Rust, PHP, and Dart are measured, plus their calibrated Reference ranges.
4. [Built-in Languages](./languages.md): how TypeScript/JavaScript, Rust, PHP, Dart, and Python are measured, plus their calibrated Reference ranges.
5. [CI and GitHub Actions](./ci-and-github-actions.md): gate pull requests with `codeint diff` and upload SARIF findings to GitHub code scanning.
6. [Programmatic API](../programmatic.md): call codeint from JavaScript, TypeScript, or Rust.
7. [Plugins](../plugins.md): build, hash, declare, and test external WebAssembly Language and Metric plugins.
Expand Down
3 changes: 2 additions & 1 deletion docs/guide/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ When you upgrade via `codeint update`, codeint updates that `$schema` tag automa
{ "plugin": "typescript-javascript", "include": ["web"], "exclude": ["web/dist"] },
{ "plugin": "rust", "include": ["crates"], "exclude": [] },
{ "plugin": "php", "include": ["app", "src"], "exclude": [] },
{ "plugin": "dart", "include": ["lib"], "exclude": [] }
{ "plugin": "dart", "include": ["lib"], "exclude": [] },
{ "plugin": "python", "include": ["services"], "exclude": [] }
]
}
```
Expand Down
6 changes: 5 additions & 1 deletion docs/guide/languages.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Built-in Languages

codeint ships four built-in Language plugins in pure, safe Rust (`#![forbid(unsafe_code)]`).
codeint ships five built-in Language plugins in pure, safe Rust (`#![forbid(unsafe_code)]`).
Each plugin parses the modern superset of its language family with no language-version pin needed in `codeint.json`.

## Summary
Expand All @@ -11,6 +11,7 @@ Each plugin parses the modern superset of its language family with no language-v
| `rust` | `.rs` | `Cargo.toml` | `tests/`, `benches/`, `examples/`, `tests.rs`, `*_test.rs`, `*_tests.rs`; inline `#[cfg(test)]` excluded from Production |
| `php` | `.php` | `composer.json` (`repositories` of type `path`) | `tests/`, `test/`, `*Test.php`, `*.test.php` |
| `dart` | `.dart` | `pubspec.yaml` (`workspace`) | `test/`, `tests/`, `integration_test/`, `*_test.dart`; `*.g.dart`, `*.freezed.dart`, `*.gr.dart`, `*.mocks.dart`, `*.pb*.dart` -> Generated |
| `python` | `.py` | `pyproject.toml` (`[tool.uv.workspace].members`) | `test/`, `tests/`, `test_*.py`, `*_test.py`, `conftest.py`; `*_pb2.py`, `*_pb2_grpc.py` -> Generated; `if TYPE_CHECKING:` imports excluded from Import cycles |

Core rules also classify files under `vendor/` or `third_party/` as `vendored` and files with generated-file header comments (`@generated`, `GENERATED CODE`, `DO NOT EDIT`) as `generated`.

Expand All @@ -24,6 +25,7 @@ Measured across 20 pre-2023 public repositories per language (10th to 90th perce
| Rust | 38.0% to 64.2% | 5.0% to 32.5% | 6.0% to 32.9% | 2.1% to 50.6% | [ADR 0010](../adr/0010-rust-reference-ranges.md) |
| PHP | 5.5% to 67.7% | 4.1% to 29.0% | 4.2% to 29.2% | 0.0% to 10.7% | [ADR 0011](../adr/0011-php-reference-ranges.md) |
| Dart | 4.7% to 41.9% | 7.3% to 25.6% | 8.0% to 25.9% | 7.3% to 52.4% | [ADR 0012](../adr/0012-dart-reference-ranges.md) |
| Python | 14.4% to 62.4% | 1.2% to 20.1% | 1.4% to 20.4% | 0.0% to 32.1% | [ADR 0013](../adr/0013-python-reference-ranges.md) |

To add another language as an external WebAssembly plugin, see [docs/plugins.md](../plugins.md).

Expand All @@ -41,3 +43,5 @@ Sample Production measurements from `codeint check` (release build, Apple Silico
| PHP | `laravel/framework` | 3,208 | 132,791 | 16.9% | 8.1% | 8.2% | 4.4% | 0.47s |
| Dart | `dart-lang/pub` | 547 | 26,170 | 44.4% | 0.5% | 1.7% | 78.6% | 0.88s |
| Dart | `flutter/packages` | 4,137 | 434,407 | 45.9% | 23.1% | 23.3% | 18.5% | 3.68s |
| Python | `django/django` | 865 | 116,838 | 42.3% | 1.8% | 2.9% | 18.6% | 0.33s |
| Python | `home-assistant/core` | 5,592 | 671,942 | 23.4% | 8.2% | 8.3% | 2.6% | 0.73s |
Loading