Skip to content

Refactor CLI with Cyclopts, split models/services, add stats & docs — 1.0.0 stable - #16

Merged
dcode merged 7 commits into
mainfrom
refactor-cli-cyclopts-17353565500630855185
Feb 24, 2026
Merged

Refactor CLI with Cyclopts, split models/services, add stats & docs — 1.0.0 stable#16
dcode merged 7 commits into
mainfrom
refactor-cli-cyclopts-17353565500630855185

Conversation

@dcode

@dcode dcode commented Feb 24, 2026

Copy link
Copy Markdown
Owner

Summary

This PR brings the repository to its first stable 1.0.0 release, incorporating a major CLI/SDK refactor and all follow-up
polish commits:

  • CLI migrated from argparse → Cyclopts — global flags via app.meta, Annotated+cyclopts.Parameter for rich help,
    auth login/show/clear subcommands with rich.prompt
  • Monolithic models.py split into models/ package — separate modules for cameras, common, config, files,
    jobs, printers, stats, teams
  • New services/ package — per-resource service classes encapsulate all SDK calls; PrusaConnectClient now exposes
    typed service attributes
  • Removed deprecated shim methods (get_printers(), get_cameras(), etc.) before stable release (no stability
    guarantee in prereleases)
  • New stats CLI command group with printer/team subcommands; print usage duration rendered human-readable or
    --seconds for numeric output
  • --format flag added to CLI (rich / plain / json output); priority: flag → env var → config file → TTY auto-detect
  • Docs restructured into docs/cli/ and docs/sdk/ subdirectories; new installation, authentication, CLI quickstart,
    and SDK quickstart pages; mkdocs.yml updated
  • CHANGELOG.md added (Keep a Changelog format)
  • README completed with Quick Start snippet, docs link, Contributing, and License sections
  • Comprehensive test coverage added for all CLI commands, services, config, and SDK surface (test_sdk_coverage.py)
  • CI security fix: split dependabot uv-lock workflow to eliminate pwn-request vulnerability (CodeQL
    actions/untrusted-checkout/high)
  • Dependency bumps: pillow 11→12, actions/checkout, actions/cache, setup-uv, artifact actions

Test plan

  • uv run pytest — all unit tests pass
  • prusactl --help renders correctly in rich, plain, and json output modes
  • prusactl stats printers and prusactl stats teams return expected output
  • prusactl auth login / show / clear flow works end-to-end
  • Docs build cleanly: uv run mkdocs build
  • Verify no deprecated shim methods remain in sdk.py
  • Confirm CHANGELOG and README are accurate for 1.0.0

This PR refactors the Python Prusa Connect SDK client with several major improvements:

- Migrate CLI from argparse to Cyclopts for improved argument parsing and DX
- Use `app.meta` for global flags (token, host, verbose, output format)
- Refactor `auth` command group with `login`, `show`, `clear` subcommands using `rich.prompt`
- Use `Annotated` + `cyclopts.Parameter` throughout for rich help strings
- Add config file support via `cli/config.py`

- Split monolithic `models.py` into a `models/` package
- Separate modules: `cameras`, `common`, `config`, `files`, `jobs`, `printers`, `stats`, `teams`

- Add `services/` package with per-resource service classes
- Services encapsulate SDK calls: `cameras`, `files`, `jobs`, `printers`, `stats`, `teams`

- Add `stats` CLI command group with subcommands for printer/team stats

- Restructure docs into `docs/cli/` and `docs/sdk/` subdirectories
- Add `docs/installation.md` and `docs/authentication.md`
- Add CLI quickstart and SDK quickstart guides
- Update `mkdocs.yml` navigation

- Add comprehensive test coverage for all CLI commands and services
- Add `test_sdk_coverage.py` and `test_config.py`
- Fix CI lint errors and apply ruff formatting
- Disable mkdocs image optimization plugin to fix CI (missing `pngquant`)
- Remove `.python-version` pin; update pre-commit config
The prerelease versions (v1.0.0a0, v1.0.0a2) introduced DeprecationWarning
wrappers on PrusaConnectClient as a transitional courtesy during the
refactor to a service-based API. Per semver, prereleases carry no
stability guarantee, so these shims are removed before the first stable
release rather than carrying dead weight.

Removed from sdk.py:
- get_printers()  → client.printers.list_printers()
- get_printer()   → client.printers.get()
- get_cameras()   → client.cameras.list()
- get_teams()     → client.teams.list_teams()
- get_team()      → client.teams.get()
- send_command()  → client.printers.send_command()

CLI commands and all tests updated to call the service layer directly.
Service attributes annotated at class level for correct type inference.
- Fix stale API examples in docs/examples.md and docs/sdk/quickstart.md
  to use the service-based API (client.printers.list_printers(), etc.)
  following removal of deprecated shim methods
- Bump Development Status classifier to 5 - Production/Stable
- Complete README with Quick Start snippet, Documentation link,
  Contributing and License sections
- Add CHANGELOG.md (Keep a Changelog format) documenting breaking
  changes, additions, and alpha release history
CodeQL rule actions/untrusted-checkout/high flagged that the commit job
was checking out untrusted PR code inside a pull_request_target workflow
(which has secret/write access), violating the principle of least
privilege.

Fix: split into two workflows following the recommended pattern.

- dependabot-uv-lock.yml now uses pull_request (unprivileged, no
  secrets). It checks out PR code, runs `uv lock`, and uploads the
  resulting uv.lock as an artifact. No credentials are exposed.

- dependabot-uv-lock-commit.yml uses workflow_run, triggered only after
  the unprivileged workflow succeeds. It checks out the PR branch at the
  exact HEAD SHA the lock job saw, downloads the artifact into the
  workspace, and commits. No code from the PR is executed — only git
  operations on the known-good artifact.

The HEAD_BRANCH env-var pattern is used for the push target to avoid
shell injection from branch name expressions interpolated directly into
the run block.

Ref: https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
- Adds `--format` flag to CLI to allow selection of rich, plain, or json output
- Change print usage stats value type to duration with human-readable output or optional `--seconds` flag for numeric output
Comment thread .github/workflows/dependabot-uv-lock-commit.yml Dismissed
@dcode
dcode marked this pull request as draft February 24, 2026 04:34
Resolves merge conflicts between the refactor-cli-cyclopts PR branch and main.
All conflicts were resolved in favor of the PR branch (HEAD), which has:
- common.output_message/output_table helpers instead of direct rprint/Table usage
- --format CLI flag for configurable output (rich/plain/json)
- _NO_PRINTER constant in stats.py
- --seconds flag in stats usage command
- duration (timedelta) field in PrintingNotPrintingEntry instead of raw int
- resolved_id pattern in camera commands for default fallback
- Removed legacy backward-compat comment in auth.py
- Split dependabot-uv-lock.yml (commit job lives in separate workflow)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@dcode
dcode marked this pull request as ready for review February 24, 2026 04:46
@dcode
dcode merged commit 3f37b00 into main Feb 24, 2026
27 checks passed
@dcode
dcode deleted the refactor-cli-cyclopts-17353565500630855185 branch February 24, 2026 04:55
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.

2 participants