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

Make C++ submodules importable #16

Open
azukov opened this issue May 23, 2024 · 3 comments
Open

Make C++ submodules importable #16

azukov opened this issue May 23, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@azukov
Copy link
Member

azukov commented May 23, 2024

Currently if a C++ module has a submodule the import is not working properly as the module is not a package.
E.g.

from orbit.core.orbit_utils.bunch_utils_functions import copyCoordsToInitCoordsAttr

will give

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'orbit.core.orbit_utils.bunch_utils_functions'; 'orbit.core.orbit_utils' is not a package

The import from module itself works, following is OK:

from orbit.core.orbit_utils import bunch_utils_functions
bunch_utils_functions.copyCoordsToInitCoordsAttr

Could be done following StackOverflow ?

@azukov azukov added the bug Something isn't working label May 30, 2024
@juanfem
Copy link
Collaborator

juanfem commented Nov 5, 2024

The way I understand C++ extension modules is that if you want to import that way, you need to declare the submodule as a separate extension module, instead of using PyModule_AddObject

But if you define a separate extension module, I think you can't do

from orbit.core.orbit_utils import bunch_utils_functions
bunch_utils_functions.copyCoordsToInitCoordsAttr()

unless you create a __init__.py under orbit/core/orbit_utils that does from . import copyCoordsToInitCoordsAttr

@azukov
Copy link
Member Author

azukov commented Nov 5, 2024

I think I tried adding 'package' constant as mentioned in the above StackOverflow post and it worked.

@juanfem
Copy link
Collaborator

juanfem commented Nov 5, 2024

ah, I haven't tried that. I'll check that solution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants