-
-
Notifications
You must be signed in to change notification settings - Fork 276
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
Update submodule_path after finding an editable install #2033
Update submodule_path after finding an editable install #2033
Conversation
Thanks for this @noah-weingarden! Do you think it will be possible to add a test for this? |
Hmm, you mentioned in #1752 that you don't want to introduce a dependency on setuptools, so that definitely makes it harder. Could we test it by mocking To be honest though, I'm pretty confused in general about which aspects of the Python packaging world are stable. #1752 seems to depend on there being an |
I have you are willing to put in the in the time to create the tests that mocks |
Alrighty, I made a test! If you remove the change I made to (Side-note: To get this to work locally, I had to make a separate import for |
astroid/interpreter/_import/spec.py
Outdated
submodule_path = finder.contribute_to_path(spec, processed) | ||
# If modname is a package from an editable install, update submodule_path | ||
# so that the next module in the path will be found inside of it using importlib. | ||
elif finder.__name__ in {"_EditableFinder", "_EditableNamespaceFinder"}: |
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'm wondering if we should extract this logic into a class, but for now I think this is fine!
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 agree. Do you think the logic will apply to all of the keys in _MetaPathFinderModuleTypes
? (I'm not familiar with six
). If so, an improvement for now would be to use 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.
When I implemented this @jacobtylerwalls actually (rightly) stressed that we should probably be careful here: we rather want to have less support for installers we don't know than making assumptions that don't turn out to be true.
We can always add support for new ones if we encounter them.
The import system is apparently not that well defined..
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.
Sounds good. I left the set alone, but moved it to be a top-level variable instead of treating it as a constant. Any new classes can be added to that set.
tests/testdata/python3/data/import_setuptools_pep660/__editable___example_0_1_0_finder.py
Show resolved
Hide resolved
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.
@jacobtylerwalls Do you want to take a look?
Thanks for this @noah-weingarden
I'll create a PR myself to unblock the CI, that seems unassosciated.
@noah-weingarden Could you rebase this? |
Add a test Add module docstring and extract set to top-level
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #2033 +/- ##
=======================================
Coverage 92.78% 92.78%
=======================================
Files 95 95
Lines 11007 11011 +4
=======================================
+ Hits 10213 10217 +4
Misses 794 794
Flags with carried forward coverage won't be shown. Click here to find out more.
|
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.
Looks good!
Type of Changes
Description
#1752 enabled
astroid
to find modules that use an editable install with import hooks, but it didn't enable finding submodules of a package that uses such an editable install. This PR updatessubmodule_path
when necessary to fix that. All modules in the path after the first one should useImportlibFinder
as a result of this change. See this comment for a more detailed description and a minimal reproducible example.I didn't update the changelog because the bug this is fixing is tied to a different bugfix that hasn't been released yet, but let me know if I should add one.
Refs pylint-dev/pylint#7306