-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: support relative path dependencies from within crates too
refactor: refactored examples docs: updated README.md
- Loading branch information
mityax
committed
Feb 10, 2025
1 parent
b3a6c61
commit 056c43e
Showing
19 changed files
with
165 additions
and
74 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,12 +1,18 @@ | ||
// rustimport | ||
|
||
// Here, we use `rust-cpython` instead of pyO3: | ||
// - Notice how we do not have "rustimport:pyo3" in the first line of this | ||
// file (-> we don't activate the pyO3 template) | ||
// - Below, you find the full manifest (Cargo.toml) definition, which is usually | ||
// automatically defined by pyO3 | ||
|
||
//: [package] | ||
//: name = "doublecount" | ||
//: name = "cpython_doublecount" | ||
//: version = "0.1.0" | ||
//: authors = ["Bruno Rocha <[email protected]>"] | ||
//: | ||
//: [lib] | ||
//: name = "myrustlib" | ||
//: name = "cpython_doublecount" | ||
//: crate-type = ["cdylib"] | ||
//: | ||
//: [dependencies.cpython] | ||
|
@@ -34,7 +40,7 @@ fn count_doubles(_py: Python, val: &str) -> PyResult<u64> { | |
Ok(total) | ||
} | ||
|
||
py_module_initializer!(doublecount, |py, m | { | ||
py_module_initializer!(cpython_doublecount, |py, m | { | ||
m.add(py, "__doc__", "This module is implemented in Rust.")?; | ||
m.add(py, "count_doubles", py_fn!(py, count_doubles(val: &str)))?; | ||
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 @@ | ||
This is a marker-file to make this crate importable by rustimport. |
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,24 @@ | ||
[package] | ||
name = "crate_relative_path_dependency" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
|
||
# You can safely remove the code below to let rustimport define your pyo3 configuration | ||
# automatically. It's still possible to add other configuration or dependencies, or overwrite | ||
# specific parts here. rustimport will merge your Cargo.toml file into it's generated default | ||
# configuration. | ||
[lib] | ||
# The name of the native library. This is the name which will be used in Python to import the | ||
# library (i.e. `import crate_relative_path_dependency`). | ||
name = "crate_relative_path_dependency" | ||
|
||
# "cdylib" is necessary to produce a shared library for Python to import from. | ||
# Downstream Rust code (including code in `bin/`, `examples/`, and `examples/`) will not be able | ||
# to `use crate_relative_path_dependency;` unless the "rlib" or "lib" crate type is also included, e.g.: | ||
# crate-type = ["cdylib", "rlib"] | ||
crate-type = ["cdylib"] | ||
|
||
[dependencies] | ||
pyo3 = { version = "0.23.4", features = ["extension-module"] } | ||
test_crate = { path = "../test_crate" } |
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,18 @@ | ||
// rustimport:pyo3 | ||
|
||
// Instruct rustimport to track any changes in `test_crate` and rebuild this crate automatically: | ||
|
||
//d: ../../test_crate/**/*.rs | ||
//d: ../../test_crate/Cargo.toml | ||
|
||
use pyo3::prelude::*; | ||
use test_crate; | ||
|
||
|
||
#[pyfunction] | ||
fn say_hello() -> String { | ||
format!( | ||
"Hello from crate_relative_path_dependency, and also hello from test_crate: \"{}\"", | ||
test_crate::say_hello() | ||
) | ||
} |
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
File renamed without changes.
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
File renamed without changes.
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,27 @@ | ||
// rustimport:pyo3 | ||
|
||
// Below, we specify a dependency on a path relative to the current file. Since rustimport builds | ||
// your extensions in a temporary location, it will automatically rewrite this path and turn it | ||
// into an absolute one: | ||
|
||
//: [dependencies] | ||
//: test_crate = { path = "./test_crate" } | ||
|
||
// If you also want rustimport to automatically rebuild this extension when anything in `test_crate` | ||
// is changed, you can specify dependency paths like below: | ||
|
||
//d: ./test_crate/Cargo.toml | ||
//d: ./test_crate/**/*.rs | ||
|
||
|
||
|
||
use pyo3::prelude::*; | ||
use test_crate; | ||
|
||
#[pyfunction] | ||
fn say_hello() -> String { | ||
format!( | ||
"Hello from relative_path_dependency.rs, and also hello from test_crate: \"{}\"", | ||
test_crate::say_hello() | ||
) | ||
} |
This file was deleted.
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
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
Oops, something went wrong.