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

Development towards 0.1.1 #1

Merged
merged 5 commits into from
Jan 20, 2024
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
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
26 changes: 19 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# pyo3_bindgen

<p align="left">
<a href="https://crates.io/crates/pyo3_bindgen"> <img alt="crates.io" src="https://img.shields.io/crates/v/pyo3_bindgen.svg"></a>
<a href="https://github.com/AndrejOrsula/pyo3_bindgen/actions/workflows/rust.yml"> <img alt="Rust" src="https://github.com/AndrejOrsula/pyo3_bindgen/actions/workflows/rust.yml/badge.svg"></a>
<a href="https://codecov.io/gh/AndrejOrsula/pyo3_bindgen"> <img alt="codecov" src="https://codecov.io/gh/AndrejOrsula/pyo3_bindgen/branch/main/graph/badge.svg"></a>
<a href="https://crates.io/crates/pyo3_bindgen"> <img alt="crates.io" src="https://img.shields.io/crates/v/pyo3_bindgen.svg"></a>
<a href="https://docs.rs/pyo3_bindgen"> <img alt="docs.rs" src="https://docs.rs/pyo3_bindgen/badge.svg"></a>
<a href="https://github.com/AndrejOrsula/pyo3_bindgen/actions/workflows/rust.yml"> <img alt="Rust" src="https://github.com/AndrejOrsula/pyo3_bindgen/actions/workflows/rust.yml/badge.svg"></a>
<a href="https://deps.rs/repo/github/AndrejOrsula/pyo3_bindgen"> <img alt="deps.rs" src="https://deps.rs/repo/github/AndrejOrsula/pyo3_bindgen/status.svg"></a>
<a href="https://codecov.io/gh/AndrejOrsula/pyo3_bindgen"> <img alt="codecov.io" src="https://codecov.io/gh/AndrejOrsula/pyo3_bindgen/branch/main/graph/badge.svg"></a>
</p>

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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"));
}
Expand Down Expand Up @@ -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");
}
```
Expand Down
16 changes: 13 additions & 3 deletions pyo3_bindgen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
//! }
Expand Down Expand Up @@ -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");
//! }
//! ```
Expand Down
8 changes: 6 additions & 2 deletions pyo3_bindgen_engine/src/bindgen/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,12 @@
.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)

Check warning on line 246 in pyo3_bindgen_engine/src/bindgen/module.rs

View check run for this annotation

Codecov / codecov/patch

pyo3_bindgen_engine/src/bindgen/module.rs#L245-L246

Added lines #L245 - L246 were not covered by tests
} else {
std::iter::repeat("self".to_string()).take(1)

Check warning on line 248 in pyo3_bindgen_engine/src/bindgen/module.rs

View check run for this annotation

Codecov / codecov/patch

pyo3_bindgen_engine/src/bindgen/module.rs#L248

Added line #L248 was not covered by tests
};
let reexport_path: String = reexport_path

Check warning on line 250 in pyo3_bindgen_engine/src/bindgen/module.rs

View check run for this annotation

Codecov / codecov/patch

pyo3_bindgen_engine/src/bindgen/module.rs#L250

Added line #L250 was not covered by tests
.chain(
attr_origin_module
.split('.')
Expand Down
7 changes: 6 additions & 1 deletion pyo3_bindgen_engine/src/build_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
/// }
Expand Down
14 changes: 12 additions & 2 deletions pyo3_bindgen_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
/// }
Expand Down