From a853288d4b5bd573db66ca5c8415a0af9d45c266 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20Vask=C3=B3?= <1771332+vlaci@users.noreply.github.com> Date: Fri, 2 Jun 2023 15:03:06 +0200 Subject: [PATCH] chore: allow importing submodule from python 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. --- src/math_tools.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/math_tools.rs b/src/math_tools.rs index 826adf0..fadc904 100644 --- a/src/math_tools.rs +++ b/src/math_tools.rs @@ -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(()) }