Skip to content

Commit

Permalink
chore: Unbreak release (#1591)
Browse files Browse the repository at this point in the history
Replaces the breaking changes introduced in #1587 with non-breaking
deprecations.
We should be able to remove these on the next breaking release.
  • Loading branch information
aborgna-q authored Oct 21, 2024
1 parent d349eee commit 45c3106
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 2 deletions.
7 changes: 7 additions & 0 deletions hugr-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
15 changes: 15 additions & 0 deletions hugr-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -126,4 +128,17 @@ impl HugrArgs {
let pkg = serde_json::from_value::<Package>(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<Package, CliError> {
let val: serde_json::Value = serde_json::from_reader(&mut self.input)?;
let pkg = serde_json::from_value::<Package>(val.clone())?;
Ok(pkg)
}
}
8 changes: 8 additions & 0 deletions hugr-cli/src/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
62 changes: 61 additions & 1 deletion hugr-core/src/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<Hugr>, 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].
Expand Down Expand Up @@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion release-please-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@
"hidden": true
}
]
}
}

0 comments on commit 45c3106

Please sign in to comment.