-
Notifications
You must be signed in to change notification settings - Fork 2
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
Remove duplicate python module name #31
Comments
This must be different from |
See [https://www.codingem.com/python-difference-between-import-and-from-import/] for the difference between them. |
The issue is referring to the |
Agreed. Let me investigate. |
Same solution as #34 . |
There is not much we can do about this, this is how the Python structure works. |
FTR, there is no To reiterate, the problem here is our package setup not how Python works. I expect: import nwchemex
nwchemex.load_modules() to work. I should not have to do: from nwchemex import nwchemex
nwchemex.load_moddules() The former code snippet imports the |
You are correct, I misspoke.
|
To be clear are you saying that you agree that it shouldn't be |
It's undesirable, but this is a Python feature. To do what you want we need to tell cppyy to ignore the nwchemex namespace (for example). |
End of the day, this syntax is not normal. Users do: import numpy
import math
my_array = numpy.ndarray()
two = math.sqrt(4) not: from numpy import numpy
from math import math
my_array = numpy.ndarray()
two = math.sqrt(4) As for resolving this issue, if we have to provide a wrapper to get the syntax to be |
Will see if there is a way around this. For reference: https://realpython.com/python-modules-packages/ |
What is your issue with
With this all of it works, and you can directly access all the modules. There is no way to effectively remove the extra namespace. And, adding a wrapper to initialize only adds another level of namespace. |
First FWIW, I'm pretty sure this entire issue can be resolved with a one line modification to the |
Actually, I see where @ryanmrichard was going with the init.py discussion. I think I overlooked what I think he is referring to. Bert |
I was wrong. I don't think this can be fixed in one line. There's more going on here than I appreciated. I thought we could do something like: from cppy.gbl.parallelzone import * or (since from cppy.gbl import parallelzone
from parallelzone import * to strip off the extra However, while testing my solution I now see that when you do |
I'm incredibly confused by what's going on because I don't understand how from parallelzone import parallelzone_meta |
This seems to work:
|
Working off of NWChemEx/ParallelZone#75, your solution doesn't work for me: [ctest] ImportError: Failed to import test module: test_parallelzone
[ctest] Traceback (most recent call last):
[ctest] File "/usr/lib/python3.10/unittest/loader.py", line 470, in _find_test_path
[ctest] package = self._get_module_from_name(name)
[ctest] File "/usr/lib/python3.10/unittest/loader.py", line 377, in _get_module_from_name
[ctest] __import__(name)
[ctest] File "/home/ryan/workspaces/NWX/ParallelZone/tests/py_unit_tests/test_parallelzone/__init__.py", line 19, in <module>
[ctest] from parallelzone import parallelzone
[ctest] File "/home/ryan/workspaces/NWX/ParallelZone/build/Python/parallelzone/__init__.py", line 28, in <module>
[ctest] import cppyy.gbl.parallelzone as parallelzone
[ctest] ModuleNotFoundError: No module named 'cppyy.gbl.parallelzone'; 'cppyy.gbl' is not a package
[ctest] |
I did not check the init. I simply was doing: `[GCC 9.4.0] on linux
` Not sure why this does not work on the init side. |
I think I'm starting to understand what's going on. It appears that Cppyy does not make a parallelzone module or package at all. All the Cppyy symbols live in a global object So @wadejong I think that you're right, there's nothing we can do at the moment to change this sytax. The current syntax is a result of Python's import semantics and the decisions Cppyy makes. However, I would argue the Cppyy decision to map a C++ namespace to a Python class doesn't make sense. Conceptually it's more of a Python module or a Python package. I don't know, but maybe it's not possible for Cppyy to automate such a mapping? |
I posed the question to Wim. Let's see what his thoughts are. |
Right now our Python API looks like:
Namely each top-level Python module keeps its functionality in a submodule of the same name.
I think it makes more sense for the API to be:
I assume this is an either an issue with the generated
__init__.py
file or the CMake module for creating the Python bindings.The text was updated successfully, but these errors were encountered: