-
Notifications
You must be signed in to change notification settings - Fork 60
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
Restructure python parts, splitting code generation and python bindings into separate modules #511
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably a good idea. I see you already moved quite a few tests, but you mention more that would need to be moved? Which ones would that be?
I didn't move any tests - I mean moving tests from the current folder |
Ah, apologies. Misread the diff. I would move them, just to have them closer to the code they are testing. |
Now they are moved and are in a separate test since it doesn't seem it's easy to get them working in the same since they are now different modules |
python/CMakeLists.txt
Outdated
#--- install templates --------------------------------------------------------- | ||
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/templates | ||
DESTINATION ${podio_PYTHON_INSTALLDIR}) | ||
|
||
IF (BUILD_TESTING) | ||
add_test( NAME pyunittest COMMAND python3 -m unittest discover -s ${PROJECT_SOURCE_DIR}/python/podio) | ||
add_test( NAME pyunittest COMMAND python3 -m unittest discover -s ${PROJECT_SOURCE_DIR}/python/podio -p "test_*.py") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add_test( NAME pyunittest COMMAND python3 -m unittest discover -s ${PROJECT_SOURCE_DIR}/python/podio -p "test_*.py") | |
add_test( NAME pyunittest COMMAND python3 -m unittest discover -s ${PROJECT_SOURCE_DIR}/python -p "test_*.py") |
I think otherwise we are missing the ones that are now in podio_gen
, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, of course, that is what I tested before and it doesn't work. I'm checking...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I have no idea how to make it work with a single test. First, when trying to discover from the top directory python will call dir(podio)
and will fail like in #512. Even finding a workaround some tests fail with errors related to some errors when importing like this
ImportError: Failed to import test module: podio.test_EventStore
Traceback (most recent call last):
File "/usr/lib/python3.11/unittest/loader.py", line 407, in _find_test_path
module = self._get_module_from_name(name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/unittest/loader.py", line 350, in _get_module_from_name
__import__(name)
File "/usr/lib/python3.11/site-packages/ROOT/_facade.py", line 154, in _importhook
return _orig_ihook(name, *args, **kwds)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named 'podio.test_EventStore'; 'podio' is not a package
so I reverted back to the version that works except pre-commit...
pre-commit complains about a cyclic import, but it doesn't really make sense to me, as the script should now only import from https://github.com/AIDASoft/podio/actions/runs/6776714508/job/18418800193?pr=511#step:4:427 |
I believe the diagnosis is correct; podio wants to import test_utils and test_utils wants to import podio. Actually the try - except block only seems to work during test time. I'm not sure why it appears now though |
Ah then we can maybe switch to a from .frame import Frame in |
That breaks some tests due to relative imports. Another proposal: move test_utils.py to |
I tried that, but that breaks with the weird c++ error in the comment (or at least it did in the past). I agree, this should really live in the |
I think I found the issue. If I do from podio.test_utils import Frame
print(Frame) I get from podio import Frame
print(Frame) I get I am not yet sure why things are working inside |
- Make tests actuallyt test that
I have removed the I think in this case not having all of the c++ bits of podio directly available in python is OK, since for the main use cases we provide wrappers in any case and all the others are effectively mainly there to support the implementation of those, and I don't think we gain too much by exposing them to people in python. Since this has now become a bit more than just "decoupling the generation files from the rest of the podio python files" I would actually also like to pick up #498 in this PR and make it another general overhaul of the python structure of podio. Mainly because #498 needs to be touched again in any case and we might as well resolve the merge conflict in this PR, rather than later. |
@@ -2,59 +2,5 @@ | |||
"""Utilities for python unittests""" | |||
|
|||
import os |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm this file only has like 3 lines after all the removals, I'm not sure if it's needed...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I can clean this up in the course of #485
Looks good but now if you want to have a fully working podio in python you can't unless you do |
I think
|
BEGINRELEASENOTES
podio_gen
. This is a transparent change for users that only use the generator script.podio
)__init__.py
and remove thetest_utils
from it.tests
folder, where they belong and also test the SIO python writer.ENDRELEASENOTES
Generation tools do not need to load or know anything about the rest of podio. I think the remaining question is if the tests have to be moved or not, some of them only test generation tools.