Skip to content

refactor(config): the config barrel and the unused config names go, and the package inits stop re-exporting #776

Description

@dan-petty

Refreshed plan (2026-10-17, unblocking review)

This section supersedes any text below that conflicts with it.

Decisions

Scope

  • Delete the barrel, point its 9 source and 6 test importers at the defining modules, and remove test_config_package_exports_resolve.
  • Delete the unused names and move the test-only names into tests, as the body says. The PR recounts at its base and lists what it deletes and moves.
  • Delete the re-exports in devops_cli/__init__.py and devops_cli/core/__init__.py, so python -m devops_cli.core.code_metrics loads only the stdlib and its own package. Point tests/test_metadata.py at devops_cli.config.metadata.
  • Update the known-limit bullet in refactor(ci): one nesting metric module shared by the pre-commit hook and the scanner #773's task file to name this issue, and the structural-invariants hook comment that says the package inits still load devops_cli.config and typer.

Delivery

  1. One PR, size M, closing refactor(config): the config barrel and the unused config names go, and the package inits stop re-exporting #776.

Acceptance criteria (in addition to the body's four, which stay; the counts in its second criterion are refreshed under Current references)

  • src/devops_cli/config/__init__.py holds only a docstring, and a test fails if it gains an import, an assignment or a function.
  • src/devops_cli/core/__init__.py holds only a docstring. _CORE_EXPORTS, its __getattr__, __all__ and the eager core.cli import are gone, and test_core_getattr_exports is removed.
  • src/devops_cli/__init__.py imports nothing from devops_cli at module level and serves __version__ through __getattr__. The five metadata re-exports, ProjectMetadata and __all__ are gone. The 12 source modules that run from devops_cli import __version__ still work, and tests/test_metadata.py imports from devops_cli.config.metadata.
  • The PYDANTIC_DISABLE_PLUGINS assignment stays at the top of src/devops_cli/__init__.py, before any import that can load pydantic, so the logfire plugin opt-out still holds. tests/test_cli_startup_imports.py passes, and its AST ordering test covers devops_cli/__init__.py as well as entry.py.
  • A test in tests/test_code_metrics.py runs python -m devops_cli.core.code_metrics --max-depth 5 <file> in a fresh subprocess and asserts that sys.modules holds no pydantic, typer or devops_cli.config module. Today all three load, in a run that imports 269 modules.
  • docs/agent/tasks/task-773-one-nesting-metric-module.md:45 names refactor(config): the config barrel and the unused config names go, and the package inits stop re-exporting #776 instead of "moved to a follow-up issue, not yet filed".
  • The structural-invariants hook comment (.pre-commit-config.yaml:50) no longer says the package inits load devops_cli.config and typer.

Current references (checked at 3dd7fa6)

  • src/devops_cli/config/__init__.py (867 lines): imports :7-406, _SETTINGS_EXPORTS :408-439, __getattr__ :442-447, __all__ :450-867.
  • Source importers, all under src/devops_cli/: argo/fleet.py:9, argo/gitops.py:25, argo/rollouts.py:80, commands/argo.py:19, commands/serve.py:27, :62, :141, sandbox/host.py:16, sandbox/engine.py:237, docker/sandbox.py:154 and ai/review_schema.py:23.
  • Test importers: tests/test_consolidation_ast_cache.py:83, tests/test_verdict_polarity.py:22, tests/test_server_service.py:24, tests/test_data_dir_configuration.py:21 and :80, and tests/test_ai_agent_prompt.py:95, whose barrel half goes. The devops_cli.config.load_settings patch targets are at tests/test_argo_fleet.py:368, :376 and :393.
  • test_config_package_exports_resolve is at tests/test_public_export_surface.py:135, and test_core_getattr_exports is at tests/test_fast_dispatch.py:106.
  • Package-init importers in tests: tests/test_metadata.py:10-18 imports ProjectMetadata, __version__ and the five metadata functions through devops_cli.
  • Eager package imports: src/devops_cli/__init__.py:15-23 loads config.metadata, which imports pydantic at config/metadata.py:12. src/devops_cli/core/__init__.py:7 loads core.cli, which imports typer at core/cli.py:12. The plugin opt-out is at src/devops_cli/__init__.py:8-13.
  • The hook is at .pre-commit-config.yaml:54-60, and its comment at :47-53 says at :50 that the package inits still load devops_cli.config and typer.
  • A token scan at 3dd7fa6 finds about 128 names that nothing reads (38 in constants.py, 90 in defaults.py) and about 42 that only tests read, up from 8 at 38517a8.
  • CONST_GH_CHECK_BUCKETS (config/constants.py:1096) is still unread and still repeats CheckBucket (github/check_verdict.py:26).
  • tests/fixtures/config_placement_baseline.json does not exist yet.

Dependencies and order


Context & Rationale

config/constants.py changed in 13 of the 25 commits since v0.2.23. config/__init__.py re-exports 427 names in __all__, but only 27 are imported through it, and three recent commits added re-exports that nothing uses. About 68% of the names in constants.py (368 of 529) and defaults.py (372 of 566) have exactly one consumer. About 126 are used nowhere, for example CONST_GH_CHECK_BUCKETS (constants.py:477), which repeats CheckBucket in github/check_verdict.py:26-34. Test-only values ship in src (constants.py:137, :145). #431 is about what those lists contain; this item is about where they live.

Scope & Deliverables

  • Deliverable:
    • First, delete the config/__init__.py re-exports and the unused names, and remove test_config_package_exports_resolve.
    • Then move each single-consumer value into the module that uses it, keeping config for values shared by several modules.
  • Constraint: AGENTS.md:24 requires constants to live centrally for audit. The move needs that rule changed so the audit becomes a query (an AST listing of module-level literal collections) instead of a file location; until that is decided, only the first step is ready.

Strategic Alignment

Scope added 2026-10-02: the architecture review of 2026-10-02 (candidate 7) measured the same problem. The rule change this item waited on is now its own item, #1016. The second step (moving each single-consumer value to its module) is split by subsystem into eight items, one PR each: #1025, -ai-runtime, -ai-agents-rag, -commands, -security, -infra, -github-roadmap and -platform. This item keeps the first step, which does not wait on the rule. Checked at 38517a8 with an AST pass, re-exports excluded:

  • config/__init__.py re-exports 431 names in __all__ (:464-896).

  • Nothing imports about 130 names (about 35 in constants.py, 94 in defaults.py), and only tests import 8. 8 source and 4 test modules import names through devops_cli.config. CONST_GH_CHECK_BUCKETS (now constants.py:708) is still unused.

  • constants.py has grown from 529 to 682 names since this item was filed, and defaults.py from 566 to 595.

  • The 40 CONST_ERROR_CODE_* names are refactor(cli): exceptions carry their codes as class data, and one exit seam replaces 19 hand-rolled exits #1006's.

  • config/__init__.py re-exports nothing. Its imports (:7-421), the lazy settings exports (_SETTINGS_EXPORTS and __getattr__, :423-461) and __all__ (:464-896) are gone. Every module that imported through devops_cli.config imports from the defining module.

  • Every name in constants.py and defaults.py that no module and no test reads, directly or through a name built from it, is deleted (about 130 at 38517a8). Each of the 8 names only tests import moves into the test module that uses it, or into tests/conftest.py when several tests use it. Names used only to build another config/ name stay with that name.

  • test_config_package_exports_resolve (tests/test_public_export_surface.py:135) is removed.

  • If docs(agents): a matching table lives beside its one owner, and moves to config/ only when a second package imports it #1016 has landed, this PR deletes the unused and test-only keys from tests/fixtures/config_placement_baseline.json, and that item's invariants pass.

Update 2026-10-08: refinement

Lines moved: imports config/__init__.py:7-413, lazy exports :415-454, __all__ :457-881; CONST_GH_CHECK_BUCKETS (constants.py:1082) has no reader. Submodule imports keep working. The PR recounts unused names at its base and lists what it deletes.

Proposed design

Problem statement

The config barrel (config/__init__.py) re-exports 427 names, but only 27 are imported through it. About 68% of the names in constants.py and defaults.py have exactly one consumer, and about 126 are used nowhere. The package inits (devops_cli/__init__.py and devops_cli/core/__init__.py) re-export names from submodules, causing unnecessary imports and bloating startup times.

Acceptance criteria

  • Criterion 1: src/devops_cli/config/__init__.py holds only a docstring, and a test fails if it gains an import, an assignment or a function.
    Verification: Delete config/__init__.py and ensure that test_config_package_exports_resolve is removed. Verify that no module imports from the config barrel anymore.
  • Criterion 2: src/devops_cli/core/__init__.py holds only a docstring. _CORE_EXPORTS, its __getattr__, __all__ and the eager core.cli import are gone, and test_core_getattr_exports is removed.
    Verification: Verify that devops_cli/core/__init__.py only contains a docstring and no other code. Confirm that test_core_getattr_exports test is removed.
  • Criterion 3: src/devops_cli/__init__.py imports nothing from devops_cli at module level and serves __version__ through __getattr__. The five metadata re-exports, ProjectMetadata and __all__ are gone. The 12 source modules that run from devops_cli import __version__ still work, and tests/test_metadata.py imports from devops_cli.config.metadata.
    Verification: Ensure that devops_cli/__init__.py no longer imports anything from devops_cli at module level. Confirm that ProjectMetadata is no longer re-exported. Verify that the source modules still work and tests/test_metadata.py imports from devops_cli.config.metadata.
  • Criterion 4: The file still contains the literal __version__, so the release tooling's text read (_get_init_version and _verify_release_versions) still resolves the pyproject version and reports no version mismatch.
    Verification: Confirm that __version__ is present as a literal in src/devops_cli/__init__.py and that release tooling functions correctly.
  • Criterion 5: The PYDANTIC_DISABLE_PLUGINS assignment stays at the top of src/devops_cli/__init__.py, before any import that can load pydantic, so the logfire plugin opt-out still holds. tests/test_cli_startup_imports.py passes, and its AST ordering test covers devops_cli/__init__.py as well as entry.py.
    Verification: Verify that PYDANTIC_DISABLE_PLUGINS assignment is at the top of src/devops_cli/__init__.py before any imports. Run tests/test_cli_startup_imports.py and confirm it passes.
  • Criterion 6: A test in tests/test_code_metrics.py runs python -m devops_cli.core.code_metrics --max-depth 5 in a fresh subprocess and asserts that sys.modules holds no pydantic, typer or devops_cli.config module. Today all three load, in a run that imports 269 modules.
    Verification: Run the test that checks for no pydantic, typer or devops_cli.config modules being loaded and confirm it passes.
  • Criterion 7: docs/agent/tasks/task-773-one-nesting-metric-module.md:45 names refactor(config): the config barrel and the unused config names go, and the package inits stop re-exporting #776 instead of "moved to a follow-up issue, not yet filed".
    Verification: Check that line 45 in docs/agent/tasks/task-773-one-nesting-metric-module.md references refactor(config): the config barrel and the unused config names go, and the package inits stop re-exporting #776.
  • Criterion 8: The structural-invariants hook comment (.pre-commit-config.yaml:50) no longer says the package inits load devops_cli.config and typer.
    Verification: Verify that line 50 of .pre-commit-config.yaml no longer mentions that package inits load devops_cli.config and typer.

Key questions

  • What are the unused names that need to be deleted?: About 130 names in constants.py and defaults.py have no readers directly or through a name built from it, and only tests import 8. The specific names include CONST_GH_CHECK_BUCKETS, CONST_ERROR_CODE_HARNESS, and CONST_ERROR_CODE_STRUCTURED_VALIDATION. [sources: src/devops_cli/config/init.py:464-896, src/devops_cli/config/constants.py:1096, src/devops_cli/config/defaults.py:595]
  • Which modules import names through the config barrel?: Source importers include argo/fleet.py, argo/gitops.py, argo/rollouts.py, commands/argo.py, commands/serve.py, sandbox/host.py, sandbox/engine.py, docker/sandbox.py, and ai/review_schema.py. Test importers include tests/test_consolidation_ast_cache.py, tests/test_verdict_polarity.py, tests/test_server_service.py, tests/test_data_dir_configuration.py, tests/test_ai_agent_prompt.py. [sources: src/devops_cli/config/init.py:7-421, src/devops_cli/config/init.py:423-461, src/devops_cli/config/init.py:464-896]
  • What are the test-only names that need to be moved?: There are about 42 names that only tests read, and these will be moved into the test module that uses them or into tests/conftest.py when several tests use it. [sources: src/devops_cli/config/init.py:464-896]
  • Should the package inits become lazy or just stop re-exporting?: The decision was made to stop re-exporting instead of becoming lazy, because the only name any source module imports through them is __version__; it stays, served by a module __getattr__. Only tests read the other names. (proposed) [sources: src/devops_cli/init.py:15-23, src/devops_cli/core/init.py:7]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    type/refactor
    scope/config
    priority/p2-medium
    on Oct 1, 2026
  2. added
    priority/p3-low
    and removed
    priority/p2-medium
    on Oct 2, 2026
  3. dan-petty commented on Oct 2, 2026

    @dan-petty
    OwnerAuthor

    Grooming (2026-10-02): Priority p2-medium → p3-low. Code-health cleanup with no defect and no user-visible effect.

    Checked against the code at the release/v0.2.25 tip.

  4. dan-petty commented on Oct 9, 2026

    @dan-petty
    OwnerAuthor

    Folded in from #773 (2026-10-09)

    #773 (PR #1466) moved the nesting metric into core/code_metrics.py, whose own imports are stdlib only. But python -m devops_cli.core.code_metrics runs the package inits first:

    • devops_cli/__init__.py imports devops_cli.config.metadata, and with it pydantic and the devops_cli.config barrel this item removes;
    • devops_cli/core/__init__.py imports core.cli, and with it typer and 16 devops_cli.exceptions modules.

    A hook run loads 269 modules and took 0.43 s, against 0.07 s for the module's stdlib imports alone (medians of 5). When the barrel goes here, also make those two package inits import lazily (or not at all), so the structural-invariants hook loads only the stdlib. Criterion to add: a fresh-subprocess python -m devops_cli.core.code_metrics run leaves no pydantic, typer or devops_cli.config module in sys.modules.

    When this lands, also update docs/agent/tasks/task-773-one-nesting-metric-module.md, whose known-limit bullet says the lazy package inits were "moved to a follow-up issue, not yet filed": it should name this issue (#773 merged before the fold).

  5. modified the milestones: , v0.2.38 on Oct 17, 2026
  6. changed the title [-]refactor(config): single-use constants live with their consumer and the config barrel goes[/-] [+]refactor(config): the config barrel and the unused config names go, and the package inits stop re-exporting[/+] on Oct 18, 2026
  7. dan-petty commented on Oct 18, 2026

    @dan-petty
    OwnerAuthor

    Status set to Ready at 25e2cda (see proposed design in issue body).

  8. removed this from the v0.2.38 milestone on Oct 20, 2026
  9. added a commit that references this issue on Oct 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority/p3-lowscope/configtype/refactor

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions