PyOxidizer icon indicating copy to clipboard operation
PyOxidizer copied to clipboard

Migrating from `importlib.resources.open_text` to `files` looks broken

Open alexprengere opened this issue 3 years ago • 2 comments

First of all, let me say the pyoxidizer works great! I have a pure python project where I use pyoxidizer to build a fully standalone executable (no issues here).

I wanted to get rid of some warnings in that Python project and migrate from importlib.resources.open_text to the files API, as described here.

It looks like this breaks pyoxidizer:

  File "importlib.resources", line 147, in files
  File "importlib._common", line 14, in from_package
  File "importlib._common", line 18, in fallback_resources
  File "pathlib", line 1082, in __new__
  File "pathlib", line 707, in _from_parts
  File "pathlib", line 691, in _parse_args
TypeError: expected str, bytes or os.PathLike object, not NoneType

After digging a bit, it looks like the files() as implemented here relies on fallback_resources as implemented there. The python modules returned by import_module from oxidized_importer.OxidizedFinder, seem to have their __spec__.origin set to None. This breaks the fallback_resources, that is never called when using open_text (there seems to be a fallback on empty __spec__.origin in that code path).

alexprengere avatar Mar 18 '22 07:03 alexprengere

I was also trying to use the updated files() interface, and in particular the feature where (in conjunction with as_file()) it offers directory support, released in v5.9.0 of importlib_resources...

Currently, using pyoxidizer, I similarly get a TypeError due to the NoneType returned.

lorengordon avatar Jan 29 '23 16:01 lorengordon

Better than relying on fallback_resources, I'd like for PyOxidizer/OxidizedFinder to implement the preferred TraversableResources interface, mentioned here, and specified here.

jaraco avatar Feb 13 '23 22:02 jaraco