mixed_sub_multiple/
lib.rs1use pyo3::prelude::*;
2use pyo3_stub_gen::{define_stub_info_gatherer, derive::*};
3
4#[gen_stub_pyfunction(module = "mixed_sub_multiple.main_mod.mod_a")]
5#[pyfunction(name = "greet_a")]
6pub fn greet_a() {
7 println!("Hello from mod_A!")
8}
9
10#[gen_stub_pyfunction(module = "mixed_sub_multiple.main_mod")]
11#[pyfunction(name = "greet_main")]
12pub fn greet_main() {
13 println!("Hello from main_mod!")
14}
15
16#[gen_stub_pyfunction(module = "mixed_sub_multiple.main_mod.mod_b")]
17#[pyfunction(name = "greet_b")]
18pub fn greet_b() {
19 println!("Hello from mod_B!")
20}
21
22#[pymodule]
23fn main_mod(m: &Bound<PyModule>) -> PyResult<()> {
24 m.add_function(wrap_pyfunction!(greet_main, m)?)?;
25 mod_a(m)?;
26 mod_b(m)?;
27 Ok(())
28}
29
30#[pymodule]
31fn mod_a(parent: &Bound<PyModule>) -> PyResult<()> {
32 let py = parent.py();
33 let sub = PyModule::new(py, "mod_a")?;
34 sub.add_function(wrap_pyfunction!(greet_a, &sub)?)?;
35 parent.add_submodule(&sub)?;
36 Ok(())
37}
38
39#[pymodule]
40fn mod_b(parent: &Bound<PyModule>) -> PyResult<()> {
41 let py = parent.py();
42 let sub = PyModule::new(py, "mod_b")?;
43 sub.add_function(wrap_pyfunction!(greet_b, &sub)?)?;
44 parent.add_submodule(&sub)?;
45 Ok(())
46}
47
48define_stub_info_gatherer!(stub_info);
49
50#[cfg(test)]
52mod test {
53 #[test]
54 fn test() {
55 assert_eq!(2 + 2, 4);
56 }
57}