Skip to content

Commit

Permalink
Generate my_pkg/my_rust_pkg.pyi
Browse files Browse the repository at this point in the history
  • Loading branch information
termoshtt committed Jan 27, 2024
1 parent 1da2abe commit 15fd361
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
11 changes: 11 additions & 0 deletions pyo3-stub-gen-testing-mixed/python/my_pkg/my_rust_pkg.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# 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.
"""
...

2 changes: 1 addition & 1 deletion pyo3-stub-gen-testing-mixed/src/bin/stub_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ 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"))?;
stub.generate()?;
Ok(())
}
9 changes: 5 additions & 4 deletions pyo3-stub-gen/src/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,14 +459,15 @@ impl StubInfo {
Ok(())
}

pub fn generate_stub_files(&self, python_root: impl AsRef<Path>) -> Result<()> {
let python_root = python_root.as_ref();
pub fn generate(&self) -> Result<()> {
let python_source = self.pyproject.python_source().unwrap();
for (name, module) in self.modules.iter() {
let path: Vec<&str> = name.split('.').collect();
dbg!(&path);
let dest = if path.len() > 1 {
python_root.join(format!("{}.pyi", path[1..].join("/")))
python_source.join(format!("{}.pyi", path.join("/")))
} else {
python_root.join("__init__.pyi")
python_source.join("__init__.pyi")
};

if let Some(dir) = dest.parent() {
Expand Down

0 comments on commit 15fd361

Please sign in to comment.