Incompatibility with newest "importlib_resources" backport of "importlib.resources"
See original GitHub issueDescription
First off, thank you for all your hard work 😃
I have found that a --onefile
/ --standalone
application using the package jsonschema
no longer works, since jsonschema
v4.x.x.
I have narrowed it down to the jsonschema._utils.load_schema
function, which appears to have changed from using pkgutil
to importlib.resources
/ importlib_resources
in its v3 -> v4 update. This seems to have broken its functionality with Nuitka.
In jsonschema
3.2.0 (working), the load_schema
function used pkgutil
def load_schema(name):
"""
Load a schema from ./schemas/``name``.json and return it.
"""
data = pkgutil.get_data("jsonschema", "schemas/{0}.json".format(name))
return json.loads(data.decode("utf-8"))
In jsonschema
4.2.1 (no longer working), it appears the load_schema
function now uses importlib_resources
if sys.version_info >= (3, 9): # pragma: no cover
import importlib.resources as resources
else: # pragma: no cover
import importlib_resources as resources
...
def load_schema(name):
"""
Load a schema from ./schemas/``name``.json and return it.
"""
path = resources.files(__package__).joinpath(f"schemas/{name}.json")
data = path.read_text(encoding="utf-8")
return json.loads(data)
Error Logs
$ ./example
Traceback (most recent call last):
File "/tmp/.mount_examplWYktsX/example.py", line 1, in <module>
import jsonschema
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "/tmp/.mount_examplWYktsX/jsonschema/__init__.py", line 29, in <module jsonschema>
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "/tmp/.mount_examplWYktsX/jsonschema/validators.py", line 349, in <module jsonschema.validators>
File "/tmp/.mount_examplWYktsX/jsonschema/_utils.py", line 61, in load_schema
File "/tmp/.mount_examplWYktsX/importlib_resources/abc.py", line 73, in read_text
File "/tmp/.mount_examplWYktsX/importlib_resources/_adapters.py", line 141, in open
FileNotFoundError: Can't open orphan path
Nuitka Version:
Tried on both latest version, and development branch version.
v0.6.17.6
develop
branch (v0.6.18rc7)
Operating System
- Ubuntu 20.04
- x86_64
- Linux 5.8.0-59-generic
Installation Method:
pip
(poetry
with virtual environment andpyproject.toml
Example
example.py
import jsonschema
print(jsonschema)
pyproject.toml
[tool.poetry]
name = "example"
version = "0.1.0"
description = ""
authors = ["..."]
[tool.poetry.dependencies]
python = "^3.8"
jsonschema = "^4.2.1"
Nuitka = "^0.6.17"
[tool.poetry.dev-dependencies]
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
nuitka.sh
#!/bin/bash
python3 -m nuitka \
example.py \
-o example \
--onefile
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Deprecating importlib.resources legacy API - Core Development
In 2018, users reported a substantial deficiency in importlib.resources API that prevented a common use-case previously supported by pkgutil ...
Read more >History - importlib-resources 5.10.2.dev4+gf8c6b66 ...
Fixes issue where backport compatibility module was masking this fallback behavior only to discover the defect when applying changes to CPython. v5.1.0#. 18...
Read more >importlib_resources backport not compatible with pyfakefs?
I'm using the importlib_resources backport for python 3.6 compatibility. The code works for pythons 3.6-3.8. However, the pytest tests, using ...
Read more >importlib-resources - PyPI
importlib_resources is a backport of Python standard library importlib.resources module for older Pythons. The key goal of this module is to replace parts ......
Read more >Loading Resource Files — PyOxidizer 0.23.0 documentation
Maintaining Compatibility With Python <3.7¶ ; importlib.resources to older Python versions. Essentially, you can always get the APIs from the latest Python ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Part of the hotfix indeed. Thanks for your report.
It seems
importlib_resources
is supposed to be working as of 0.6.1 which is a long time away, but maybe it is the one that changed. And I also couldn’t reproduce this with 3.9 and only with 3.8, which is using that backport.