The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
ci: limit python cyclomatic complexity to pre-commit hook
Maciej Lisiewski038dd659b7eb
diff --git a/lefthook.yml b/lefthook.ymlindex dadec49efeb..889eaa947b0 100644--- a/lefthook.yml+++ b/lefthook.yml@@ -2,4 +2,4 @@ pre-commit:jobs:- name: lint pythonglob: "*.py" # glob filter- run: ruff check {staged_files}+ run: ruff check --config ./ruff.pre-commit.toml {staged_files}diff --git a/ruff.pre-commit.toml b/ruff.pre-commit.tomlnew file mode 100644index 00000000000..2cfdf4be5cc--- /dev/null+++ b/ruff.pre-commit.toml@@ -0,0 +1,474 @@+# Same as Black.+line-length = 88+indent-width = 4++# The oldest Python we support (requires-python): quote-stripping (UP037) and every other+# version-gated fix must stay valid where annotations are evaluated eagerly (< 3.14).+target-version = "py311"++[format]+# Like Black, use double quotes for strings.+quote-style = "double"++# Like Black, indent with spaces, rather than tabs.+indent-style = "space"++# Like Black, respect magic trailing commas.+skip-magic-trailing-comma = false++# Like Black, automatically detect the appropriate line ending.+line-ending = "auto"++[lint]+exclude = [+ ".bzr",+ ".git",+ ".pyenv",+ ".pytest_cache",+ ".pytype",+ ".ruff_cache",+ ".venv",+ ".vscode",+ "__pypackages__",+ ]++# Allow fix for all enabled rules (when `--fix`) is provided.+fixable = ["ALL"]+unfixable = []++# Allow unused variables when underscore-prefixed.+dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"++select = [+ "YTT101",+ "YTT102",+ "YTT103",+ "YTT201",+ "YTT202",+ "YTT203",+ "YTT204",+ "YTT301",+ "YTT302",+ "YTT303",+ "ASYNC100",+ "ASYNC105",+ "ASYNC115",+ "ASYNC116",+ "ASYNC210",+ "ASYNC220",+ "ASYNC221",+ "ASYNC222",+ "ASYNC230",+ "ASYNC251",+ # "S102",+ # "S110",+ # "S112",+ # "BLE001",+ "B002",+ "B003",+ "B004",+ "B005",+ "B006",+ # "B008",+ "B009",+ "B010",+ "B012",+ "B013",+ "B014",+ "B015",+ "B016",+ # "B017",+ # "B018",+ "B019",+ "B020",+ "B021",+ # "B022",+ # "B023",+ "B025",+ # "B026",+ "B029",+ # "B030",+ "B031",+ "B032",+ "B033",+ "B035",+ # "B039",+ "C400",+ # "C401",+ # "C402",+ "C403",+ "C404",+ "C405",+ # "C406",+ # "C408",+ # "C409",+ "C410",+ "C411",+ # "C413",+ "C414",+ "C415",+ # "C417",+ "C418",+ # "C419",+ "C901",+ # "DTZ001",+ "DTZ002",+ # "DTZ003",+ "DTZ004",+ # "DTZ005",+ # "DTZ006",+ # "DTZ007",+ # "DTZ011",+ "DTZ012",+ "DTZ901",+ "T100",+ # "EXE001",+ # "EXE002",+ "EXE004",+ "EXE005",+ "FA100",+ "FA102",+ "INT001",+ "INT002",+ "INT003",+ # "ISC004",+ # "LOG001",+ "LOG002",+ "LOG009",+ # "LOG014",+ # "LOG015",+ "G010",+ "G101",+ # "G201",+ "G202",+ "PIE790",+ "PIE794",+ "PIE796",+ "PIE800",+ "PIE804",+ "PIE807",+ "PIE808",+ # "PIE810",+ "PYI001",+ "PYI002",+ "PYI003",+ "PYI004",+ "PYI005",+ "PYI006",+ "PYI007",+ "PYI008",+ "PYI009",+ "PYI010",+ "PYI012",+ "PYI013",+ "PYI015",+ "PYI016",+ "PYI017",+ "PYI018",+ "PYI019",+ "PYI020",+ "PYI025",+ "PYI026",+ "PYI029",+ "PYI030",+ "PYI032",+ "PYI033",+ # "PYI034",+ "PYI035",+ "PYI036",+ "PYI041",+ "PYI042",+ "PYI043",+ "PYI044",+ "PYI045",+ "PYI046",+ "PYI047",+ "PYI048",+ "PYI049",+ "PYI050",+ "PYI052",+ "PYI055",+ "PYI057",+ "PYI058",+ "PYI059",+ "PYI061",+ "PYI062",+ "PYI063",+ "PYI064",+ "PYI066",+ "PT010",+ # "PT014",+ "PT020",+ "PT025",+ "PT026",+ "PT031",+ "RET501",+ "SIM101",+ # "SIM102",+ # "SIM103",+ "SIM107",+ # "SIM113",+ "SIM114",+ # "SIM115",+ # "SIM117",+ # "SIM118",+ # "SIM201",+ "SIM202",+ "SIM208",+ "SIM210",+ # "SIM211",+ "SIM220",+ "SIM221",+ "SIM222",+ "SIM223",+ # "SIM401",+ # "SIM905",+ "SIM911",+ "TC004",+ "TC005",+ "TC007",+ "TC010",+ "PTH124",+ "PTH210",+ # "FLY002",+ # "I001",+ # "N999",+ "PERF101",+ # "PERF102",+ "PERF402",+ "E722",+ "E902",+ "W605",+ "D419",+ # "F401",+ # "F402",+ "F404",+ "F407",+ "F501",+ "F502",+ "F503",+ "F504",+ "F505",+ "F506",+ "F507",+ "F508",+ "F509",+ "F521",+ "F522",+ "F523",+ "F524",+ "F525",+ "F541",+ # "F601",+ "F602",+ "F621",+ "F622",+ "F631",+ "F632",+ "F633",+ "F634",+ "F701",+ "F702",+ "F704",+ "F706",+ "F707",+ # "F811",+ # "F821",+ "F822",+ "F823",+ "F841",+ "F842",+ "F901",+ "PGH005",+ "PLC0105",+ "PLC0131",+ "PLC0132",+ "PLC0205",+ "PLC0206",+ "PLC0208",+ "PLC0414",+ "PLC3002",+ "PLE0100",+ "PLE0101",+ "PLE0115",+ "PLE0116",+ "PLE0117",+ "PLE0118",+ "PLE0303",+ "PLE0304",+ "PLE0305",+ "PLE0307",+ "PLE0308",+ "PLE0309",+ "PLE0604",+ # "PLE0605",+ "PLE0643",+ # "PLE0704",+ "PLE1132",+ "PLE1142",+ "PLE1205",+ "PLE1206",+ "PLE1300",+ "PLE1307",+ "PLE1310",+ "PLE1507",+ "PLE1519",+ "PLE1520",+ "PLE1700",+ # "PLE2502",+ "PLE2510",+ "PLE2512",+ "PLE2513",+ "PLE2514",+ "PLE2515",+ # "PLR0124",+ "PLR0133",+ "PLR0206",+ "PLR0402",+ # "PLR1704",+ "PLR1708",+ "PLR1711",+ "PLR1716",+ "PLR1722",+ "PLR1730",+ "PLR1733",+ "PLR1736",+ "PLR2044",+ "PLW0120",+ "PLW0127",+ "PLW0128",+ "PLW0129",+ "PLW0131",+ "PLW0133",+ "PLW0177",+ "PLW0211",+ "PLW0245",+ "PLW0406",+ # "PLW0602",+ "PLW0604",+ "PLW0642",+ "PLW0711",+ "PLW1501",+ "PLW1507",+ # "PLW1508",+ "PLW1509",+ "PLW1510",+ "PLW2101",+ "UP001",+ "UP003",+ "UP004",+ "UP005",+ "UP006",+ "UP007",+ "UP008",+ "UP009",+ "UP010",+ "UP011",+ "UP012",+ "UP014",+ "UP017",+ "UP018",+ "UP019",+ "UP020",+ "UP021",+ "UP022",+ "UP023",+ "UP024",+ "UP025",+ "UP026",+ "UP028",+ "UP029",+ "UP030",+ "UP031",+ "UP032",+ "UP033",+ "UP034",+ # "UP035",+ "UP036",+ "UP037",+ "UP039",+ "UP040",+ "UP041",+ "UP043",+ "UP044",+ #"UP045",+ # "UP046", # deferred: fix is PEP 695 class syntax (3.12+), project floor is py3.11+ # "UP047", # deferred: fix is PEP 695 generic-callable syntax (3.12+), project floor is py3.11+ "UP049",+ "UP050",+ "FURB105",+ "FURB122",+ "FURB129",+ "FURB132",+ "FURB136",+ "FURB157",+ "FURB161",+ "FURB162",+ "FURB163",+ "FURB166",+ "FURB167",+ "FURB168",+ "FURB169",+ "FURB177",+ "FURB181",+ "FURB188",+ "FURB192",+ "RUF007",+ "RUF008",+ "RUF009",+ "RUF010",+ # "RUF012",+ "RUF013",+ "RUF015",+ "RUF016",+ "RUF017",+ "RUF018",+ "RUF019",+ "RUF020",+ "RUF022",+ "RUF023",+ "RUF024",+ "RUF026",+ "RUF028",+ "RUF030",+ "RUF032",+ "RUF033",+ "RUF034",+ "RUF040",+ "RUF041",+ "RUF046",+ "RUF048",+ "RUF049",+ "RUF051",+ "RUF053",+ "RUF057",+ "RUF058",+ "RUF059",+ "RUF063",+ "RUF068",+ "RUF100",+ "RUF101",+ "RUF200",+ # "TRY002",+ # "TRY004",+ # "TRY201",+ # "TRY203",+ # "TRY401",+ "TID251"+]++[lint.flake8-tidy-imports.banned-api]+"pm.uv".msg = "Use PM's semantic Python operations, not an installer executable."+"pm.client.uv".msg = "Use PM's semantic Python operations."+"pm.install.uv".msg = "The raw uv bridge was removed; use PM operations."+"pm._uv".msg = "Tool acquisition is private to PM."+"pm.environment".msg = "The environment engine is private; use PM operations."+"pm.runtime_stage".msg = "PM stages its own worker runtime; consumers call pm operations."++[lint.per-file-ignores]+"apps/desktop/electron/fixtures/**" = ["TID251"]+"pm/**" = ["TID251"]+"tests/pm/**" = ["TID251"]++[lint.mccabe]+max-complexity = 20\ No newline at end of filediff --git a/ruff.toml b/ruff.tomlindex 2ccb9d89cba..7f11631727a 100644--- a/ruff.toml+++ b/ruff.toml@@ -454,7 +454,7 @@ select = [# "TRY201",# "TRY203",# "TRY401",- "TID251"+ "TID251",][lint.flake8-tidy-imports.banned-api]diff --git a/tests/ci/test_strict_ruff_target.py b/tests/ci/test_strict_ruff_target.pyindex 1e76c9ff002..c85f1995c46 100644--- a/tests/ci/test_strict_ruff_target.py+++ b/tests/ci/test_strict_ruff_target.py@@ -17,7 +17,7 @@ ROOT = Path(__file__).resolve().parents[2]def test_strict_ruff_target_is_the_supported_python_floor():floor = tomllib.loads((ROOT / "pyproject.toml").read_text(encoding="utf-8"))["project"]["requires-python"]major, minor = re.search(r">=\s*(\d+)\.(\d+)", floor).groups()- strict = tomllib.loads((ROOT / "ruff.strict.toml").read_text(encoding="utf-8"))+ strict = tomllib.loads((ROOT / "ruff.toml").read_text(encoding="utf-8"))assert strict["target-version"] == f"py{major}{minor}", (f"ruff.strict.toml target-version {strict['target-version']!r} is not the requires-python "f"floor {floor!r}: its autofixes would emit syntax the oldest supported Python cannot import")