-
Notifications
You must be signed in to change notification settings - Fork 13
feat(cli, python): programmatic interface to cli with python bindings #2677
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #2677 +/- ##
==========================================
- Coverage 83.46% 83.41% -0.05%
==========================================
Files 262 263 +1
Lines 51297 51489 +192
Branches 46858 46984 +126
==========================================
+ Hits 42813 42949 +136
- Misses 6105 6156 +51
- Partials 2379 2384 +5
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
169afd7 to
195070d
Compare
cqc-alec
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, just a few comments.
hugr-py/src/hugr/cli.py
Outdated
| format: Target format ("json" or "model", default: auto-detect). | ||
| text: Output as text (default: auto-detect). | ||
| binary: Output as binary (default: auto-detect). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not clear what "auto-detect" means for output format. (I think the default is to use the input format, i.e. do no conversion, if not specified?)
hugr-py/src/hugr/cli.py
Outdated
| text: Output as text (default: auto-detect). | ||
| binary: Output as binary (default: auto-detect). | ||
| compress: Compress the output (default: False). | ||
| compression_level: Compression level 0-9 (default: 6). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be 1--22? And where does 6 come from?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah this was the last item on my todo list to fix sorry missed it (is a placeholder)
Co-authored-by: Alec Edgington <[email protected]>
| } | ||
| } | ||
|
|
||
| fn run_external(args: Vec<OsString>) -> Result<()> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved unchanged to lib.rs
hugr-py/src/hugr/cli.py
Outdated
| text: Output as text (default: auto-detect). | ||
| binary: Output as binary (default: auto-detect). | ||
| compress: Compress the output (default: False). | ||
| compression_level: Compression level 0-9 (default: 6). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah this was the last item on my todo list to fix sorry missed it (is a placeholder)
| /// Directly invoke the HUGR CLI entrypoint. | ||
| fn run_cli() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add that we're invoking the CLI passing std::env::args to the docs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may be a bit confusing to call this module cli when including it in the python lib.
From a user standpoint, there's no connection between hugr.cli.describe or hugr.cli.mermaid and a command line interface.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any suggestions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I sort of agree, but not sure what else to call it. utils is too broad.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally like making it clear that it relies on the cli interface, it makes the idiosyncrasies of the interface easier to understand (e.g. why pass bytes?). The module docstring explains why it is this way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was imagining that we would add user level features in future that would wrap around this (e.g. Package.describe() -> PackageDesc) where there is then no reference to the cli.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, let's go with cli for now then
🤖 I have created a release *beep* *boop* --- ## [0.14.2](hugr-py-v0.14.1...hugr-py-v0.14.2) (2025-11-13) ### Features * **cli, python:** programmatic interface to cli with python bindings ([#2677](#2677)) ([0fd0332](0fd0332)) * ComposablePass protocol and ComposedPass for hugr-py (unstable) ([[#2636](https://github.com/CQCL/hugr/issues/2636)](https://github.com/CQCL/hugr/pull/2636)) ([45dc3fc](45dc3fc)) * return description output to python on error ([#2681](#2681)) ([f483146](f483146)) * track package descriptions when loading ([#2639](#2639)) ([349dd61](349dd61)) ### Documentation * Fix typo in docstring. ([#2656](#2656)) ([a1ce622](a1ce622)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). --------- Co-authored-by: Seyon Sivarajah <[email protected]>
Closes #2671
Goals
hugrcli available in environment when installed via uv (uvx hugr --help)Implications
Primary outcomes
Secondary outcomes
climodule in python to wrap core sub-commands and parameters, with simply typed interfacesdescribejson outputPossible issues
uvx hugr --versionwill report a different value touv --with hugr run python -c "import hugr; print(hugr.__version__)". Are we ok with this?