-
-
Notifications
You must be signed in to change notification settings - Fork 45
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
Calling importlib_resources.files
with an editable install fails
#311
Comments
I recently encountered this error too in jaraco.imaging. The same code previously passed on Apr 24, so my guess is there was some regression since then. |
For what it's worth, editable installs used to work, but not since the path hook was added to the namespace path (probably a newer form of editable install). Here's what I'm seeing for namespace path:
@abravalheri Do you know what it is that's adding that |
Oh, I see pypa/setuptools#3548 is already tracking the issue. |
This is added by a I believe that the standard that supports this is PEP 302. In the text of the PEP it is suggested that adding a "non existing" path is an acceptable approach for a different class of problems (but nonetheless the approach described still adds a non existing file to
The Python docs also explicitly say:
Also here in https://docs.python.org/3/reference/import.html#finders-and-loaders:
So my interpretation is that
I am not sure here. PEP 320 mentions Another thought is that sometimes editable namespace packages do not correspond to an actual directory in disk, and it is only simulated by the importlib machinery. For example, consider that a developer uses In that case, users are better off if they avoid calling I believe that pypa/setuptools#3548 regards a different original problem. To be honest, since we never got a reproducer, I believe that the original problem might be caused by another piece of software that expects all entries of |
@GarrStau , there is a non-exhaustive list in https://setuptools.pypa.io/en/latest/userguide/development_mode.html#limitations. |
That helps a lot. Thanks for the context. I do believe it makes sense for importlib resources to support this mode, and it should continue to be possible to resolve resources from a namespace package (as long as some provider provides resources from that package). |
…amespace package with non-path elements in the path. Ref #311
It wasn't too hard to create a test that captures the failure (b06b5fb), but unfortunately, its traceback reveals another problem:
The error is coming from |
I do see that importlib_resources/importlib_resources/readers.py Lines 140 to 150 in d021417
And that's causing the namespace reader to be skipped. So, fixing the root issue might also address the secondary issue. |
When editable installs create sentinels, as they are not a valid directory, they're unsuitable for constructing a `MultiplexedPath`. Filter them out. Fixes #311
And indeed it does. |
When editable installs create sentinels, as they are not a valid directory, they're unsuitable for constructing a `MultiplexedPath`. Filter them out. Fixes #311
…amespace package with non-path elements in the path. Ref #311
When calling
importlib_resources.files("sample-namespace")
to retrieve a text file, an exception is thrown if an editable install has been done for the package.I am able to trigger this with a relatively simple setup - I have a namespace package with two files,
sample.txt
and a__main__.py
that has two lines:from importlib_resources import files
files("sample-namespace")
In a venv with only importlib_resources 6.4.0 installed, calling "py -m sample-namespace" works without issue if
sample-namespace
is not installed or normally installed, but will fail if it is installed in editable mode.The error is thrown in the MultiplexedPath constructor, because
'__editable__.sample_namespace-1.0.finder.__path_hook__'
is one of the paths provided, andpath.is_dir()
is False leading to raising NotADirectoryError.I'm not convinced that I'm doing everything right, but I don't know of any limitations with editable installs. I'm not very familiar with this library, but if there's anything I can do to help, let me know.
Thank you!
The text was updated successfully, but these errors were encountered: