-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Allow namespace packages in _EditableFinder #4954
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
Draft
jaraco
wants to merge
1
commit into
main
Choose a base branch
from
feature/4943-namespace-child-simple
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+5
−0
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Would something like the following make sense?
(or some kind of refactoring on
_EditableNamespaceFinder
so that we reuse the same logic?)Previously when I was working with namespaces, I found that sometimes the import machinery ignores the
ModuleSpec
object returned by the finders and create a completely new one.For some cases I found that I had to use a
sys.path_hooks
instead ofsys.meta_path
, that is why I implemented the namespace handling in_EditableNamespaceFinder
. But it seems that it was not enough 😅. I believe that the relevant portion of the code ishttps://github.com/python/cpython/blob/580888927c8eafbf3d4c6be9144684117f0a96ca/Lib/importlib/_bootstrap_external.py#L1259-L1285.
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.
Maybe. I briefly considered using the _EditableNamespaceFinder, but it also felt like that finder had too much behavior that was maybe unneeded for these (ns-package-in-simple-package) packages. Because the parent simple package can't have multiple paths, that also means there's no possibility of this child ns package having multiple paths. In the example,
test
has one home, sotest.b
will only ever have one home.Although, now that I think about it, since Setuptools is doing something special here, and constructing packages virtually from various sources, it's conceivable that
test.b
could in fact have multiple paths. That is,test.b.foo
could come from one path whiletest.b.bar
ortest.b.c
comes from another. I don't think that's possible given the currentpackage_dir
implementation thattest.b
could ever have modules in multiple paths, but it seems perfectly possible thatpackage_dir = {'test.b.c': 'some path'}
could extend the paths and namespace oftest.b
. And in that case, maybe reusing the functionality of _EditableNamespaceFinder makes sense. I also like the elegance of fewer lines of code. I'll give it a try.