-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Build docs.rs documentation with all features enabled Signed-off-by: Andrej Orsula <[email protected]> * Make Config fields public Signed-off-by: Andrej Orsula <[email protected]> * Bump to 0.4.0 Signed-off-by: Andrej Orsula <[email protected]> * Reenable non-proc macro doc tests Signed-off-by: Andrej Orsula <[email protected]> * Rearrange instructions Signed-off-by: Andrej Orsula <[email protected]> * Fix instructions for `macros` feature Signed-off-by: Andrej Orsula <[email protected]> * Add "py" to forbidden function/type names Signed-off-by: Andrej Orsula <[email protected]> * Disable some debug asserts due to the uncertainty of Python code Signed-off-by: Andrej Orsula <[email protected]> * Improve error handling in `Codegen::generate()` Signed-off-by: Andrej Orsula <[email protected]> * Make kwargs optional Signed-off-by: Andrej Orsula <[email protected]> * Reenable support for generating bindings to builtin functions Signed-off-by: Andrej Orsula <[email protected]> * Improve docstring processing Signed-off-by: Andrej Orsula <[email protected]> * Make Codegen API more ergonomic Signed-off-by: Andrej Orsula <[email protected]> * Re-export `pyo3` directly from `pyo3_bindgen` Signed-off-by: Andrej Orsula <[email protected]> * Fix loading of libpython symbols in `import_python!` procedural macro Signed-off-by: Andrej Orsula <[email protected]> * Add "macros" to default features Signed-off-by: Andrej Orsula <[email protected]> * Update documentation Signed-off-by: Andrej Orsula <[email protected]> * Add examples Signed-off-by: Andrej Orsula <[email protected]> * Disable `pygal` example Signed-off-by: Andrej Orsula <[email protected]> * Slightly simplify README example Signed-off-by: Andrej Orsula <[email protected]> * Update information about `pyo3_bindgen_macros` Signed-off-by: Andrej Orsula <[email protected]> * Update documentation Signed-off-by: Andrej Orsula <[email protected]> * Fix TOML formatting Signed-off-by: Andrej Orsula <[email protected]> --------- Signed-off-by: Andrej Orsula <[email protected]>
- Loading branch information
1 parent
73556cc
commit 3817fc7
Showing
30 changed files
with
542 additions
and
189 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
[package] | ||
name = "examples" | ||
authors.workspace = true | ||
edition.workspace = true | ||
license.workspace = true | ||
rust-version.workspace = true | ||
version.workspace = true | ||
publish = false | ||
|
||
[dependencies] | ||
pyo3 = { workspace = true, features = ["auto-initialize"] } | ||
pyo3_bindgen = { workspace = true } | ||
|
||
[build-dependencies] | ||
pyo3_bindgen = { workspace = true } | ||
|
||
[[example]] | ||
name = "math" | ||
path = "math.rs" | ||
|
||
[[example]] | ||
name = "os_sys" | ||
path = "os_sys.rs" | ||
|
||
# [[example]] | ||
# name = "pygal" | ||
# path = "pygal.rs" | ||
|
||
[[example]] | ||
name = "random" | ||
path = "random.rs" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
use pyo3_bindgen::Codegen; | ||
|
||
fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
Codegen::default() | ||
.module_names(["os", "posixpath", "sys"])? | ||
.build(format!("{}/bindings.rs", std::env::var("OUT_DIR")?))?; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
//! Example demonstrating the use of the `import_python!` macro for the "math" module. | ||
//! | ||
//! Python equivalent: | ||
//! | ||
//! ```py | ||
//! import math | ||
//! | ||
//! python_pi = math.pi | ||
//! assert python_pi == 3.141592653589793 | ||
//! print(f"Python Pi: {python_pi}") | ||
//! ``` | ||
pyo3_bindgen::import_python!("math"); | ||
|
||
fn main() { | ||
// Which Pi do you prefer? | ||
// a) 🐍 Pi from Python "math" module | ||
// b) 🦀 Pi from Rust standard library | ||
// c) 🥧 Pi from your favorite bakery | ||
pyo3::Python::with_gil(|py| { | ||
let python_pi = math::pi(py).unwrap(); | ||
let rust_pi = std::f64::consts::PI; | ||
assert_eq!(python_pi, rust_pi); | ||
println!("Python Pi: {}", python_pi); | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
//! Example demonstrating the use of the `pyo3_bindgen` crate via build script for | ||
//! the "os", "posixpath", and "sys" Python modules. | ||
//! | ||
//! See `build.rs` for more details about the generation. | ||
//! | ||
//! Python equivalent: | ||
//! | ||
//! ```py | ||
//! import os | ||
//! import posixpath | ||
//! import sys | ||
//! | ||
//! python_exe_path = sys.executable | ||
//! current_dir = os.getcwd() | ||
//! relpath_to_python_exe = posixpath.relpath(python_exe_path, current_dir) | ||
//! | ||
//! print(f"Relative path to Python executable: '{relpath_to_python_exe}'") | ||
//! ``` | ||
include!(concat!(env!("OUT_DIR"), "/bindings.rs")); | ||
|
||
fn main() -> pyo3::PyResult<()> { | ||
pyo3::Python::with_gil(|py| { | ||
// Get the path to the Python executable via "sys" Python module | ||
let python_exe_path = sys::executable(py)?; | ||
// Get the current working directory via "os" Python module | ||
let current_dir = os::getcwd(py)?; | ||
// Get the relative path to the Python executable via "posixpath" Python module | ||
let relpath_to_python_exe = posixpath::relpath(py, python_exe_path, current_dir)?; | ||
|
||
println!("Relative path to Python executable: '{relpath_to_python_exe}'"); | ||
Ok(()) | ||
}) | ||
} |
Oops, something went wrong.