diff --git a/Cargo.lock b/Cargo.lock index 75b9b12..d21179c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -572,7 +572,7 @@ dependencies = [ [[package]] name = "pyo3_bindgen" -version = "0.1.0" +version = "0.1.1" dependencies = [ "pyo3_bindgen_engine", "pyo3_bindgen_macros", @@ -580,7 +580,7 @@ dependencies = [ [[package]] name = "pyo3_bindgen_cli" -version = "0.1.0" +version = "0.1.1" dependencies = [ "assert_cmd", "clap", @@ -592,7 +592,7 @@ dependencies = [ [[package]] name = "pyo3_bindgen_engine" -version = "0.1.0" +version = "0.1.1" dependencies = [ "criterion", "indoc", @@ -607,7 +607,7 @@ dependencies = [ [[package]] name = "pyo3_bindgen_macros" -version = "0.1.0" +version = "0.1.1" dependencies = [ "proc-macro2", "pyo3", diff --git a/Cargo.toml b/Cargo.toml index 6368a3b..bc13643 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,12 +20,12 @@ license = "MIT OR Apache-2.0" readme = "README.md" repository = "https://github.com/AndrejOrsula/pyo3_bindgen" rust-version = "1.70" -version = "0.1.0" +version = "0.1.1" [workspace.dependencies] -pyo3_bindgen = { path = "pyo3_bindgen", version = "0.1.0" } -pyo3_bindgen_engine = { path = "pyo3_bindgen_engine", version = "0.1.0" } -pyo3_bindgen_macros = { path = "pyo3_bindgen_macros", version = "0.1.0" } +pyo3_bindgen = { path = "pyo3_bindgen", version = "0.1.1" } +pyo3_bindgen_engine = { path = "pyo3_bindgen_engine", version = "0.1.1" } +pyo3_bindgen_macros = { path = "pyo3_bindgen_macros", version = "0.1.1" } assert_cmd = { version = "2" } clap = { version = "4.4", features = ["derive"] } diff --git a/README.md b/README.md index 682646d..da3b342 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,11 @@ # pyo3_bindgen
Automatic generation of Rust FFI bindings to Python modules via [PyO3](https://pyo3.rs). Python modules are analyzed recursively to generate Rust bindings with an identical structure for all public classes, functions, properties, and constants. Any available docstrings and type annotations are also preserved in their Rust equivalents. @@ -76,7 +78,7 @@ On its own, the generated Rust code does not provide any performance benefits ov The workspace contains these packages: -- **[pyo3_bindgen](pyo3_bindgen):** Public API for generation of bindings (in `build.rs` scripts or via procedural macros if enabled) +- **[pyo3_bindgen](pyo3_bindgen):** Public API for generation of bindings (in `build.rs` or via procedural macros) - **[pyo3_bindgen_cli](pyo3_bindgen_cli):** CLI tool for generation of bindings via `pyo3_bindgen` executable - **[pyo3_bindgen_engine](pyo3_bindgen_engine):** The underlying engine for generation of bindings - **[pyo3_bindgen_macros](pyo3_bindgen_macros):** \[Experimental\] Procedural macros for in-place generation @@ -113,7 +115,12 @@ fn main() { Afterwards, include the generated bindings anywhere in your crate. ```rs -#[allow(non_camel_case_types, non_snake_case, non_upper_case_globals)] +#[allow( + clippy::all, + non_camel_case_types, + non_snake_case, + non_upper_case_globals +)] pub mod target_module { include!(concat!(env!("OUT_DIR"), "/bindings.rs")); } @@ -148,8 +155,13 @@ pyo3_bindgen = { version = "0.1", features = ["macros"] } Then, you can call the `import_python!` macro anywhere in your crate. ```rs -#[allow(non_camel_case_types, non_snake_case, non_upper_case_globals)] -pub(crate) mod target_module { +#[allow( + clippy::all, + non_camel_case_types, + non_snake_case, + non_upper_case_globals +)] +pub mod target_module { pyo3_bindgen::import_python!("target_module"); } ``` diff --git a/pyo3_bindgen/src/lib.rs b/pyo3_bindgen/src/lib.rs index 19d8b7c..ac8e676 100644 --- a/pyo3_bindgen/src/lib.rs +++ b/pyo3_bindgen/src/lib.rs @@ -32,7 +32,12 @@ //! Afterwards, include the generated bindings anywhere in your crate. //! //! ```rs -//! #[allow(non_camel_case_types, non_snake_case, non_upper_case_globals)] +//! #[allow( +//! clippy::all, +//! non_camel_case_types, +//! non_snake_case, +//! non_upper_case_globals +//! )] //! pub mod target_module { //! include!(concat!(env!("OUT_DIR"), "/bindings.rs")); //! } @@ -67,8 +72,13 @@ //! Then, you can call the `import_python!` macro anywhere in your crate. //! //! ```rs -//! #[allow(non_camel_case_types, non_snake_case, non_upper_case_globals)] -//! pub(crate) mod target_module { +//! #[allow( +//! clippy::all, +//! non_camel_case_types, +//! non_snake_case, +//! non_upper_case_globals +//! )] +//! pub mod target_module { //! pyo3_bindgen::import_python!("target_module"); //! } //! ``` diff --git a/pyo3_bindgen_engine/src/bindgen/module.rs b/pyo3_bindgen_engine/src/bindgen/module.rs index f5f1c1c..fca4c8c 100644 --- a/pyo3_bindgen_engine/src/bindgen/module.rs +++ b/pyo3_bindgen_engine/src/bindgen/module.rs @@ -242,8 +242,12 @@ pub fn bind_reexport( .take_while(|(a, b)| a == b) .count(); let current_module_depth = module_name.split('.').count(); - let reexport_path: String = std::iter::repeat("super".to_string()) - .take(current_module_depth - n_common_ancestors) + let reexport_path = if (current_module_depth - n_common_ancestors) > 0 { + std::iter::repeat("super".to_string()).take(current_module_depth - n_common_ancestors) + } else { + std::iter::repeat("self".to_string()).take(1) + }; + let reexport_path: String = reexport_path .chain( attr_origin_module .split('.') diff --git a/pyo3_bindgen_engine/src/build_utils.rs b/pyo3_bindgen_engine/src/build_utils.rs index 246c64b..a73814c 100644 --- a/pyo3_bindgen_engine/src/build_utils.rs +++ b/pyo3_bindgen_engine/src/build_utils.rs @@ -36,7 +36,12 @@ /// ```ignore /// // src/lib.rs /// -/// #[allow(non_camel_case_types, non_snake_case, non_upper_case_globals)] +/// #[allow( +/// clippy::all, +/// non_camel_case_types, +/// non_snake_case, +/// non_upper_case_globals +/// )] /// pub mod os { /// include!(concat!(env!("OUT_DIR"), "/bindings.rs")); /// } diff --git a/pyo3_bindgen_macros/src/lib.rs b/pyo3_bindgen_macros/src/lib.rs index 280e5f2..61bd26f 100644 --- a/pyo3_bindgen_macros/src/lib.rs +++ b/pyo3_bindgen_macros/src/lib.rs @@ -14,12 +14,22 @@ mod parser; /// // use pyo3_bindgen::import_python; /// use pyo3_bindgen_macros::import_python; /// -/// #[allow(non_camel_case_types, non_snake_case, non_upper_case_globals)] +/// #[allow( +/// clippy::all, +/// non_camel_case_types, +/// non_snake_case, +/// non_upper_case_globals +/// )] /// pub mod sys { /// import_python!("sys"); /// } /// -/// #[allow(non_camel_case_types, non_snake_case, non_upper_case_globals)] +/// #[allow( +/// clippy::all, +/// non_camel_case_types, +/// non_snake_case, +/// non_upper_case_globals +/// )] /// pub(crate) mod os_path { /// import_python!("os.path"); /// }