Skip to content

Commit ebbcbc8

Browse files
committed
Use flask to server remotes directly
1 parent bb98b03 commit ebbcbc8

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

bin/jsonschema_suite

+8-16
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,6 @@ def collect(root_dir):
5757
yield os.path.join(root, filename)
5858

5959

60-
def collect_contents(root_dir):
61-
files = {}
62-
for path in collect(root_dir):
63-
relative_path = os.path.relpath(path, root_dir)
64-
with open(path) as schema_file:
65-
files[relative_path] = json.load(schema_file)
66-
return files
67-
68-
6960
class SanityTests(unittest.TestCase):
7061
@classmethod
7162
def setUpClass(cls):
@@ -153,7 +144,11 @@ def main(arguments):
153144

154145
json.dump(selected_cases, sys.stdout, indent=4, sort_keys=True)
155146
elif arguments.command == "remotes":
156-
remotes = collect_contents(REMOTES_DIR)
147+
remotes = {}
148+
for path in collect(REMOTES_DIR):
149+
relative_path = os.path.relpath(path, REMOTES_DIR)
150+
with open(path) as schema_file:
151+
remotes[relative_path] = json.load(schema_file)
157152
json.dump(remotes, sys.stdout, indent=4, sort_keys=True)
158153
elif arguments.command == "dump_remotes":
159154
if arguments.update:
@@ -168,7 +163,7 @@ def main(arguments):
168163
raise
169164
elif arguments.command == "serve":
170165
try:
171-
from flask import Flask, jsonify
166+
import flask
172167
except ImportError:
173168
print(textwrap.dedent("""
174169
The Flask library is required to serve the remote schemas.
@@ -181,14 +176,11 @@ def main(arguments):
181176
""".strip("\n")))
182177
sys.exit(1)
183178

184-
remotes = collect_contents(REMOTES_DIR)
185-
app = Flask(__name__)
179+
app = flask.Flask(__name__)
186180

187181
@app.route("/<path:path>")
188182
def serve_path(path):
189-
if path in remotes:
190-
return jsonify(remotes[path])
191-
return "Document does not exist.", 404
183+
return flask.send_from_directory(REMOTES_DIR, path)
192184

193185
app.run(port=1234)
194186

0 commit comments

Comments
 (0)