Skip to content
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

feat: hugr binary cli tool #1096

Merged
merged 4 commits into from
May 22, 2024
Merged

feat: hugr binary cli tool #1096

merged 4 commits into from
May 22, 2024

Conversation

ss2165
Copy link
Member

@ss2165 ss2165 commented May 22, 2024

Closes #1095

currently validates against std extensions

can read from stdin with echo "<json>" | hugr -

binary depends on optional feature to limit dependencies, but not put in sub crate to allow cargo install hugr

add integration testing of binary behaviour
based on https://docs.rs/assert_cmd/2.0.14/assert_cmd/cmd/struct.Command.html#method.write_stdin

@ss2165 ss2165 requested a review from a team as a code owner May 22, 2024 11:25
@ss2165 ss2165 requested review from zrho and doug-q and removed request for zrho May 22, 2024 11:25
Copy link

codecov bot commented May 22, 2024

Codecov Report

Attention: Patch coverage is 91.17647% with 3 lines in your changes are missing coverage. Please review.

Project coverage is 86.73%. Comparing base (3ea4834) to head (dc1396b).

Files Patch % Lines
hugr/src/cli.rs 80.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1096      +/-   ##
==========================================
+ Coverage   86.66%   86.73%   +0.06%     
==========================================
  Files          88       90       +2     
  Lines       18467    18501      +34     
  Branches    18074    18108      +34     
==========================================
+ Hits        16005    16047      +42     
+ Misses       1621     1615       -6     
+ Partials      841      839       -2     
Flag Coverage Δ
rust 86.81% <91.17%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@doug-q doug-q left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice coverage. I have a suggestion inline but I do not feel strongly if you disagree.

hugr/src/cli.rs Outdated
pub const VALID_PRINT: &str = "HUGR valid!";

/// Run the HUGR cli and validate against an extension registry.
pub fn run(registry: &ExtensionRegistry) -> Result<(), Box<dyn std::error::Error>> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to expose pub CmdLineArgs and either take it as a parameter here, or put this function on impl CmdLineArgs.

This moves the CmdLineArgs::parse() into the caller, which allows callers to add (and handle) options, embed as a SubCommand etc.


#[fixture]
fn test_hugr_file(test_hugr_string: String) -> NamedTempFile {
// TODO use proptests?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For generating the Hugr? That's a long way off, we need to generate valid sub-properties then wire them together into a Hugr. I don't think it would be useful here, we are already testing serialisation elsewhere.

@aborgna-q
Copy link
Collaborator

Does the cli need access to non-public stuff? It would be cleaner to have it as a separate subcrate instead;

Add a hugr-cli dir with the relevant code and a Cargo.toml with

[[bin]]
name = "hugr"
path = "src/main.rs"

This way we don't need to add a new feature that's useless to lib users.

@doug-q
Copy link
Collaborator

doug-q commented May 22, 2024

This way we don't need to add a new feature that's useless to lib users.

The reasoning, which should be in the commit message, is to make cargo install hugr work.

I disagree it's useless to lib users.

@ss2165 ss2165 requested a review from doug-q May 22, 2024 13:24
@aborgna-q
Copy link
Collaborator

After some discussion; if we want to be able to do cargo install hugr (instead of hugr-cli) then it's right that we'll need to define the binary there.

I still think the library should go in a subcrate. The cli feature here could be renamed to _cli so it doesn't appear in docs.rs and users that need the args definitions can depend on hugr-cli directly.

We can merge this PR as-is, and I'll propose the subcrate in a separate issue.

@ss2165 ss2165 added this pull request to the merge queue May 22, 2024
Merged via the queue into main with commit 3476bd7 May 22, 2024
19 checks passed
@ss2165 ss2165 deleted the ss/cli branch May 22, 2024 14:09
@github-actions github-actions bot mentioned this pull request May 22, 2024
@github-actions github-actions bot mentioned this pull request May 23, 2024
This was referenced May 29, 2024
github-merge-queue bot pushed a commit that referenced this pull request May 29, 2024
## 🤖 New release
* `hugr`: 0.4.0 -> 0.5.0
* `hugr-cli`: 0.1.0
* `hugr-core`: 0.1.0
* `hugr-passes`: 0.1.0

<details><summary><i><b>Changelog</b></i></summary><p>

## `hugr`
<blockquote>

## 0.5.0 (2024-05-29)

### Bug Fixes

- Missing re-exports in `hugr::hugr`
([#1127](#1127))
- Set initial version of hugr-core to 0.1.0
([#1129](#1129))

### Features

- [**breaking**] Remove `PartialEq` impl for `ConstF64`
([#1079](#1079))
- [**breaking**] Allow "Row Variables" declared as List<Type>
([#804](#804))
- Hugr binary cli tool ([#1096](#1096))
- [**breaking**] Move passes from `algorithms` into a separate crate
([#1100](#1100))
- [**breaking**] Disallow nonlocal value edges into FuncDefn's
([#1061](#1061))
- [**breaking**] Move cli in to hugr-cli sub-crate
([#1107](#1107))
- Add verbosity, return `Hugr` from `run`.
([#1116](#1116))
- Unseal and make public the traits `HugrInternals` and
`HugrMutInternals` ([#1122](#1122))

### Refactor

- [**breaking**] No Ports in TypeRow
([#1087](#1087))
- Add a `hugr-core` crate
([#1108](#1108))
</blockquote>

## `hugr-core`
<blockquote>

## 0.1.0 (2024-05-29)

### Bug Fixes

- Set initial version of hugr-core to 0.1.0
([#1129](#1129))

### Features

- [**breaking**] Move cli in to hugr-cli sub-crate
([#1107](#1107))
- Make internals of int ops and the "int" CustomType more public.
([#1114](#1114))
- Unseal and make public the traits `HugrInternals` and
`HugrMutInternals` ([#1122](#1122))

### Refactor

- Add a `hugr-core` crate
([#1108](#1108))
</blockquote>


</p></details>

---
This PR was generated with
[release-plz](https://github.com/MarcoIeni/release-plz/).

---------

Co-authored-by: Agustin Borgna <[email protected]>
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.

HUGR validation CLI
3 participants