Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python module issues #3

Closed
Tracked by #5 ...
AtomicGamer9523 opened this issue Dec 16, 2023 · 2 comments · May be fixed by #5
Closed
Tracked by #5 ...

Python module issues #3

AtomicGamer9523 opened this issue Dec 16, 2023 · 2 comments · May be fixed by #5
Assignees
Labels
B-Nightly Branch: Nightly Done Progress: This is done / completed / answered O-Other OS: Other / Unknown / Universal T-Bug Tag: Bug, error, or unintended behavior

Comments

@AtomicGamer9523 AtomicGamer9523 added T-Bug Tag: Bug, error, or unintended behavior O-Other OS: Other / Unknown / Universal labels Dec 16, 2023
@AtomicGamer9523 AtomicGamer9523 self-assigned this Dec 16, 2023
This was referenced Dec 25, 2023
@AtomicGamer9523 AtomicGamer9523 linked a pull request Dec 26, 2023 that will close this issue
6 tasks
@AtomicGamer9523 AtomicGamer9523 added WIP Progress: This is work in progress B-Nightly Branch: Nightly labels Dec 28, 2023
@AtomicGamer9523
Copy link
Member Author

Fixed in bbc66fe

Explanation:

  1. We create the submodule via PyModule::new
  2. Call that the function that represents the submodule (providing py, so this module)
  3. Then we add the submodule to the parent module. (m.add_submodule(module_name))
  4. Finally, run a python script to add the submodule to sys.modules.

I created this macro to do so easier:

macro_rules! pymod {
    ($module_name: ident -> $submodule_func: path, $module_path: literal, $py:ident, $m: ident) => {
        let $module_name = PyModule::new($py, ::core::stringify!($module_name))?;
        $submodule_func($py, $module_name)?;
        $m.add_submodule($module_name)?;
        pyo3::py_run!(
            $py,
            $module_name,
            ::core::concat!(
                "import sys; sys.modules['",
                $module_path,
                "'] = ",
                ::core::stringify!($module_name),
            )
        );
    };
}

@AtomicGamer9523
Copy link
Member Author

Also added these same docs in 1774431

@AtomicGamer9523 AtomicGamer9523 added Done Progress: This is done / completed / answered and removed WIP Progress: This is work in progress labels Dec 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
B-Nightly Branch: Nightly Done Progress: This is done / completed / answered O-Other OS: Other / Unknown / Universal T-Bug Tag: Bug, error, or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant