diff --git a/hugr-cli/Cargo.toml b/hugr-cli/Cargo.toml index a517d8f48..976bcdb2f 100644 --- a/hugr-cli/Cargo.toml +++ b/hugr-cli/Cargo.toml @@ -25,6 +25,13 @@ clio = { workspace = true, features = ["clap-parse"] } [lints] workspace = true +[package.metadata.cargo-semver-checks.lints] +workspace = true +# Temporarily disabled due to Package being moved to `hugr-core` triggering an error in rustdoc +# https://github.com/obi1kenobi/cargo-semver-checks/issues/355 +enum_missing = "warn" +struct_missing = "warn" + [dev-dependencies] assert_cmd = { workspace = true } assert_fs = { workspace = true } diff --git a/hugr-cli/src/lib.rs b/hugr-cli/src/lib.rs index 41db94653..24cc40e2b 100644 --- a/hugr-cli/src/lib.rs +++ b/hugr-cli/src/lib.rs @@ -14,6 +14,8 @@ pub mod mermaid; pub mod validate; // TODO: Deprecated re-export. Remove on a breaking release. +#[doc(inline)] +#[deprecated(since = "0.13.2", note = "Use `hugr::package::Package` instead.")] pub use hugr::package::Package; /// CLI arguments. @@ -126,4 +128,17 @@ impl HugrArgs { let pkg = serde_json::from_value::(val.clone())?; Ok(PackageOrHugr::Package(pkg)) } + + /// Read either a package from the input. + /// + /// deprecated: use [HugrArgs::get_package_or_hugr] instead. + #[deprecated( + since = "0.13.2", + note = "Use `HugrArgs::get_package_or_hugr` instead." + )] + pub fn get_package(&mut self) -> Result { + let val: serde_json::Value = serde_json::from_reader(&mut self.input)?; + let pkg = serde_json::from_value::(val.clone())?; + Ok(pkg) + } } diff --git a/hugr-cli/src/validate.rs b/hugr-cli/src/validate.rs index eaf3bfccd..996799b77 100644 --- a/hugr-cli/src/validate.rs +++ b/hugr-cli/src/validate.rs @@ -7,6 +7,14 @@ use hugr::{extension::ExtensionRegistry, Extension, Hugr}; use crate::{CliError, HugrArgs}; +// TODO: Deprecated re-export. Remove on a breaking release. +#[doc(inline)] +#[deprecated( + since = "0.13.2", + note = "Use `hugr::package::PackageValidationError` instead." +)] +pub use hugr::package::PackageValidationError as ValError; + /// Validate and visualise a HUGR file. #[derive(Parser, Debug)] #[clap(version = "1.0", long_about = None)] diff --git a/hugr-core/src/package.rs b/hugr-core/src/package.rs index 7dd10010b..586d31c3e 100644 --- a/hugr-core/src/package.rs +++ b/hugr-core/src/package.rs @@ -106,6 +106,22 @@ impl Package { Ok(()) } + /// Validate the package against an extension registry. + /// + /// `reg` is updated with any new extensions. + /// + /// Returns the validated modules. + /// + /// deprecated: use [Package::update_validate] instead. + #[deprecated(since = "0.13.2", note = "Replaced by `Package::update_validate`")] + pub fn validate( + mut self, + reg: &mut ExtensionRegistry, + ) -> Result, PackageValidationError> { + self.update_validate(reg)?; + Ok(self.modules) + } + /// Read a Package in json format from an io reader. /// /// If the json encodes a single [Hugr] instead, it will be inserted in a new [Package]. @@ -259,13 +275,57 @@ pub enum PackageEncodingError { } /// Error raised while validating a package. -#[derive(Debug, Display, Error, From)] +#[derive(Debug, From)] #[non_exhaustive] pub enum PackageValidationError { /// Error raised while processing the package extensions. Extension(ExtensionRegistryError), /// Error raised while validating the package hugrs. Validation(ValidationError), + /// Error validating HUGR. + // TODO: Remove manual Display and Error impls when removing deprecated variants. + #[from(ignore)] + #[deprecated( + since = "0.13.2", + note = "Replaced by `PackageValidationError::Validation`" + )] + Validate(ValidationError), + /// Error registering extension. + // TODO: Remove manual Display and Error impls when removing deprecated variants. + #[from(ignore)] + #[deprecated( + since = "0.13.2", + note = "Replaced by `PackageValidationError::Extension`" + )] + ExtReg(ExtensionRegistryError), +} + +// Note: We cannot use the `derive_more::Error` derive due to a bug with deprecated elements. +// See https://github.com/JelteF/derive_more/issues/419 +#[allow(deprecated)] +impl std::error::Error for PackageValidationError { + fn source(&self) -> Option<&(dyn derive_more::Error + 'static)> { + match self { + PackageValidationError::Extension(source) => Some(source), + PackageValidationError::Validation(source) => Some(source), + PackageValidationError::Validate(source) => Some(source), + PackageValidationError::ExtReg(source) => Some(source), + } + } +} + +// Note: We cannot use the `derive_more::Display` derive due to a bug with deprecated elements. +// See https://github.com/JelteF/derive_more/issues/419 +impl Display for PackageValidationError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + #[allow(deprecated)] + match self { + PackageValidationError::Extension(e) => write!(f, "Error processing extensions: {}", e), + PackageValidationError::Validation(e) => write!(f, "Error validating HUGR: {}", e), + PackageValidationError::Validate(e) => write!(f, "Error validating HUGR: {}", e), + PackageValidationError::ExtReg(e) => write!(f, "Error registering extension: {}", e), + } + } } #[cfg(test)] diff --git a/release-please-config.json b/release-please-config.json index 54e6bdf7b..7cbb53196 100644 --- a/release-please-config.json +++ b/release-please-config.json @@ -63,4 +63,4 @@ "hidden": true } ] -} \ No newline at end of file +}