refactor: extract paths/jsonio/argutils from cli.py - #91
Merged
Conversation
`plate job/send <url> --dry-run` predicted `would_slice` from the raw URL-path extension, which is absent for Printables model pages and extension-less direct links. In those cases the predictor returned `would_slice: false`, but the real run downloads a model file (the downloader falls back to `.stl` when it cannot infer an extension) and slices it — so the dry-run pre-check disagreed with what actually happened. Fix: share one slicing predicate between the predictor and the doer. - `_ext_would_slice(ext)` in bambu_cli/job/predict.py is now the single rule (`ext in SLICEABLE_EXTENSIONS`, applied to the single-suffix `_file_extension` so `foo.gcode.3mf` stays print-ready). The real-run local, ZIP-member, and post-download branches in orchestrate.py all route through it. - `_predicted_download_slice_extension(url, args)` resolves the URL's predicted extension by reusing the downloader's own `_download_source_extension`, which falls back to `.stl` for sources whose extension is unknowable offline. `--name` is intentionally ignored because the real download overrides the `--name` extension with the URL/resolved-name extension. `would_slice` remains a boolean; no JSON shape or schema change. Tests: extended the direct-URL dry-run matrix (.stl/.step/.obj/.zip/.3mf and .gcode.3mf), added Printables-model-URL and extension-less-URL predictions, a predictor/doer shared-predicate equivalence test, local .gcode.3mf print-ready, and a ZIP-member matrix (.stl slices, .3mf/.gcode.3mf do not). Strengthened the Printables dry-run agent smoke to assert would_slice=True.
…80938994f57 # Conflicts: # CHANGELOG.md
Extract the filesystem-path, JSON-mode/URL-redaction, and argparse-coercion helpers out of bambu_cli/cli.py into three focused modules (paths.py, jsonio.py, argutils.py) so domain modules no longer import private _underscore helpers from the CLI entrypoint (roadmap B.4). Pure move-and-rewire: symbols keep their names minus the leading underscore in their new public homes; cli.py re-imports them under the old aliases for internal use. Behaviour, JSON envelopes, output, and exit codes are unchanged. Domain -> cli private-helper imports: 93 symbol imports across 32 statements before, 0 after; only the public build_parser/main imports remain. Docs updated: AGENTS.md module table + debt list, quality-roadmap Architecture grade and B.4 row, CHANGELOG [Unreleased] Changed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Roadmap B.4: extract the shared helpers out of
bambu_cli/cli.pyinto three focused modules, so domain code no longer reaches back into the CLI entrypoint for private_underscorehelpers.bambu_cli/paths.py— filesystem/path helpers:expand_path,display_path,path_for_message,exception_for_message(+ internal home-dir cache).bambu_cli/jsonio.py— JSON-mode detection + URL-credential redaction for logs/JSON output:json_mode_requested,redact_url_credentials,looks_like_schemeless_credential_url.bambu_cli/argutils.py— argparse/Namespacecoercion:namespace_get,exit_code_from_system_exit,setup_args_provided.cli.pyre-imports these under their historical underscore aliases for internal use. Symbols keep their names minus the leading underscore in their new public homes; nothing else renamed.Why
The domain→cli private-helper imports were the last thing pinning the Architecture grade at A− (the other item, B.5 single pin helper, landed in #89). This is a pure move-and-rewire refactor — no behaviour change, no user-visible change. Output, JSON envelopes, and exit codes are identical.
Proof the domain→cli private imports are gone
git grepforfrom bambu_cli.cli import(excludingcli.pyitself):The 3 remaining are the public CLI API only —
bambu_cli/bambu.pyimportsmain, andinteractive/{presets,session}.pyimportbuild_parser(function-local). No private helper is imported fromclianywhere.Gates (all green locally)
pytest -m "not live"under-W error::ResourceWarning,--cov-fail-under=83: 1051 passed, coverage 84.76%ruff check/ruff format --check/mypy -p bambu_cli(60 files) /bandit -ll(no issues): passsyntax_smoke(79 files) /cli_help_smoke(20 subcommands) /ci_workflow_smoke(20 cmds, 60 modules) /privacy_smoke/python_compat_smoke: passsys.exit(grep outside cli.py/errors.py: clean (moved helpers carry none, incl. prose)Test/patch-target changes
tests/test_job.py:_display_pathnow imported frombambu_cli.paths.tests/test_access_code_deprecation.py: patch seam moved frombambu_cli.cli._expand_pathtobambu_cli.paths.expand_path(whereconfig.load_access_codelooks it up). No assertions weakened.Docs
AGENTS.md: module table now listspaths/jsonio/argutils; removed the B.4 debt bullet.docs/quality-roadmap.md: Architecture grade A− → A; B.4/B.5 rows marked done.CHANGELOG.md: one### Changedentry under[Unreleased](internal refactor, no user-visible change).