Skip to content

Commit

Permalink
refactor(filetree): docs -> document, features -> feature, dev -> dev…
Browse files Browse the repository at this point in the history
…elopment
  • Loading branch information
HsiangNianian committed Mar 12, 2024
1 parent 91ebc76 commit 6e555bf
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 1 deletion.
3 changes: 2 additions & 1 deletion hydro_roll_core/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import corelib
from . import corelib

File renamed without changes.
File renamed without changes.
File renamed without changes.
36 changes: 36 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#![allow(unused)]
fn main() {
use pyo3::prelude::*;

#[pymodule]
fn parent_module(py: Python<'_>, m: &PyModule) -> PyResult<()> {
register_child_module(py, m)?;
Ok(())
}

fn register_child_module(py: Python<'_>, parent_module: &PyModule) -> PyResult<()> {
let child_module = PyModule::new(py, "child_module")?;
child_module.add_function(wrap_pyfunction!(func, child_module)?)?;
parent_module.add_submodule(child_module)?;
Ok(())
}

#[pyfunction]
fn func() -> String {
"func".to_string()
}

Python::with_gil(|py| {
use pyo3::types::IntoPyDict;
use pyo3::wrap_pymodule;
let parent_module = wrap_pymodule!(parent_module)(py);
let ctx = [("parent_module", parent_module)].into_py_dict(py);

py.run(
"assert parent_module.child_module.func() == 'func'",
None,
Some(&ctx),
)
.unwrap();
})
}

0 comments on commit 6e555bf

Please sign in to comment.