Skip to content

refactor: split monolithic models.py into a models/ subpackage#397

Merged
tschm merged 3 commits intomainfrom
copilot/refactor-models-into-modules
Mar 8, 2026
Merged

refactor: split monolithic models.py into a models/ subpackage#397
tschm merged 3 commits intomainfrom
copilot/refactor-models-into-modules

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 8, 2026

src/rhiza/models.py (~962 lines) contained four unrelated dataclasses, git subprocess helpers, YAML I/O, and path resolution logic in a single file, making it hard to navigate and unit-test in isolation.

Changes

New package structure

src/rhiza/models/
  __init__.py      # re-exports all public symbols — zero changes needed in callers
  _git_utils.py    # get_git_executable, _log_git_stderr_errors, _normalize_to_list
  bundle.py        # BundleDefinition, RhizaBundles
  template.py      # RhizaTemplate (~500 lines)
  lock.py          # TemplateLock

Backward compatibility

__init__.py re-exports the full public API, so all existing imports across commands/ continue to work unchanged:

# still works — no changes required in callers
from rhiza.models import RhizaTemplate, TemplateLock, get_git_executable

Test adjustments

  • test_models.py, test_bundle_resolver.py, test_subprocess_utils.py — imports updated to reference specific submodules (e.g. from rhiza.models.bundle import RhizaBundles)
  • test_commands/test_sync.pysubprocess.run mock path updated from rhiza.models.subprocess.runrhiza.models.template.subprocess.run
Original prompt

This section details on the original issue you should resolve

<issue_title>Refactor</issue_title>
<issue_description>1. 🗂️ Split the Monolithic models.py into Smaller Modules
File: src/rhiza/models.py (~962 lines)

This single file contains four unrelated dataclasses (BundleDefinition, RhizaBundles, RhizaTemplate, TemplateLock), git-subprocess helpers, YAML I/O, and path resolution logic. RhizaTemplate alone is ~500 lines.

Suggested split:

Code
src/rhiza/
models/
init.py # re-exports for backward compatibility
bundle.py # BundleDefinition, RhizaBundles
template.py # RhizaTemplate
lock.py # TemplateLock
_git_utils.py # get_git_executable, _log_git_stderr_errors
This improves navigability, reduces merge conflicts, and makes each class unit-testable in isolation.</issue_description>

<agent_instructions>also adjust the tests then</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@tschm tschm marked this pull request as ready for review March 8, 2026 08:52
Co-authored-by: tschm <2046079+tschm@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor monolithic models.py into smaller modules refactor: split monolithic models.py into a models/ subpackage Mar 8, 2026
Copilot finished work on behalf of tschm March 8, 2026 08:59
@tschm tschm merged commit 626f64a into main Mar 8, 2026
15 checks passed
@tschm tschm deleted the copilot/refactor-models-into-modules branch March 8, 2026 09:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor

2 participants