Skip to content

Consolidate duplicated file-write helpers across modules #2

@JRS1986

Description

@JRS1986

Context

Near-duplicate file-write helpers exist in four modules:

They all do the same thing — mkdir(parents=True, exist_ok=True) + write_text/write_json — with subtly different overwrite semantics (always overwrite vs skip-if-exists vs append-to-skipped-list). Easy place for bugs to creep in as the surface grows.

Recommendation

Create src/coding_scaffold/io.py with three primitives:

def write_text(path: Path, content: str, *, overwrite: bool = True) -> Path: ...
def write_json(path: Path, payload: object, *, overwrite: bool = True) -> Path: ...
def write_if_absent(path: Path, content: str) -> Path | None: ...  # returns None when skipped

Replace all four module-local helpers with these. Update call sites in writers.py, adapters.py, knowledge.py, enablement.py.

Verification

  • git grep -nE '_write_json|_write_text|_collect_write|_collect\\b' src/ shows no duplicates.
  • All 51 tests still pass.
  • Adding a new template-writing call site requires importing one of the three helpers, not copying yet another local function.

Carry-over from prior code review (F8).

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions