From 766e5c3257fa30b8b378222ace84816e1a6028b8 Mon Sep 17 00:00:00 2001 From: Seyon Sivarajah Date: Tue, 28 May 2024 15:44:26 +0100 Subject: [PATCH] feat!: move cli in to hugr-cli sub-crate (#1107) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BREAKING CHANGE: cli library no longer available from `hugr::cli` --------- Co-authored-by: Agustín Borgna <121866228+aborgna-q@users.noreply.github.com> --- Cargo.toml | 13 +++---- hugr-cli/CHANGELOG.md | 5 +++ hugr-cli/Cargo.toml | 30 ++++++++++++++ hugr-cli/README.md | 43 +++++++++++++++++++++ hugr-core/src/cli.rs => hugr-cli/src/lib.rs | 6 +-- hugr-core/Cargo.toml | 7 +--- hugr-core/src/lib.rs | 3 -- hugr-passes/Cargo.toml | 2 +- hugr/Cargo.toml | 11 +++--- hugr/src/main.rs | 3 +- hugr/tests/cli.rs | 8 ++-- release-plz.toml | 8 ++++ 12 files changed, 107 insertions(+), 32 deletions(-) create mode 100644 hugr-cli/CHANGELOG.md create mode 100644 hugr-cli/Cargo.toml create mode 100644 hugr-cli/README.md rename hugr-core/src/cli.rs => hugr-cli/src/lib.rs (91%) diff --git a/Cargo.toml b/Cargo.toml index a1ff18b5e..54fed82da 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" @@ -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" @@ -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" @@ -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 diff --git a/hugr-cli/CHANGELOG.md b/hugr-cli/CHANGELOG.md new file mode 100644 index 000000000..38ec96fd2 --- /dev/null +++ b/hugr-cli/CHANGELOG.md @@ -0,0 +1,5 @@ +# Changelog + +## 0.1.0 (2024-05-24) + +Initial release, ported from `hugr::cli` module. diff --git a/hugr-cli/Cargo.toml b/hugr-cli/Cargo.toml new file mode 100644 index 000000000..067a08a67 --- /dev/null +++ b/hugr-cli/Cargo.toml @@ -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 diff --git a/hugr-cli/README.md b/hugr-cli/README.md new file mode 100644 index 000000000..1c08dcac8 --- /dev/null +++ b/hugr-cli/README.md @@ -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 diff --git a/hugr-core/src/cli.rs b/hugr-cli/src/lib.rs similarity index 91% rename from hugr-core/src/cli.rs rename to hugr-cli/src/lib.rs index a58278188..421a900fa 100644 --- a/hugr-core/src/cli.rs +++ b/hugr-cli/src/lib.rs @@ -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)] @@ -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. diff --git a/hugr-core/Cargo.toml b/hugr-core/Cargo.toml index 5894ef984..41e411dcb 100644 --- a/hugr-core/Cargo.toml +++ b/hugr-core/Cargo.toml @@ -18,7 +18,6 @@ workspace = true [features] extension_inference = [] -cli = ["dep:clap", "dep:clap-stdin"] [dependencies] portgraph = { workspace = true, features = ["serde", "petgraph"] } @@ -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 } @@ -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" } diff --git a/hugr-core/src/lib.rs b/hugr-core/src/lib.rs index a0c7b95ba..6bd2a262d 100644 --- a/hugr-core/src/lib.rs +++ b/hugr-core/src/lib.rs @@ -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; diff --git a/hugr-passes/Cargo.toml b/hugr-passes/Cargo.toml index 4a1bdc680..09cc231a4 100644 --- a/hugr-passes/Cargo.toml +++ b/hugr-passes/Cargo.toml @@ -23,4 +23,4 @@ thiserror = { workspace = true } extension_inference = ["hugr-core/extension_inference"] [dev-dependencies] -rstest = "0.19.0" +rstest = { workspace = true } diff --git a/hugr/Cargo.toml b/hugr/Cargo.toml index 59d468014..aa5e33b3e 100644 --- a/hugr/Cargo.toml +++ b/hugr/Cargo.toml @@ -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" diff --git a/hugr/src/main.rs b/hugr/src/main.rs index 4c2e163ac..a1bf109f4 100644 --- a/hugr/src/main.rs +++ b/hugr/src/main.rs @@ -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(); diff --git a/hugr/tests/cli.rs b/hugr/tests/cli.rs index 2da86bc32..99ced61a4 100644 --- a/hugr/tests/cli.rs +++ b/hugr/tests/cli.rs @@ -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] diff --git a/release-plz.toml b/release-plz.toml index 9683d768b..5b3c4ee9f 100644 --- a/release-plz.toml +++ b/release-plz.toml @@ -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