Skip to content

Commit

Permalink
feat!: move cli in to hugr-cli sub-crate (#1107)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: cli library no longer available from `hugr::cli`

---------

Co-authored-by: Agustín Borgna <[email protected]>
  • Loading branch information
ss2165 and aborgna-q authored May 28, 2024
1 parent 1b4136f commit 766e5c3
Show file tree
Hide file tree
Showing 12 changed files with 107 additions and 32 deletions.
13 changes: 6 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ lto = "thin"

[workspace]
resolver = "2"
members = ["hugr", "hugr-core", "hugr-passes"]
members = ["hugr", "hugr-core", "hugr-passes", "hugr-cli"]
default-members = ["hugr", "hugr-core", "hugr-passes"]
default-run = "hugr"

[workspace.package]
rust-version = "1.75"
Expand All @@ -26,12 +25,8 @@ debug_assert_with_mut_call = "warn"
[workspace.dependencies]
portgraph = { version = "0.12.0" }
insta = { version = "1.34.0" }
assert_cmd = "2.0.14"
assert_fs = "1.1.1"
bitvec = "1.0.1"
cgmath = "0.18.0"
clap = "4.5.4"
clap-stdin = "0.4.0"
context-iterators = "0.2.0"
cool_asserts = "2.0.3"
criterion = "0.5.1"
Expand All @@ -46,7 +41,6 @@ lazy_static = "1.4.0"
num-rational = "0.4.1"
paste = "1.0"
petgraph = { version = "0.6.3", default-features = false }
predicates = "3.1.0"
proptest = "1.4.0"
proptest-derive = "0.4.0"
regex = "1.9.5"
Expand All @@ -62,6 +56,11 @@ thiserror = "1.0.28"
typetag = "0.2.7"
urlencoding = "2.1.2"
webbrowser = "1.0.0"
clap = { version = "4.5.4"}
assert_cmd = "2.0.14"
assert_fs = "1.1.1"
clap-stdin = "0.4.0"
predicates = "3.1.0"

[profile.dev.package]
insta.opt-level = 3
Expand Down
5 changes: 5 additions & 0 deletions hugr-cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Changelog

## 0.1.0 (2024-05-24)

Initial release, ported from `hugr::cli` module.
30 changes: 30 additions & 0 deletions hugr-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[package]
name = "hugr-cli"
version = "0.1.0"
edition = { workspace = true }
rust-version = { workspace = true }
license = { workspace = true }
readme = "README.md"
documentation = "https://docs.rs/hugr-passes/"
homepage = { workspace = true }
repository = { workspace = true }
description = "Compiler passes for Quantinuum's HUGR"
keywords = ["Quantum", "Quantinuum"]
categories = ["compilers"]


[dependencies]
clap = {workspace = true, features = ["derive"]}
clap-stdin = { workspace = true }
hugr-core = { path = "../hugr-core", version = "0.0.0" }
serde_json.workspace = true
thiserror.workspace = true

[lints]
workspace = true

[dev-dependencies]
assert_cmd = { workspace = true }
assert_fs = { workspace = true }
predicates = { workspace = true }
rstest.workspace = true
43 changes: 43 additions & 0 deletions hugr-cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
![](/hugr/assets/hugr_logo.svg)

hugr-cli
===============

[![build_status][]](https://github.com/CQCL/hugr/actions)
[![crates][]](https://crates.io/crates/hugr-cli)
[![msrv][]](https://github.com/CQCL/hugr)
[![codecov][]](https://codecov.io/gh/CQCL/hugr)

This crate provides tooling used by the `hugr` CLI tool.
Refer to the [main crate](http://crates.io/crates/hugr) for more information.

## Usage

Add the dependency to your project:

```bash
cargo add hugr-cli
```

Please read the [API documentation here][].

## Recent Changes

See [CHANGELOG][] for a list of changes. The minimum supported rust
version will only change on major releases.

## Development

See [DEVELOPMENT.md](https://github.com/CQCL/hugr/blob/main/DEVELOPMENT.md) for instructions on setting up the development environment.

## License

This project is licensed under Apache License, Version 2.0 ([LICENSE][] or http://www.apache.org/licenses/LICENSE-2.0).

[API documentation here]: https://docs.rs/hugr-cli/
[build_status]: https://github.com/CQCL/hugr/actions/workflows/ci-rs.yml/badge.svg?branch=main
[msrv]: https://img.shields.io/badge/rust-1.75.0%2B-blue.svg
[crates]: https://img.shields.io/crates/v/hugr-cli
[codecov]: https://img.shields.io/codecov/c/gh/CQCL/hugr?logo=codecov
[LICENSE]: https://github.com/CQCL/hugr/blob/main/LICENCE
[CHANGELOG]: https://github.com/CQCL/hugr/blob/main/hugr-cli/CHANGELOG.md
6 changes: 3 additions & 3 deletions hugr-core/src/cli.rs → hugr-cli/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! Standard command line tools, used by the hugr binary.
use crate::{extension::ExtensionRegistry, Hugr, HugrView};
use clap::Parser;
pub use clap::Parser;
use clap_stdin::FileOrStdin;
use hugr_core::{extension::ExtensionRegistry, Hugr, HugrView};
use thiserror::Error;
/// Validate and visualise a HUGR file.
#[derive(Parser, Debug)]
Expand Down Expand Up @@ -30,7 +30,7 @@ pub enum CliError {
Parse(#[from] serde_json::Error),
/// Error validating HUGR.
#[error("Error validating HUGR: {0}")]
Validate(#[from] crate::hugr::ValidationError),
Validate(#[from] hugr_core::hugr::ValidationError),
}

/// String to print when validation is successful.
Expand Down
7 changes: 1 addition & 6 deletions hugr-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ workspace = true

[features]
extension_inference = []
cli = ["dep:clap", "dep:clap-stdin"]

[dependencies]
portgraph = { workspace = true, features = ["serde", "petgraph"] }
Expand All @@ -45,8 +44,6 @@ delegate = { workspace = true }
paste = { workspace = true }
strum = { workspace = true }
strum_macros = { workspace = true }
clap = { workspace = true, features = ["derive"], optional = true }
clap-stdin = { workspace = true, optional = true }

[dev-dependencies]
rstest = { workspace = true }
Expand All @@ -58,9 +55,7 @@ jsonschema = { workspace = true }
proptest = { workspace = true }
proptest-derive = { workspace = true }
regex-syntax = { workspace = true }
assert_cmd = { workspace = true }
predicates = { workspace = true }
assert_fs = { workspace = true }


# Required for documentation examples
hugr = { path = "../hugr" }
3 changes: 0 additions & 3 deletions hugr-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,5 @@ pub use crate::core::{
pub use crate::extension::Extension;
pub use crate::hugr::{Hugr, HugrView, SimpleReplacement};

#[cfg(feature = "cli")]
pub mod cli;

#[cfg(test)]
pub mod proptest;
2 changes: 1 addition & 1 deletion hugr-passes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ thiserror = { workspace = true }
extension_inference = ["hugr-core/extension_inference"]

[dev-dependencies]
rstest = "0.19.0"
rstest = { workspace = true }
11 changes: 5 additions & 6 deletions hugr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,21 @@ path = "src/lib.rs"
extension_inference = []

# Definitions used by the `hugr` binary
_cli = ["hugr-core/cli", "dep:clap"]
_cli = ["dep:hugr-cli"]

[dependencies]
hugr-core = { path = "../hugr-core", version = "0.0.0" }
hugr-passes = { path = "../hugr-passes", version = "0.1.0" }

clap = { workspace = true, features = ["derive"], optional = true }
hugr-cli = { path = "../hugr-cli", version = "0.1.0", optional = true }

[dev-dependencies]
rstest = { workspace = true }
assert_cmd = { workspace = true }
predicates = { workspace = true }
assert_fs = { workspace = true }
lazy_static = { workspace = true }
criterion = { workspace = true, features = ["html_reports"] }
serde_json = { workspace = true }
assert_cmd = { workspace = true }
assert_fs = { workspace = true }
predicates = { workspace = true }

[[bench]]
name = "bench_main"
Expand Down
3 changes: 1 addition & 2 deletions hugr/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ use hugr::std_extensions::logic::EXTENSION as LOGICS_EXTENSION;

use hugr::extension::{ExtensionRegistry, PRELUDE};

use clap::Parser;
use hugr_core::cli::CmdLineArgs;
use hugr_cli::{CmdLineArgs, Parser};

fn main() {
let opts = CmdLineArgs::parse();
Expand Down
8 changes: 4 additions & 4 deletions hugr/tests/cli.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
#![cfg(feature = "_cli")]
use assert_cmd::Command;
use assert_fs::{fixture::FileWriteStr, NamedTempFile};
use hugr::builder::DFGBuilder;
use hugr::{
use hugr_cli::VALID_PRINT;
use hugr_core::builder::DFGBuilder;
use hugr_core::{
builder::{Container, Dataflow, DataflowHugr},
extension::prelude::{BOOL_T, QB_T},
type_row,
types::FunctionType,
Hugr,
};
use hugr_core::cli::VALID_PRINT;
use predicates::{prelude::*, str::contains};
use rstest::{fixture, rstest};

#[fixture]
fn cmd() -> Command {
Command::cargo_bin("hugr").unwrap()
Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap()
}

#[fixture]
Expand Down
8 changes: 8 additions & 0 deletions release-plz.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,11 @@ release = true
# Disabled until the first version is manually published
publish = false
git_release_enable = false


[[package]]
name = "hugr-cli"

# Disabled until the first version is manually published
publish = false
git_release_enable = false

0 comments on commit 766e5c3

Please sign in to comment.