From 83e810c24ace8c3d3853de9000ba2098bce78ff3 Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Sun, 27 Apr 2014 18:32:35 -0400 Subject: [PATCH] Load meta-schemas via pkgutil rather than searching the filesystem. Hopefully this makes things like cx_Freeze work, but they appear to all be special snowflakes and this doesn't appear easy to test. Credit to @pjdelport for helping clear away some of the smoke. Closes #161, #162 --- jsonschema/_utils.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/jsonschema/_utils.py b/jsonschema/_utils.py index 620dab4..2262f33 100644 --- a/jsonschema/_utils.py +++ b/jsonschema/_utils.py @@ -1,7 +1,7 @@ import itertools import json +import pkgutil import re -import os from jsonschema.compat import str_types, MutableMapping, urlsplit @@ -54,11 +54,8 @@ def load_schema(name): """ - schema_dir = os.path.join( - os.path.dirname(os.path.abspath(__file__)), "schemas", - ) - with open(os.path.join(schema_dir, name + ".json")) as schema_file: - return json.load(schema_file) + data = pkgutil.get_data(__package__, "schemas/{0}.json".format(name)) + return json.loads(data.decode("utf-8")) def indent(string, times=1):