Repository navigation
Description
Problem or Motivation
Decision 4 on #1876 (owner, 2026-10-22): a separate item covers the hand-written McCabe port mccabe_complexity in src/devops_cli/core/code_metrics.py. After #1876 the module measures complexity only (119 lines). Ruff's C901 already enforces the same count in ruff check at 10 (#586), and tests/test_code_metrics.py keeps the port equal to Ruff on 12 samples. Two product paths still read the port: devops scan complexity (security/complexity.py) and the inspection hotspots (ai/inspection.py).
Proposed Solution & Architectural Design
- Decide whether the two readers take the complexity figure from Ruff, or whether the port stays with a stated reason.
- Ruff is a dev dependency only (
pyproject.toml), andC901reports only the functions abovemax-complexity. A figure for every function needsruff check --select C901 --config 'lint.mccabe.max-complexity=0' --output-format json, run as a subprocess from product code, or Ruff as a runtime dependency. - Record the cost of each option (a runtime dependency, a subprocess per scan, or keeping about 90 lines and their 12-sample test) and the choice.
Target Subsystem
core/code_metrics.py, security/complexity.py, ai/inspection.py.
Existing Tool Considered
Ruff C901 (standard McCabe, the same count). The item decides whether devops-cli reads it at run time.
Acceptance criteria
- The two readers get their complexity from one source that matches
ruff check --select C901, and a test holds it. - If the port goes,
core/code_metrics.pyand its samples go with it.
Proposed design
Problem statement
The two product paths that report function complexity, devops scan complexity and the inspection hotspots, read a hand-written McCabe port in core/code_metrics.py. Ruff's C901 enforces the same count in CI. This item decides whether the two readers take the figure from Ruff at run time, or whether the port stays with a stated reason.
Acceptance criteria
Requirement: single-source complexity
The two readers SHALL get their complexity figure from one source that matches ruff check --select C901, and a test SHALL hold that match.
Scenario: port matches ruff
- WHEN the 12 parametrized samples in
tests/test_code_metrics.pyrun - THEN each measured value equals the value that
ruff check --select C901withmax-complexity = 0reports for the same function
Requirement: port removal is complete
If the port is removed, core/code_metrics.py and its test samples SHALL be removed with it.
Scenario: port removed
- WHEN the decision is to read from Ruff at run time
- THEN
src/devops_cli/core/code_metrics.pyandtests/test_code_metrics.pydo not exist
Existing Tool Considered
Ruff C901 computes the same standard McCabe count. It lacks a structured field for the complexity number in its JSON output. The number is in the diagnostic message string. Ruff is a dev dependency, not a runtime dependency. The port costs about 90 lines of Python and 12 test samples to build, keep and fix.
Key questions
- Should the two readers read complexity from Ruff at run time, or keep the hand-written port?: Keep the port. Ruff is a dev dependency, not a runtime dependency. Its JSON output has no structured field for the complexity number. The port is 90 lines of pure Python with no external dependencies, tested to match Ruff's C901 on 12 samples. (best practice) [sources: pyproject.toml, src/devops_cli/core/code_metrics.py, tests/test_code_metrics.py]
- Chosen: Keep the port. Ruff is a dev dependency. Its JSON output has no structured complexity field. The port is 90 lines of pure Python, no external dependencies, tested to match Ruff.
- Rejected: Ruff as subprocess. Ruff is not a runtime dependency. Its JSON output embeds the number in a message string. A subprocess per scan adds latency and a binary dependency.
- Rejected: Ruff as runtime dependency. Adding a Rust binary as a runtime dependency of a CLI tool is a supply-chain and size cost for a metric that 90 lines of pure Python already compute.
- What is the written cost of keeping the port?: About 90 lines of Python in
src/devops_cli/core/code_metrics.pyand 12 parametrized test samples intests/test_code_metrics.py. [sources: src/devops_cli/core/code_metrics.py, tests/test_code_metrics.py] - Is Ruff a runtime dependency of devops-cli?: No. Ruff is in the
[dependency-groups] devlist inpyproject.toml, not in[project] dependencies. [sources: pyproject.toml]
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Activity
dan-petty commentedon Oct 29, 2026
Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.
The candidate refactors how two product paths obtain their complexity figure, either replacing or retaining a hand-written port.It is a maintainability decision with no user-facing urgency or blocking impact.It removes or justifies a 90-line duplicate of Ruff C901 logic in product code.The decision is small, but switching to Ruff requires a subprocess call or a runtime dependency change.Both touch security/complexity.py and the complexity metric, but #773 unifies the nesting metric implementation while the candidate decides whether to replace the McCabe port with Ruff C901 as the runtime source.ci(lint): Ruff PLR1702 caps nesting at 4 blocks and replaces the hook (…
devops-cli-service commentedon Oct 30, 2026
Status set to Ready at 07fb4c2 (see proposed design in issue body).
devops-cli-service commentedon Nov 1, 2026
Staged: branch
refactor/2600-devops-scan-complexity-and-the-inspection, draft pull request #3070. The pull request plans the item and closes no issue.The task groups, with the tokens of the inputs of each step, for a budget of 40000 tokens:
docs(openspec): fix plan #2600 real test paths, no spec delta, honest…
docs(openspec): fix plan #2600 test holds Ruff figures, not Ruff
docs(openspec): plan #2600 record keep-port decision (#3070)
[-]refactor(ci): devops scan complexity and the inspection hotspots read Ruff's C901 count, or keep the McCabe port with a stated reason[/-][+]refactor(ci): record keep-port decision[/+]dan-petty commentedon Nov 6, 2026
The job shortened the title of this item. The summary had 119 characters, and the limit is 60. The type and the scope stay.
refactor(ci): devops scan complexity and the inspection hotspots read Ruff's C901 count, or keep the McCabe port with a stated reasonrefactor(ci): record keep-port decisiondevops-cli-service commentedon Nov 6, 2026
Released in v0.71.0: https://github.com/dan-petty/devops-cli/releases/tag/v0.71.0
devops-cli-service commentedon Nov 6, 2026
Live since 2026-11-06 19:47 UTC