Split __init__.py into focused modules #29

Closed
opened 2026-06-24 06:56:10 +00:00 by coding-agent-marvin8 · 1 comment
coding-agent-marvin8 commented 2026-06-24 06:56:10 +00:00 (Migrated from codeberg.org)

src/zaojun/init.py has grown to ~1320 lines as features (aged-version fallback, vulnerability scanning, license checking, library-mode) accumulated. The file now contains at least seven distinct concerns mixed together, making it hard to navigate and hard to place new logic when adding features.

This issue tracks splitting it into focused single-responsibility modules with no behaviour changes.

src/zaojun/__init__.py has grown to ~1320 lines as features (aged-version fallback, vulnerability scanning, license checking, library-mode) accumulated. The file now contains at least seven distinct concerns mixed together, making it hard to navigate and hard to place new logic when adding features. This issue tracks splitting it into focused single-responsibility modules with no behaviour changes.
coding-agent-marvin8 commented 2026-06-24 06:58:01 +00:00 (Migrated from codeberg.org)

Findings

Seven distinct concerns currently live in __init__.py:

  • CLI entry point and config merging
  • Dependency processing pipeline
  • PyPI HTTP client and response parsing
  • Version classification (including aged-version fallback and library-constraint checking)
  • Vulnerability filtering
  • Text and JSON rendering
  • Dataclasses (VulnAdvisory, PyPIPackageData, DependencyResult)

The existing split-out files (cache.py, config.py, licenses.py) are already well-scoped and won't change.

Plan of attack

Create six new modules with a clean layered dependency graph (no cycles):

Module Responsibility
models.py Three dataclasses — the data root layer
pypi.py PyPI HTTP client and response parsers
version.py All version classification + aged-fallback + library-constraint logic
vulns.py Vulnerability filtering (_norm_pkg lives here too)
render.py Text and JSON rendering
checker.py Dependency processing pipeline
__init__.py Thin CLI only (~190 lines)

Dependency graph: models ← pypi, version, vulns, render; all ← checker; checker ← __init__

Migration is a pure mechanical move — one module at a time, full quality suite after each step. No logic changes.

Design spec: docs/superpowers/specs/2026-06-24-refactor-init-design.md

## Findings Seven distinct concerns currently live in `__init__.py`: - CLI entry point and config merging - Dependency processing pipeline - PyPI HTTP client and response parsing - Version classification (including aged-version fallback and library-constraint checking) - Vulnerability filtering - Text and JSON rendering - Dataclasses (`VulnAdvisory`, `PyPIPackageData`, `DependencyResult`) The existing split-out files (`cache.py`, `config.py`, `licenses.py`) are already well-scoped and won't change. ## Plan of attack Create six new modules with a clean layered dependency graph (no cycles): | Module | Responsibility | |---|---| | `models.py` | Three dataclasses — the data root layer | | `pypi.py` | PyPI HTTP client and response parsers | | `version.py` | All version classification + aged-fallback + library-constraint logic | | `vulns.py` | Vulnerability filtering (`_norm_pkg` lives here too) | | `render.py` | Text and JSON rendering | | `checker.py` | Dependency processing pipeline | | `__init__.py` | Thin CLI only (~190 lines) | Dependency graph: `models ← pypi, version, vulns, render; all ← checker; checker ← __init__` Migration is a pure mechanical move — one module at a time, full quality suite after each step. No logic changes. Design spec: `docs/superpowers/specs/2026-06-24-refactor-init-design.md`
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
marvin8/zaojun#29
No description provided.