-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
93 additions
and
8 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
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,15 @@ | ||
[package] | ||
name = "pyo3-stub-gen-testing-mixed" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[lib] | ||
crate-type = ["cdylib", "rlib"] | ||
|
||
[dependencies] | ||
pyo3-stub-gen.workspace = true | ||
pyo3.workspace = true | ||
|
||
[[bin]] | ||
name = "stub_gen" | ||
doc = false |
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,10 @@ | ||
[build-system] | ||
requires = ["maturin>=1.1,<2.0"] | ||
build-backend = "maturin" | ||
|
||
[project] | ||
name = "pyo3_stub_gen_testing_mixed" | ||
requires-python = ">=3.9" | ||
|
||
[project.optional-dependencies] | ||
test = ["pytest", "pyright"] |
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,7 @@ | ||
use pyo3_stub_gen::Result; | ||
|
||
fn main() -> Result<()> { | ||
let stub = pyo3_stub_gen_testing_mixed::stub_info()?; | ||
stub.generate_single_stub_file(env!("CARGO_MANIFEST_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,32 @@ | ||
use pyo3::prelude::*; | ||
use pyo3_stub_gen::{derive::gen_stub_pyfunction, StubInfo}; | ||
use std::{env, path::*}; | ||
|
||
/// Gather information to generate stub files | ||
pub fn stub_info() -> pyo3_stub_gen::Result<StubInfo> { | ||
let manifest_dir: &Path = env!("CARGO_MANIFEST_DIR").as_ref(); | ||
StubInfo::from_pyproject_toml(manifest_dir.join("pyproject.toml")) | ||
} | ||
|
||
/// Returns the sum of two numbers as a string. | ||
#[gen_stub_pyfunction] | ||
#[pyfunction] | ||
fn sum_as_string(a: usize, b: usize) -> PyResult<String> { | ||
Ok((a + b).to_string()) | ||
} | ||
|
||
/// Initializes the Python module | ||
#[pymodule] | ||
fn pyo3_stub_gen_testing_mixed(_py: Python, m: &PyModule) -> PyResult<()> { | ||
m.add_function(wrap_pyfunction!(sum_as_string, m)?)?; | ||
Ok(()) | ||
} | ||
|
||
/// Test of unit test for testing link problem | ||
#[cfg(test)] | ||
mod test { | ||
#[test] | ||
fn test() { | ||
assert_eq!(2 + 2, 4); | ||
} | ||
} |
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,5 @@ | ||
import pyo3_stub_gen_testing_pure | ||
|
||
|
||
def test_sum_as_string(): | ||
assert pyo3_stub_gen_testing_pure.sum_as_string(1, 2) == "3" |
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