Refactor CLI with Cyclopts, split models/services, add stats & docs — 1.0.0 stable - #16
Merged
Merged
Conversation
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
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
marked this pull request as ready for review
February 24, 2026 04:46
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.
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:
app.meta,Annotated+cyclopts.Parameterfor rich help,auth login/show/clearsubcommands withrich.promptmodels.pysplit intomodels/package — separate modules forcameras,common,config,files,jobs,printers,stats,teamsservices/package — per-resource service classes encapsulate all SDK calls;PrusaConnectClientnow exposestyped service attributes
get_printers(),get_cameras(), etc.) before stable release (no stabilityguarantee in prereleases)
statsCLI command group with printer/team subcommands; print usage duration rendered human-readable or--secondsfor numeric output--formatflag added to CLI (rich / plain / json output); priority: flag → env var → config file → TTY auto-detectdocs/cli/anddocs/sdk/subdirectories; new installation, authentication, CLI quickstart,and SDK quickstart pages;
mkdocs.ymlupdatedtest_sdk_coverage.py)actions/untrusted-checkout/high)Test plan
uv run pytest— all unit tests passprusactl --helprenders correctly in rich, plain, and json output modesprusactl stats printersandprusactl stats teamsreturn expected outputprusactl auth login / show / clearflow works end-to-enduv run mkdocs buildsdk.py