Skip to content

Commit ae0ef4e

Browse files
author
Peter Amstutz
committed
Remove explicit calls to validate_links since it is folded into resolve_all().
1 parent 2fa6bfb commit ae0ef4e

File tree

4 files changed

+21
-33
lines changed

4 files changed

+21
-33
lines changed

schema_salad/main.py

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,16 @@ def main(argsl=None): # type: (List[str]) -> int
9898
if not urlparse.urlparse(schema_uri)[0]:
9999
schema_uri = "file://" + os.path.abspath(schema_uri)
100100
schema_raw_doc = metaschema_loader.fetch(schema_uri)
101-
schema_doc, schema_metadata = metaschema_loader.resolve_all(
102-
schema_raw_doc, schema_uri)
101+
102+
try:
103+
schema_doc, schema_metadata = metaschema_loader.resolve_all(
104+
schema_raw_doc, schema_uri)
105+
except (validate.ValidationException) as e:
106+
_logger.error("Schema `%s` failed link checking:\n%s",
107+
args.schema, e, exc_info=(e if args.debug else False))
108+
_logger.debug("Index is %s", metaschema_loader.idx.keys())
109+
_logger.debug("Vocabulary is %s", metaschema_loader.vocab.keys())
110+
return 1
103111

104112
# Optionally print the schema after ref resolution
105113
if not args.document and args.print_pre:
@@ -110,16 +118,6 @@ def main(argsl=None): # type: (List[str]) -> int
110118
print(json.dumps(metaschema_loader.idx.keys(), indent=4))
111119
return 0
112120

113-
# Validate links in the schema document
114-
# try:
115-
# metaschema_loader.validate_links(schema_doc)
116-
# except (validate.ValidationException) as e:
117-
# _logger.error("Schema `%s` failed link checking:\n%s",
118-
# args.schema, e, exc_info=(e if args.debug else False))
119-
# _logger.debug("Index is %s", metaschema_loader.idx.keys())
120-
# _logger.debug("Vocabulary is %s", metaschema_loader.vocab.keys())
121-
# return 1
122-
123121
# Validate the schema document against the metaschema
124122
try:
125123
schema.validate_doc(metaschema_names, schema_doc,
@@ -196,16 +194,6 @@ def main(argsl=None): # type: (List[str]) -> int
196194
print(json.dumps(document_loader.idx.keys(), indent=4))
197195
return 0
198196

199-
# Validate links in the target document
200-
# try:
201-
# document_loader.validate_links(document)
202-
# except (validate.ValidationException) as e:
203-
# _logger.error("Document `%s` failed link checking:\n%s",
204-
# args.document, e, exc_info=(e if args.debug else False))
205-
# _logger.debug("Index is %s", json.dumps(
206-
# document_loader.idx.keys(), indent=4))
207-
# return 1
208-
209197
# Validate the schema document against the metaschema
210198
try:
211199
schema.validate_doc(avsc_names, document,

schema_salad/ref_resolver.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ def add_context(self, newcontext, baseuri=""):
239239
_logger.debug("vocab_fields is %s", self.vocab_fields)
240240
_logger.debug("vocab is %s", self.vocab)
241241

242-
def resolve_ref(self, ref, base_url=None, toplevel=True):
242+
def resolve_ref(self, ref, base_url=None, checklinks=True):
243243
# type: (Union[Dict[str, Any], str, unicode], Union[str, unicode], bool) -> Tuple[Union[Dict[str, Any], str, unicode], Dict[str, Any]]
244244
base_url = base_url or 'file://%s/' % os.path.abspath('.')
245245

@@ -301,7 +301,7 @@ def resolve_ref(self, ref, base_url=None, toplevel=True):
301301
doc = self.fetch(doc_url)
302302

303303
# Recursively expand urls and resolve directives
304-
obj, metadata = self.resolve_all(doc if doc else obj, doc_url, toplevel=toplevel)
304+
obj, metadata = self.resolve_all(doc if doc else obj, doc_url, checklinks=checklinks)
305305

306306
# Requested reference should be in the index now, otherwise it's a bad
307307
# reference
@@ -322,7 +322,7 @@ def resolve_ref(self, ref, base_url=None, toplevel=True):
322322
except TypeError:
323323
return obj, metadata
324324

325-
def resolve_all(self, document, base_url, file_base=None, toplevel=True):
325+
def resolve_all(self, document, base_url, file_base=None, checklinks=True):
326326
# type: (Any, Union[str, unicode], Union[str, unicode], bool) -> Tuple[Any, Dict[str, Any]]
327327
loader = self
328328
metadata = {} # type: Dict[str, Any]
@@ -332,7 +332,7 @@ def resolve_all(self, document, base_url, file_base=None, toplevel=True):
332332
if isinstance(document, dict):
333333
# Handle $import and $include
334334
if ('$import' in document or '$include' in document):
335-
return self.resolve_ref(document, base_url=file_base, toplevel=toplevel)
335+
return self.resolve_ref(document, base_url=file_base, checklinks=checklinks)
336336
elif isinstance(document, list):
337337
pass
338338
else:
@@ -368,7 +368,7 @@ def resolve_all(self, document, base_url, file_base=None, toplevel=True):
368368
if "$graph" in document:
369369
metadata = _copy_dict_without_key(document, "$graph")
370370
document = document["$graph"]
371-
metadata, _ = loader.resolve_all(metadata, base_url, file_base=file_base, toplevel=False)
371+
metadata, _ = loader.resolve_all(metadata, base_url, file_base=file_base, checklinks=False)
372372

373373
if isinstance(document, dict):
374374
for idmapField in loader.idmap:
@@ -433,7 +433,7 @@ def resolve_all(self, document, base_url, file_base=None, toplevel=True):
433433
try:
434434
for key, val in document.items():
435435
document[key], _ = loader.resolve_all(
436-
val, base_url, file_base=file_base, toplevel=False)
436+
val, base_url, file_base=file_base, checklinks=False)
437437
except validate.ValidationException as v:
438438
_logger.debug("loader is %s", id(loader))
439439
raise validate.ValidationException("(%s) (%s) Validation error in field %s:\n%s" % (
@@ -445,7 +445,7 @@ def resolve_all(self, document, base_url, file_base=None, toplevel=True):
445445
while i < len(document):
446446
val = document[i]
447447
if isinstance(val, dict) and "$import" in val:
448-
l, _ = loader.resolve_ref(val, base_url=file_base, toplevel=False)
448+
l, _ = loader.resolve_ref(val, base_url=file_base, checklinks=False)
449449
if isinstance(l, list):
450450
del document[i]
451451
for item in aslist(l):
@@ -456,7 +456,7 @@ def resolve_all(self, document, base_url, file_base=None, toplevel=True):
456456
i += 1
457457
else:
458458
document[i], _ = loader.resolve_all(
459-
val, base_url, file_base=file_base, toplevel=False)
459+
val, base_url, file_base=file_base, checklinks=False)
460460
i += 1
461461
except validate.ValidationException as v:
462462
raise validate.ValidationException("(%s) (%s) Validation error in position %i:\n%s" % (
@@ -469,7 +469,7 @@ def resolve_all(self, document, base_url, file_base=None, toplevel=True):
469469
metadata[identifer], base_url, scoped=True)
470470
loader.idx[metadata[identifer]] = document
471471

472-
if toplevel:
472+
if checklinks:
473473
self.validate_links(document, "")
474474

475475
return document, metadata

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
extras_require = {} # TODO: to be removed when the above is added
4242

4343
setup(name='schema-salad',
44-
version='1.11',
44+
version='1.12',
4545
description='Schema Annotations for Linked Avro Data (SALAD)',
4646
long_description=open(README).read(),
4747
author='Common workflow language working group',

tests/test_examples.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def test_examples(self):
166166
"schema_salad/metaschema/%s_schema.yml" % a)
167167
with open("schema_salad/metaschema/%s_src.yml" % a) as src_fp:
168168
src = ldr.resolve_all(
169-
yaml.load(src_fp, Loader=SafeLoader), "", toplevel=False)[0]
169+
yaml.load(src_fp, Loader=SafeLoader), "", checklinks=False)[0]
170170
with open("schema_salad/metaschema/%s_proc.yml" % a) as src_proc:
171171
proc = yaml.load(src_proc, Loader=SafeLoader)
172172
self.assertEqual(proc, src)

0 commit comments

Comments
 (0)