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!: Drop the pyo3 feature #717

Merged
merged 1 commit into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ path = "src/lib.rs"
[dependencies]
thiserror = "1.0.28"
portgraph = { version = "0.10.0", features = ["serde", "petgraph"] }
pyo3 = { version = "0.20.0", optional = true, features = [
"multiple-pymethods",
] }
regex = "1.9.5"
cgmath = { version = "0.18.0", features = ["serde"] }
num-rational = { version = "0.4.1", features = ["serde"] }
Expand All @@ -53,9 +50,6 @@ delegate = "0.10.0"
rustversion = "1.0.14"
paste = "1.0"

[features]
pyo3 = ["dep:pyo3"]

[dev-dependencies]
criterion = { version = "0.5.1", features = ["html_reports"] }
rstest = "0.18.1"
Expand Down
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ compilation and encodes runnable programs.

The HUGR specification is [here](specification/hugr.md).

## Features

- `pyo3`: Enable Python bindings via pyo3.

## Usage

Add this to your `Cargo.toml`:
Expand Down
18 changes: 0 additions & 18 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
//!
use thiserror::Error;

#[cfg(feature = "pyo3")]
use pyo3::{create_exception, exceptions::PyException, PyErr};

use crate::extension::SignatureError;
use crate::hugr::{HugrError, ValidationError};
use crate::ops::handle::{BasicBlockID, CfgID, ConditionalID, DfgID, FuncID, TailLoopID};
Expand Down Expand Up @@ -84,21 +81,6 @@ pub enum BuildError {
CircuitError(#[from] circuit::CircuitBuildError),
}

#[cfg(feature = "pyo3")]
create_exception!(
pyrs,
PyBuildError,
PyException,
"Errors that can occur while building a Hugr"
);

#[cfg(feature = "pyo3")]
impl From<BuildError> for PyErr {
fn from(err: BuildError) -> Self {
PyBuildError::new_err(err.to_string())
}
}

#[cfg(test)]
pub(crate) mod test {
use rstest::fixture;
Expand Down
5 changes: 0 additions & 5 deletions src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,13 @@ pub use itertools::Either;
use derive_more::From;
use itertools::Either::{Left, Right};

#[cfg(feature = "pyo3")]
use pyo3::pyclass;

use crate::hugr::HugrError;

/// A handle to a node in the HUGR.
#[derive(
Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, From, serde::Serialize, serde::Deserialize,
)]
#[serde(transparent)]
#[cfg_attr(feature = "pyo3", pyclass)]
pub struct Node {
index: portgraph::NodeIndex,
}
Expand All @@ -37,7 +33,6 @@ pub struct Node {
serde::Deserialize,
)]
#[serde(transparent)]
#[cfg_attr(feature = "pyo3", pyclass)]
pub struct Port {
offset: portgraph::PortOffset,
}
Expand Down
19 changes: 0 additions & 19 deletions src/hugr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ use portgraph::multiportgraph::MultiPortGraph;
use portgraph::{Hierarchy, PortMut, UnmanagedDenseMap};
use thiserror::Error;

#[cfg(feature = "pyo3")]
use pyo3::{create_exception, exceptions::PyException, pyclass, PyErr};

pub use self::views::{HugrView, RootTagged};
use crate::core::NodeIndex;
use crate::extension::{
Expand All @@ -38,7 +35,6 @@ use delegate::delegate;

/// The Hugr data structure.
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "pyo3", pyclass)]
pub struct Hugr {
/// The graph encoding the adjacency structure of the HUGR.
graph: MultiPortGraph,
Expand Down Expand Up @@ -353,21 +349,6 @@ pub enum HugrError {
InvalidPortDirection(Direction),
}

#[cfg(feature = "pyo3")]
create_exception!(
pyrs,
PyHugrError,
PyException,
"Errors that can occur while manipulating a Hugr"
);

#[cfg(feature = "pyo3")]
impl From<HugrError> for PyErr {
fn from(err: HugrError) -> Self {
PyHugrError::new_err(err.to_string())
}
}

#[cfg(test)]
mod test {
use super::{Hugr, HugrView};
Expand Down
18 changes: 0 additions & 18 deletions src/hugr/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
use std::collections::HashMap;
use thiserror::Error;

#[cfg(feature = "pyo3")]
use pyo3::{create_exception, exceptions::PyException, PyErr};

use crate::core::NodeIndex;
use crate::extension::ExtensionSet;
use crate::hugr::{Hugr, NodeType};
Expand Down Expand Up @@ -91,21 +88,6 @@ pub enum HUGRSerializationError {
FirstNodeNotRoot(Node),
}

#[cfg(feature = "pyo3")]
create_exception!(
pyrs,
PyHUGRSerializationError,
PyException,
"Errors that can occur while serializing a Hugr"
);

#[cfg(feature = "pyo3")]
impl From<HUGRSerializationError> for PyErr {
fn from(err: HUGRSerializationError) -> Self {
PyHUGRSerializationError::new_err(err.to_string())
}
}

impl Serialize for Hugr {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
Expand Down
18 changes: 0 additions & 18 deletions src/hugr/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ use petgraph::visit::{Topo, Walker};
use portgraph::{LinkView, PortView};
use thiserror::Error;

#[cfg(feature = "pyo3")]
use pyo3::{create_exception, exceptions::PyException, PyErr};

use crate::extension::SignatureError;
use crate::extension::{
validate::{ExtensionError, ExtensionValidator},
Expand Down Expand Up @@ -716,21 +713,6 @@ pub enum ValidationError {
CustomOpError(#[from] CustomOpError),
}

#[cfg(feature = "pyo3")]
create_exception!(
pyrs,
PyValidationError,
PyException,
"Errors that can occur while validating a Hugr"
);

#[cfg(feature = "pyo3")]
impl From<ValidationError> for PyErr {
fn from(err: ValidationError) -> Self {
PyValidationError::new_err(err.to_string())
}
}

/// Errors related to the inter-graph edge validations.
#[derive(Debug, Clone, PartialEq, Error)]
#[allow(missing_docs)]
Expand Down
18 changes: 0 additions & 18 deletions src/hugr/views/sibling_subgraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ use crate::ops::{OpTag, OpTrait};
use crate::types::{FunctionType, Type};
use crate::{Hugr, IncomingPort, Node, OutgoingPort, Port, SimpleReplacement};

#[cfg(feature = "pyo3")]
use pyo3::{create_exception, exceptions::PyException, PyErr};

/// A non-empty convex subgraph of a HUGR sibling graph.
///
/// A HUGR region in which all nodes share the same parent. Unlike
Expand Down Expand Up @@ -635,21 +632,6 @@ pub enum InvalidReplacement {
NonConvexSubgraph,
}

#[cfg(feature = "pyo3")]
create_exception!(
pyrs,
PyInvalidReplacementError,
PyException,
"Errors that can occur while constructing a SimpleReplacement"
);

#[cfg(feature = "pyo3")]
impl From<InvalidReplacement> for PyErr {
fn from(err: InvalidReplacement) -> Self {
PyInvalidReplacementError::new_err(err.to_string())
}
}

/// Errors that can occur while constructing a [`SiblingSubgraph`].
#[derive(Debug, Clone, PartialEq, Eq, Error)]
pub enum InvalidSubgraph {
Expand Down
4 changes: 0 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,6 @@
//! println!("{}", serialized);
//! ```
//!
//! # Optional feature flags
//!
//! - `pyo3`: Enable Python bindings via [pyo3](https://docs.rs/pyo3).
//!

#![warn(missing_docs)]
// Unstable check, may cause false positives.
Expand Down
11 changes: 0 additions & 11 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ pub use signature::{FunctionType, Signature};
pub use type_param::TypeArg;
pub use type_row::TypeRow;

use derive_more::{From, Into};
use itertools::FoldWhile::{Continue, Done};
use itertools::Itertools;
use serde::{Deserialize, Serialize};
Expand All @@ -27,9 +26,6 @@ use std::fmt::Debug;

use self::type_param::TypeParam;

#[cfg(feature = "pyo3")]
use pyo3::pyclass;

/// The kinds of edges in a HUGR, excluding Hierarchy.
#[derive(Clone, PartialEq, Eq, Debug, serde::Serialize, serde::Deserialize)]
#[non_exhaustive]
Expand All @@ -51,12 +47,6 @@ impl EdgeKind {
}
}

/// Python representation for [`EdgeKind`], the kinds of edges in a HUGR.
#[cfg_attr(feature = "pyo3", pyclass)]
#[repr(transparent)]
#[derive(Clone, PartialEq, Eq, Debug, From, Into)]
pub struct PyEdgeKind(EdgeKind);

#[derive(
Copy, Default, Clone, PartialEq, Eq, Hash, Debug, derive_more::Display, Serialize, Deserialize,
)]
Expand Down Expand Up @@ -196,7 +186,6 @@ impl TypeEnum {
)]
#[display(fmt = "{}", "_0")]
#[serde(into = "serialize::SerSimpleType", from = "serialize::SerSimpleType")]
#[cfg_attr(feature = "pyo3", pyclass)]
/// A HUGR type - the valid types of [EdgeKind::Value] and [EdgeKind::Static] edges.
/// Such an edge is valid if the ports on either end agree on the [Type].
/// Types have an optional [TypeBound] which places limits on the valid
Expand Down
4 changes: 0 additions & 4 deletions src/types/signature.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
//! Abstract and concrete Signature types.

use itertools::Either;
#[cfg(feature = "pyo3")]
use pyo3::{pyclass, pymethods};

use delegate::delegate;
use std::fmt::{self, Display, Write};
Expand All @@ -13,7 +11,6 @@ use super::{subst_row, Substitution, Type, TypeRow};
use crate::extension::{ExtensionRegistry, ExtensionSet, SignatureError};
use crate::{Direction, IncomingPort, OutgoingPort, Port};

#[cfg_attr(feature = "pyo3", pyclass)]
#[derive(Clone, Debug, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
/// Describes the edges required to/from a node. This includes both the concept of "signature" in the spec,
/// and also the target (value) of a call (static).
Expand Down Expand Up @@ -91,7 +88,6 @@ impl Signature {
}
}

#[cfg_attr(feature = "pyo3", pymethods)]
impl FunctionType {
/// The number of wires in the signature.
#[inline(always)]
Expand Down
6 changes: 0 additions & 6 deletions src/types/type_row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,8 @@ use crate::utils::display_list;
use crate::PortIndex;
use delegate::delegate;

#[cfg(feature = "pyo3")]
use pyo3::pyclass;

/// List of types, used for function signatures.
#[derive(Clone, PartialEq, Eq, Debug, serde::Serialize, serde::Deserialize)]
#[cfg_attr(feature = "pyo3", pyclass)]
#[non_exhaustive]
#[serde(transparent)]
pub struct TypeRow {
Expand All @@ -33,8 +29,6 @@ impl Display for TypeRow {
}
}

// TODO some of these, but not all, will probably want exposing via
// pyo3 wrappers eventually.
impl TypeRow {
/// Create a new empty row.
pub const fn new() -> Self {
Expand Down