-
Notifications
You must be signed in to change notification settings - Fork 47
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
Add more tests of package traversal #906
base: main
Are you sure you want to change the base?
Conversation
@LecrisUT this PR should capture some of the cases you mentioned in #808 (comment). Are there others that you would like to see added? |
Looks promising :). I'll need to draw it out on a paper to follow it 😅 , I'll come back to you after that. At first glance, I think the only part not covered is having both relative and absolute paths in the |
from importlib.readers import MultiplexedPath | ||
import pkg | ||
import pathlib | ||
print({check}) |
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.
This should be assert
instead of print
. Could you also move check
to be in-lined here instead of a parameter?
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.
Rather than asserting here, I print the boolean result and assert the string value outside because asserting inside a subprocess requires significantly more post-processing to handle cleanly.
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.
Could you elaborate on why it requires more post-processing, or what the output you get when doing that?
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.
Regarding the coverage, right now it seems the import
only cover python packages, the c methods must also be imported there.
Most of the imports only cover 1 level deep imports, and are a bit redundant. I would say to minimize it and comment what is being covered:
# pkg/__init__.py
# Covering importing one-level deep from 1st level pakage
from .py_mod import py_square1
from .c_mod import c_square1
# Coverging importing 2-levels deep from 1st level package
from .subA.py_mod import py_square2
from .subA.c_mod import c_square2
# pkg/subA/__init__.py
# Covering importing one-level deep from 2nd level pakage
from .py_mod import py_square3
from .c_mod import c_square3
# Coverging importing relative paths backwards
from ..subB.py_mod import py_square4
from ..subB.c_mod import c_square4
I suck at naming conventions, hope you can figure a good one.
@@ -0,0 +1,5 @@ | |||
python_add_library(subpkg1 MODULE subpkg1.c WITH_SOABI) | |||
|
|||
install(TARGETS subpkg1 DESTINATION pkg/subpkg1) |
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.
Please rename these to indicate they are modules and don't have confusing name duplication with the parent package.
@@ -0,0 +1,3 @@ | |||
from . import pure |
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.
Don't you want to from .c_mod import square
(renaming the subpkg1.c
because it's confusing). This would be testing the navigation from python package to module.
@@ -0,0 +1,3 @@ | |||
from . import pure |
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.
Can the name of the python packages be renamed to something less verbose? Maybe foo.bar.baz
or subA.subB.modC
or any convention you can think of. pkg.subpkg2.subsubpkg1.subsubpkg1
is a bit much.
import pkg.subpkg2.subsubpkg1 | ||
import pkg.subpkg2.subsubpkg1.pure | ||
import pkg.subpkg2.subsubpkg2 | ||
import pkg.subpkg2.subsubpkg2.pure |
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 am wondering if all of these imports should be merged into the import pkg
or if the __init__.py
should be empty. Feels weird having it duplicated. I am leaning towards the former because we could make the imports be relative or absolute or ambiguous using an environment variable.
On the overall structure of the files, I think it's a good skeleton to cover all the cases, we just need to cover the navigations within there. Just a few notes:
|
This PR adds tests (including some xfailed ones) demonstrated patterns of package/subpackage access via import and importlib that are expected to work correctly for both normal and editable installs. Related to #807.