Skip to content

Commit

Permalink
Use pkgutil.get_data for zip-safe resource loading
Browse files Browse the repository at this point in the history
When running from a Zip file (`zipapp`, `*.pyz`), loading resources
from package data can not be done by directly reading files relative
to `__file__`, since there is no valid path on the file system for
zipped files.

Using `pkgutil.get_data` ensures that loading files from a Zip archive
is handled accordingly.

Resolves: python-poetry/poetry#2965
  • Loading branch information
sinoroc committed Sep 26, 2020
1 parent 59bd2ce commit 1a99dd3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 23 deletions.
12 changes: 6 additions & 6 deletions poetry/core/_vendor/jsonschema/_utils.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 6 additions & 17 deletions vendors/patches/jsonschema.patch
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,15 @@ diff --git a/poetry/core/_vendor/jsonschema/_utils.py b/poetry/core/_vendor/json
index 8fb8593..368474a 100644
--- a/poetry/core/_vendor/jsonschema/_utils.py
+++ b/poetry/core/_vendor/jsonschema/_utils.py
@@ -1,6 +1,6 @@
import itertools
import json
-import pkgutil
+import os
import re

from jsonschema.compat import MutableMapping, str_types, urlsplit
@@ -50,9 +50,12 @@ def load_schema(name):
"""
@@ -51,7 +51,10 @@ def load_schema(name):
Load a schema from ./schemas/``name``.json and return it.
"""
+ with open(
+ os.path.join(os.path.dirname(__file__), "schemas", "{0}.json".format(name))
+ ) as f:
+ data = f.read()

- data = pkgutil.get_data("jsonschema", "schemas/{0}.json".format(name))
- return json.loads(data.decode("utf-8"))
+ return json.loads(data)
+ data = pkgutil.get_data(
+ "poetry.core",
+ "_vendor/jsonschema/schemas/{0}.json".format(name),
+ )
return json.loads(data.decode("utf-8"))


def indent(string, times=1):

0 comments on commit 1a99dd3

Please sign in to comment.