Skip to content

Commit

Permalink
Development towards 0.1.1 (#1)
Browse files Browse the repository at this point in the history
* Simplify documentation

Signed-off-by: Andrej Orsula <[email protected]>

* Update badges

Signed-off-by: Andrej Orsula <[email protected]>

* Suggest using `#[allow(clippy::all)]` for bindings

Signed-off-by: Andrej Orsula <[email protected]>

* Make reexports unambiguous

Signed-off-by: Andrej Orsula <[email protected]>

* Bump to 0.1.1

Signed-off-by: Andrej Orsula <[email protected]>

---------

Signed-off-by: Andrej Orsula <[email protected]>
  • Loading branch information
AndrejOrsula authored Jan 20, 2024
1 parent 399262e commit 1286e28
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 23 deletions.
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 @@ 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('.')
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

0 comments on commit 1286e28

Please sign in to comment.