feat(t2-3): replace global config singleton with local TycoonConfig construction - #172
Conversation
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
|
Cleanest PR of the stack. The conversion is complete and consistent across all four command modules, and the test churn is genuinely just cleanup — I checked the three One dead call: Two structural notes, neither blocking:
The singleton is still live in |
db-tycoon-stephen
left a comment
There was a problem hiding this comment.
Requesting changes on the items in the comment above: drop the now-dead cfg.reload() at sources.py:494, and promote the duplicated TycoonConfig(project_root=_find_project_root()) into a public factory rather than importing a private helper across four modules.
Also worth opening an issue for the singleton still live in transform.py/db.py/status.py so the two patterns don't become permanent. Strongest PR of the stack otherwise — the test cleanup checks out.
db-tycoon-stephen
left a comment
There was a problem hiding this comment.
All three addressed. load_config() is the right shape and the docstring pointing people away from _find_project_root is a nice touch — no imports of it left in commands/. You also caught the second dead reload() in remove_source that I missed. Thanks for filing #175 for the remaining modules.
fb7b4b8 to
badd95b
Compare
Writes metadata: defaults and bumps version to 0.2.0 in existing tycoon.yml files. Operates on raw YAML so comments and ordering are preserved. Idempotent — second call returns False with no file write.
…ion bump Instantiate MetadataConfig once rather than twice. Guard the version bump so a file already at a future schema version is not written back down to SCHEMA_VERSION. Update docstring to accurately state that comments are not preserved through the yaml round-trip.
…a_version field Switch migrate_project from yaml.safe_load/yaml.dump to ruamel.yaml so comments and blank lines survive the round-trip. Add schema_version as a separate field on TycoonProject so the user's version field is never touched by migration. Add ruamel-yaml==0.19.1 as a runtime dependency. Adds two new tests: comments_preserved and user_version_not_overwritten.
…e versions Change SCHEMA_VERSION from a semver string to an integer (2) so version comparisons are unambiguous — string comparison would incorrectly treat "0.10.0" < "0.2.0" as True. Change schema_version field type to int | None. Add type guard before comparison: a float schema_version (e.g. 0.2 written unquoted in YAML) now raises ValueError with a clear message rather than a TypeError. A schema_version newer than SCHEMA_VERSION also raises rather than silently passing. Add two new tests covering both error paths.
261c26c to
70d53b5
Compare
…onstruction Each ingestion command (sources, run_all, sync_cmd, explore) now constructs TycoonConfig(project_root=_find_project_root()) at invocation time rather than importing the module-level singleton. Tests drop monkeypatch.setattr calls in favour of monkeypatch.chdir so _find_project_root resolves the correct tmp directory without brittle module-level patching. Closes #94
Add load_config() to config.py as a public entry point that wraps TycoonConfig(project_root=_find_project_root()), removing the need for command modules to import the private _find_project_root across module boundaries. Update all four ingestion command files to use it. Drop two dead cfg.reload() calls in sources.py (add_source and remove_source): cfg is function-local and nothing reads from it again after either call. Tracks remaining singleton uses in transform.py / db.py / status.py in issue #175.
70d53b5 to
508d511
Compare
Summary
from tycoon.config import configglobal singleton import from four ingestion command modules:sources.py,run_all.py,sync_cmd.py, andexplore.pyTycoonConfig(project_root=_find_project_root())at invocation time, so every CLI call gets a fresh, correctly-rooted config without shared mutable statesources._require_project()now returns theTycoonConfigit builds so all helpers receive it as an explicit argument;_maybe_auto_scaffoldgains acfgkeyword parametermonkeypatch.setattr(mod, "config", ...)in favour ofmonkeypatch.chdir(tmp_path)— simpler and more faithful to real executionFiles to focus on
Production changes (2 patterns, 4 files):
_require_project()return type +_maybe_auto_scaffoldsignaturecfg = TycoonConfig(...)at top of command function, replaceconfig.X→cfg.XTest changes (drop singleton patching):
Test plan
uv run ruff check src tests— cleanuv run pytest -q— 690 passed, 3 skippedPart of milestone M2 (#83). Stacked on
feat/m2-t2-2.Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Closes #94