importlib_resources
importlib_resources copied to clipboard
Calling `importlib_resources.files` with an editable install fails
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, and path.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!
(.venv) PS C:\git\TEST\test-importlib-resources-files-editable> py -m sample-namespace Traceback (most recent call last): File "
", line 198, in _run_module_as_main File " ", line 88, in run_code File "C:\git\TEST\test-importlib-resources-files-editable\sample-namespace_main.py", line 3, in files("sample-namespace") File "C:\git\TEST\test-importlib-resources-files-editable.venv\Lib\site-packages\importlib_resources_common.py", line 46, in wrapper return func(anchor) ^^^^^^^^^^^^ File "C:\git\TEST\test-importlib-resources-files-editable.venv\Lib\site-packages\importlib_resources_common.py", line 56, in files return from_package(resolve(anchor)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\git\TEST\test-importlib-resources-files-editable.venv\Lib\site-packages\importlib_resources_common.py", line 116, in from_package reader = spec.loader.get_resource_reader(spec.name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\git\TEST\test-importlib-resources-files-editable.venv\Lib\site-packages\importlib_resources\future\adapters.py", line 66, in get_resource_reader or super().get_resource_reader(name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\git\TEST\test-importlib-resources-files-editable.venv\Lib\site-packages\importlib_resources_adapters.py", line 29, in get_resource_reader return CompatibilityFiles(self.spec)._native() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\git\TEST\test-importlib-resources-files-editable.venv\Lib\site-packages\importlib_resources_adapters.py", line 153, in _native reader = self._reader ^^^^^^^^^^^^ File "C:\git\TEST\test-importlib-resources-files-editable.venv\Lib\site-packages\importlib_resources_adapters.py", line 147, in _reader return self.spec.loader.get_resource_reader(self.spec.name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File " ", line 1425, in get_resource_reader File "C:\Users\garrstau\AppData\Local\Programs\Python\Python312\Lib\importlib\resources\readers.py", line 133, in init self.path = MultiplexedPath(*list(namespace_path)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\garrstau\AppData\Local\Programs\Python\Python312\Lib\importlib\resources\readers.py", line 70, in init raise NotADirectoryError('MultiplexedPath only supports directories') NotADirectoryError: MultiplexedPath only supports directories