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

stub_info in lib target #3

Merged
merged 7 commits into from
Jan 5, 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
3 changes: 3 additions & 0 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ jobs:

- name: Python Test
run: pytest

- name: Type check
run: pyright
3 changes: 3 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,6 @@ jobs:
with:
command: run
args: --bin stub_gen --features stub_gen

- name: Check if stub file is up to date
run: git diff --exit-code
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ prettyplease = "0.2.16"
proc-macro2 = "1.0.74"
pyo3 = { version = "0.20.1", features = ["experimental-inspect"] }
quote = "1.0.35"
serde = { version = "1.0.194", features = ["derive"] }
syn = "2.0.46"
toml = "0.8.8"
8 changes: 4 additions & 4 deletions pyo3-stub-gen-derive/src/gen_stub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub fn pyclass(item: TokenStream2) -> Result<TokenStream2> {
let inner = PyClassInfo::try_from(parse2::<ItemStruct>(item.clone())?)?;
Ok(quote! {
#item
inventory::submit! {
pyo3_stub_gen::inventory::submit! {
#inner
}
})
Expand All @@ -101,7 +101,7 @@ pub fn pyclass_enum(item: TokenStream2) -> Result<TokenStream2> {
let inner = PyEnumInfo::try_from(parse2::<ItemEnum>(item.clone())?)?;
Ok(quote! {
#item
inventory::submit! {
pyo3_stub_gen::inventory::submit! {
#inner
}
})
Expand All @@ -111,7 +111,7 @@ pub fn pymethods(item: TokenStream2) -> Result<TokenStream2> {
let inner = PyMethodsInfo::try_from(parse2::<ItemImpl>(item.clone())?)?;
Ok(quote! {
#item
inventory::submit! {
pyo3_stub_gen::inventory::submit! {
#inner
}
})
Expand All @@ -122,7 +122,7 @@ pub fn pyfunction(attr: TokenStream2, item: TokenStream2) -> Result<TokenStream2
inner.parse_attr(attr)?;
Ok(quote! {
#item
inventory::submit! {
pyo3_stub_gen::inventory::submit! {
#inner
}
})
Expand Down
1 change: 0 additions & 1 deletion pyo3-stub-gen-testing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ edition = "2021"
crate-type = ["cdylib", "rlib"]

[dependencies]
inventory.workspace = true
pyo3-stub-gen = { workspace = true, optional = true }
pyo3.workspace = true

Expand Down
17 changes: 17 additions & 0 deletions pyo3-stub-gen-testing/pyo3_stub_gen_testing.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# This file is automatically generated by pyo3_stub_gen

from typing import final, Any, List, Dict
from enum import Enum, auto

def sum_as_string(a,b) -> str:
r"""
Returns the sum of two numbers as a string.

Test of running doc-test

```rust
assert_eq!(2 + 2, 4);
```
"""
...

9 changes: 5 additions & 4 deletions pyo3-stub-gen-testing/src/bin/stub_gen.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use pyo3_stub_gen::*;
use pyo3_stub_gen::Result;

fn main() {
let modules = generate::gather().unwrap();
dbg!(modules);
fn main() -> Result<()> {
let stub = pyo3_stub_gen_testing::stub_info()?;
stub.generate_single_stub_file(env!("CARGO_MANIFEST_DIR"))?;
Ok(())
}
7 changes: 7 additions & 0 deletions pyo3-stub-gen-testing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ fn pyo3_stub_gen_testing(_py: Python, m: &PyModule) -> PyResult<()> {
Ok(())
}

#[cfg(feature = "stub_gen")]
pub fn stub_info() -> pyo3_stub_gen::Result<pyo3_stub_gen::StubInfo> {
use std::{env, path::*};
let manifest_dir: &Path = env!("CARGO_MANIFEST_DIR").as_ref();
pyo3_stub_gen::StubInfo::from_pyproject_toml(manifest_dir.join("pyproject.toml"))
}

#[cfg(test)]
mod test {
#[test]
Expand Down
4 changes: 3 additions & 1 deletion pyo3-stub-gen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ edition = "2021"
pyo3-stub-gen-derive.workspace = true

anyhow.workspace = true
itertools.workspace = true
inventory.workspace = true
itertools.workspace = true
pyo3.workspace = true
serde.workspace = true
toml.workspace = true
Loading
Loading