Skip to content

Commit

Permalink
chore: allow importing submodule from python
Browse files Browse the repository at this point in the history
This code makes it possible to import math as a Python
submodule. Extension modules are not packages, so their submodules
are not affected by the usual rules from import machinery.
  • Loading branch information
vlaci authored and qkaiser committed Jan 8, 2024
1 parent f3ee12e commit a853288
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/math_tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ pub fn init_module(py: Python, root_module: &PyModule) -> PyResult<()> {

root_module.add_submodule(module)?;

let sys = PyModule::import(py, "sys")?;
let modules = sys.getattr("modules")?;
modules.call_method(
"__setitem__",
("unblob_native.math_tools".to_string(), module),
None,
)?;

Ok(())
}

Expand Down

0 comments on commit a853288

Please sign in to comment.