Merge pull request #897 from fusion-engineering-forks/macros-feature
Move macros into separate feature.
This commit is contained in:
commit
da22eecb5f
|
@ -28,7 +28,9 @@ jobs:
|
||||||
toolchain: nightly
|
toolchain: nightly
|
||||||
default: true
|
default: true
|
||||||
- run: rustup set default-host ${{ matrix.platform.rust-target }}
|
- run: rustup set default-host ${{ matrix.platform.rust-target }}
|
||||||
- name: Build
|
- name: Build without default features
|
||||||
|
run: cargo build --no-default-features --verbose
|
||||||
|
- name: Build with default features
|
||||||
run: cargo build --verbose
|
run: cargo build --verbose
|
||||||
- name: Install test dependencies
|
- name: Install test dependencies
|
||||||
run: |
|
run: |
|
||||||
|
|
13
Cargo.toml
13
Cargo.toml
|
@ -19,14 +19,14 @@ travis-ci = { repository = "PyO3/pyo3", branch = "master" }
|
||||||
appveyor = { repository = "fafhrd91/pyo3" }
|
appveyor = { repository = "fafhrd91/pyo3" }
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
indoc = "0.3.4"
|
indoc = { version = "0.3.4", optional = true }
|
||||||
inventory = "0.1.4"
|
inventory = { version = "0.1.4", optional = true }
|
||||||
libc = "0.2.62"
|
libc = "0.2.62"
|
||||||
num-bigint = { version = "0.2", optional = true }
|
num-bigint = { version = "0.2", optional = true }
|
||||||
num-complex = { version = "0.2", optional = true }
|
num-complex = { version = "0.2", optional = true }
|
||||||
paste = "0.1.6"
|
paste = { version = "0.1.6", optional = true }
|
||||||
pyo3cls = { path = "pyo3cls", version = "=0.9.2" }
|
pyo3cls = { path = "pyo3cls", version = "=0.9.2", optional = true }
|
||||||
unindent = "0.1.4"
|
unindent = { version = "0.1.4", optional = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
assert_approx_eq = "1.1.0"
|
assert_approx_eq = "1.1.0"
|
||||||
|
@ -36,7 +36,8 @@ trybuild = "1.0.23"
|
||||||
version_check = "0.9.1"
|
version_check = "0.9.1"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = []
|
default = ["macros"]
|
||||||
|
macros = ["indoc", "inventory", "paste", "pyo3cls", "unindent"]
|
||||||
|
|
||||||
# this is no longer needed internally, but setuptools-rust assumes this feature
|
# this is no longer needed internally, but setuptools-rust assumes this feature
|
||||||
python3 = []
|
python3 = []
|
||||||
|
|
|
@ -138,6 +138,7 @@ impl PySetterDef {
|
||||||
/// Allows arbitrary pymethod blocks to submit their methods, which are eventually
|
/// Allows arbitrary pymethod blocks to submit their methods, which are eventually
|
||||||
/// collected by pyclass.
|
/// collected by pyclass.
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
|
#[cfg(feature = "macros")]
|
||||||
pub trait PyMethodsInventory: inventory::Collect {
|
pub trait PyMethodsInventory: inventory::Collect {
|
||||||
/// Create a new instance
|
/// Create a new instance
|
||||||
fn new(methods: &'static [PyMethodDefType]) -> Self;
|
fn new(methods: &'static [PyMethodDefType]) -> Self;
|
||||||
|
@ -149,6 +150,7 @@ pub trait PyMethodsInventory: inventory::Collect {
|
||||||
/// Implementation detail. Only to be used through the proc macros.
|
/// Implementation detail. Only to be used through the proc macros.
|
||||||
/// For pyclass derived structs, this trait collects method from all impl blocks using inventory.
|
/// For pyclass derived structs, this trait collects method from all impl blocks using inventory.
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
|
#[cfg(feature = "macros")]
|
||||||
pub trait PyMethodsImpl {
|
pub trait PyMethodsImpl {
|
||||||
/// Normal methods. Mainly defined by `#[pymethod]`.
|
/// Normal methods. Mainly defined by `#[pymethod]`.
|
||||||
type Methods: PyMethodsInventory;
|
type Methods: PyMethodsInventory;
|
||||||
|
@ -161,3 +163,11 @@ pub trait PyMethodsImpl {
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[doc(hidden)]
|
||||||
|
#[cfg(not(feature = "macros"))]
|
||||||
|
pub trait PyMethodsImpl {
|
||||||
|
fn py_methods() -> Vec<&'static PyMethodDefType> {
|
||||||
|
Vec::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
22
src/lib.rs
22
src/lib.rs
|
@ -150,21 +150,18 @@ pub use crate::type_object::{type_flags, PyTypeInfo};
|
||||||
// Since PyAny is as important as PyObject, we expose it to the top level.
|
// Since PyAny is as important as PyObject, we expose it to the top level.
|
||||||
pub use crate::types::PyAny;
|
pub use crate::types::PyAny;
|
||||||
|
|
||||||
// Re-exported for wrap_function
|
#[cfg(feature = "macros")]
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub use paste;
|
pub use {
|
||||||
// Re-exported for py_run
|
indoc, // Re-exported for py_run
|
||||||
#[doc(hidden)]
|
inventory, // Re-exported for pymethods
|
||||||
pub use indoc;
|
paste, // Re-exported for wrap_function
|
||||||
// Re-exported for pymethods
|
unindent, // Re-exported for py_run
|
||||||
#[doc(hidden)]
|
};
|
||||||
pub use inventory;
|
|
||||||
// Re-exported for the `__wrap` functions
|
// Re-exported for the `__wrap` functions
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub use libc;
|
pub use libc;
|
||||||
// Re-exported for py_run
|
|
||||||
#[doc(hidden)]
|
|
||||||
pub use unindent;
|
|
||||||
|
|
||||||
pub mod buffer;
|
pub mod buffer;
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
|
@ -197,6 +194,7 @@ pub mod type_object;
|
||||||
pub mod types;
|
pub mod types;
|
||||||
|
|
||||||
/// The proc macros, which are also part of the prelude.
|
/// The proc macros, which are also part of the prelude.
|
||||||
|
#[cfg(feature = "macros")]
|
||||||
pub mod proc_macro {
|
pub mod proc_macro {
|
||||||
pub use pyo3cls::pymodule;
|
pub use pyo3cls::pymodule;
|
||||||
/// The proc macro attributes
|
/// The proc macro attributes
|
||||||
|
@ -278,6 +276,7 @@ macro_rules! wrap_pymodule {
|
||||||
/// If you need to handle failures, please use [Python::run] directly.
|
/// If you need to handle failures, please use [Python::run] directly.
|
||||||
///
|
///
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
|
#[cfg(feature = "macros")]
|
||||||
macro_rules! py_run {
|
macro_rules! py_run {
|
||||||
($py:expr, $($val:ident)+, $code:literal) => {{
|
($py:expr, $($val:ident)+, $code:literal) => {{
|
||||||
pyo3::py_run_impl!($py, $($val)+, pyo3::indoc::indoc!($code))
|
pyo3::py_run_impl!($py, $($val)+, pyo3::indoc::indoc!($code))
|
||||||
|
@ -289,6 +288,7 @@ macro_rules! py_run {
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
|
#[cfg(feature = "macros")]
|
||||||
macro_rules! py_run_impl {
|
macro_rules! py_run_impl {
|
||||||
($py:expr, $($val:ident)+, $code:expr) => {{
|
($py:expr, $($val:ident)+, $code:expr) => {{
|
||||||
use pyo3::types::IntoPyDict;
|
use pyo3::types::IntoPyDict;
|
||||||
|
|
|
@ -20,5 +20,5 @@ pub use crate::python::Python;
|
||||||
pub use crate::{FromPy, FromPyObject, IntoPy, IntoPyPointer, PyTryFrom, PyTryInto, ToPyObject};
|
pub use crate::{FromPy, FromPyObject, IntoPy, IntoPyPointer, PyTryFrom, PyTryInto, ToPyObject};
|
||||||
// PyModule is only part of the prelude because we need it for the pymodule function
|
// PyModule is only part of the prelude because we need it for the pymodule function
|
||||||
pub use crate::types::{PyAny, PyModule};
|
pub use crate::types::{PyAny, PyModule};
|
||||||
pub use pyo3cls::pymodule;
|
#[cfg(feature = "macros")]
|
||||||
pub use pyo3cls::{pyclass, pyfunction, pymethods, pyproto};
|
pub use pyo3cls::{pyclass, pyfunction, pymethods, pymodule, pyproto};
|
||||||
|
|
Loading…
Reference in New Issue