Skip to content

Commit 083919a

Browse files
committed
revert chagnes to cwltool/schemas/*
1 parent 76ac261 commit 083919a

File tree

10 files changed

+159
-295
lines changed

10 files changed

+159
-295
lines changed

cwltool/schemas/draft-2/draft-2/index.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
linenum = 0
1717
for l in main:
1818
linenum += 1
19-
l = l.rstrip().lower().replace(".", "").replace(
20-
",", "").replace(";", "").replace("-", " ")
19+
l = l.rstrip().lower().replace(".", "").replace(",", "").replace(";", "").replace("-", " ")
2120
for w in l.split(" "):
2221
if w:
2322
if w not in words:

cwltool/schemas/draft-3/draft-3/index.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
linenum = 0
1818
for l in main:
1919
linenum += 1
20-
l = l.rstrip().lower().replace(".", "").replace(
21-
",", "").replace(";", "").replace("-", " ")
20+
l = l.rstrip().lower().replace(".", "").replace(",", "").replace(";", "").replace("-", " ")
2221
for w in l.split(" "):
2322
if w:
2423
if w not in words:

cwltool/schemas/draft-3/salad/schema_salad/jsonld_context.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
_logger = logging.getLogger("salad")
1919

20-
2120
def pred(datatype, field, name, context, defaultBase, namespaces):
2221
split = urlparse.urlsplit(name)
2322

@@ -34,7 +33,7 @@ def pred(datatype, field, name, context, defaultBase, namespaces):
3433
if field and "jsonldPredicate" in field:
3534
if isinstance(field["jsonldPredicate"], dict):
3635
v = {("@"+k[1:] if k.startswith("_") else k): v
37-
for k,v in field["jsonldPredicate"].items()}
36+
for k,v in field["jsonldPredicate"].items() }
3837
else:
3938
v = field["jsonldPredicate"]
4039
elif "jsonldPredicate" in datatype:
@@ -52,15 +51,13 @@ def pred(datatype, field, name, context, defaultBase, namespaces):
5251

5352
if name in context:
5453
if context[name] != v:
55-
raise Exception("Predicate collision on %s, '%s' != '%s'" %
56-
(name, context[name], v))
54+
raise Exception("Predicate collision on %s, '%s' != '%s'" % (name, context[name], v))
5755
else:
5856
_logger.debug("Adding to context '%s' %s (%s)", name, v, type(v))
5957
context[name] = v
6058

6159
return v
6260

63-
6461
def process_type(t, g, context, defaultBase, namespaces, defaultPrefix):
6562
if t["type"] == "record":
6663
recordname = t["name"]
@@ -81,14 +78,12 @@ def process_type(t, g, context, defaultBase, namespaces, defaultPrefix):
8178
predicate = "%s:%s" % (defaultPrefix, recordname)
8279

8380
if context.get(recordname, predicate) != predicate:
84-
raise Exception("Predicate collision on '%s', '%s' != '%s'" %
85-
(recordname, context[t["name"]], predicate))
81+
raise Exception("Predicate collision on '%s', '%s' != '%s'" % (recordname, context[t["name"]], predicate))
8682

8783
if not recordname:
8884
raise Exception()
8985

90-
_logger.debug("Adding to context '%s' %s (%s)",
91-
recordname, predicate, type(predicate))
86+
_logger.debug("Adding to context '%s' %s (%s)", recordname, predicate, type(predicate))
9287
context[recordname] = predicate
9388

9489
for i in t.get("fields", []):
@@ -116,8 +111,7 @@ def process_type(t, g, context, defaultBase, namespaces, defaultPrefix):
116111
# TODO generate range from datatype.
117112

118113
if isinstance(i["type"], dict) and "name" in i["type"]:
119-
process_type(
120-
i["type"], g, context, defaultBase, namespaces, defaultPrefix)
114+
process_type(i["type"], g, context, defaultBase, namespaces, defaultPrefix)
121115

122116
if "extends" in t:
123117
for e in aslist(t["extends"]):

cwltool/schemas/draft-3/salad/schema_salad/main.py

Lines changed: 29 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,10 @@
2121
import rdflib_jsonld.parser
2222
register('json-ld', Parser, 'rdflib_jsonld.parser', 'JsonLDParser')
2323

24-
2524
def printrdf(workflow, wf, ctx, sr):
26-
g = Graph().parse(data=json.dumps(wf),
27-
format='json-ld', location=workflow, context=ctx)
25+
g = Graph().parse(data=json.dumps(wf), format='json-ld', location=workflow, context=ctx)
2826
print(g.serialize(format=sr))
2927

30-
3128
def main(args=None):
3229
if args is None:
3330
args = sys.argv[1:]
@@ -38,41 +35,27 @@ def main(args=None):
3835
default="turtle")
3936

4037
exgroup = parser.add_mutually_exclusive_group()
41-
exgroup.add_argument("--print-jsonld-context",
42-
action="store_true", help="Print JSON-LD context for schema")
43-
exgroup.add_argument(
44-
"--print-doc", action="store_true", help="Print HTML documentation from schema")
45-
exgroup.add_argument(
46-
"--print-rdfs", action="store_true", help="Print RDF schema")
47-
exgroup.add_argument(
48-
"--print-avro", action="store_true", help="Print Avro schema")
49-
50-
exgroup.add_argument("--print-rdf", action="store_true",
51-
help="Print corresponding RDF graph for document")
52-
exgroup.add_argument(
53-
"--print-pre", action="store_true", help="Print document after preprocessing")
54-
exgroup.add_argument(
55-
"--print-index", action="store_true", help="Print node index")
56-
exgroup.add_argument(
57-
"--print-metadata", action="store_true", help="Print document metadata")
58-
exgroup.add_argument(
59-
"--version", action="store_true", help="Print version")
38+
exgroup.add_argument("--print-jsonld-context", action="store_true", help="Print JSON-LD context for schema")
39+
exgroup.add_argument("--print-doc", action="store_true", help="Print HTML documentation from schema")
40+
exgroup.add_argument("--print-rdfs", action="store_true", help="Print RDF schema")
41+
exgroup.add_argument("--print-avro", action="store_true", help="Print Avro schema")
42+
43+
exgroup.add_argument("--print-rdf", action="store_true", help="Print corresponding RDF graph for document")
44+
exgroup.add_argument("--print-pre", action="store_true", help="Print document after preprocessing")
45+
exgroup.add_argument("--print-index", action="store_true", help="Print node index")
46+
exgroup.add_argument("--print-metadata", action="store_true", help="Print document metadata")
47+
exgroup.add_argument("--version", action="store_true", help="Print version")
6048

6149
exgroup = parser.add_mutually_exclusive_group()
62-
exgroup.add_argument(
63-
"--strict", action="store_true", help="Strict validation (unrecognized or out of place fields are error)",
50+
exgroup.add_argument("--strict", action="store_true", help="Strict validation (unrecognized or out of place fields are error)",
6451
default=True, dest="strict")
65-
exgroup.add_argument(
66-
"--non-strict", action="store_false", help="Lenient validation (ignore unrecognized fields)",
52+
exgroup.add_argument("--non-strict", action="store_false", help="Lenient validation (ignore unrecognized fields)",
6753
default=True, dest="strict")
6854

6955
exgroup = parser.add_mutually_exclusive_group()
70-
exgroup.add_argument(
71-
"--verbose", action="store_true", help="Default logging")
72-
exgroup.add_argument(
73-
"--quiet", action="store_true", help="Only print warnings and errors.")
74-
exgroup.add_argument(
75-
"--debug", action="store_true", help="Print even more logging")
56+
exgroup.add_argument("--verbose", action="store_true", help="Default logging")
57+
exgroup.add_argument("--quiet", action="store_true", help="Only print warnings and errors.")
58+
exgroup.add_argument("--debug", action="store_true", help="Print even more logging")
7659

7760
parser.add_argument("schema", type=str)
7861
parser.add_argument("document", type=str, nargs="?", default=None)
@@ -93,17 +76,15 @@ def main(args=None):
9376
_logger.info("%s %s", sys.argv[0], pkg[0].version)
9477

9578
# Get the metaschema to validate the schema
96-
metaschema_names, metaschema_doc, metaschema_loader = schema.get_metaschema(
97-
)
79+
metaschema_names, metaschema_doc, metaschema_loader = schema.get_metaschema()
9880

9981
# Load schema document and resolve refs
10082

10183
schema_uri = args.schema
10284
if not urlparse.urlparse(schema_uri)[0]:
10385
schema_uri = "file://" + os.path.abspath(schema_uri)
10486
schema_raw_doc = metaschema_loader.fetch(schema_uri)
105-
schema_doc, schema_metadata = metaschema_loader.resolve_all(
106-
schema_raw_doc, schema_uri)
87+
schema_doc, schema_metadata = metaschema_loader.resolve_all(schema_raw_doc, schema_uri)
10788

10889
# Optionally print the schema after ref resolution
10990
if not args.document and args.print_pre:
@@ -118,19 +99,16 @@ def main(args=None):
11899
try:
119100
metaschema_loader.validate_links(schema_doc)
120101
except (validate.ValidationException) as e:
121-
_logger.error("Schema `%s` failed link checking:\n%s",
122-
args.schema, e, exc_info=(e if args.debug else False))
102+
_logger.error("Schema `%s` failed link checking:\n%s", args.schema, e, exc_info=(e if args.debug else False))
123103
_logger.debug("Index is %s", metaschema_loader.idx.keys())
124104
_logger.debug("Vocabulary is %s", metaschema_loader.vocab.keys())
125105
return 1
126106

127107
# Validate the schema document against the metaschema
128108
try:
129-
schema.validate_doc(
130-
metaschema_names, schema_doc, metaschema_loader, args.strict)
109+
schema.validate_doc(metaschema_names, schema_doc, metaschema_loader, args.strict)
131110
except validate.ValidationException as e:
132-
_logger.error("While validating schema `%s`:\n%s" %
133-
(args.schema, str(e)))
111+
_logger.error("While validating schema `%s`:\n%s" % (args.schema, str(e)))
134112
return 1
135113

136114
# Get the json-ld context and RDFS representation from the schema
@@ -139,20 +117,16 @@ def main(args=None):
139117
metactx = schema_raw_doc.get("$namespaces", {})
140118
if "$base" in schema_raw_doc:
141119
metactx["@base"] = schema_raw_doc["$base"]
142-
(schema_ctx, rdfs) = jsonld_context.salad_to_jsonld_context(
143-
schema_doc, metactx)
120+
(schema_ctx, rdfs) = jsonld_context.salad_to_jsonld_context(schema_doc, metactx)
144121

145122
# Create the loader that will be used to load the target document.
146123
document_loader = Loader(schema_ctx)
147124

148-
# Make the Avro validation that will be used to validate the target
149-
# document
150-
(avsc_names, avsc_obj) = schema.make_avro_schema(
151-
schema_doc, document_loader)
125+
# Make the Avro validation that will be used to validate the target document
126+
(avsc_names, avsc_obj) = schema.make_avro_schema(schema_doc, document_loader)
152127

153128
if isinstance(avsc_names, Exception):
154-
_logger.error("Schema `%s` error:\n%s", args.schema,
155-
avsc_names, exc_info=(avsc_names if args.debug else False))
129+
_logger.error("Schema `%s` error:\n%s", args.schema, avsc_names, exc_info=(avsc_names if args.debug else False))
156130
if args.print_avro:
157131
print json.dumps(avsc_obj, indent=4)
158132
return 1
@@ -194,8 +168,7 @@ def main(args=None):
194168
doc = "file://" + os.path.abspath(uri)
195169
document, doc_metadata = document_loader.resolve_ref(uri)
196170
except (validate.ValidationException, RuntimeError) as e:
197-
_logger.error("Document `%s` failed validation:\n%s",
198-
args.document, e, exc_info=(e if args.debug else False))
171+
_logger.error("Document `%s` failed validation:\n%s", args.document, e, exc_info=(e if args.debug else False))
199172
return 1
200173

201174
# Optionally print the document after ref resolution
@@ -211,18 +184,15 @@ def main(args=None):
211184
try:
212185
document_loader.validate_links(document)
213186
except (validate.ValidationException) as e:
214-
_logger.error("Document `%s` failed link checking:\n%s",
215-
args.document, e, exc_info=(e if args.debug else False))
216-
_logger.debug("Index is %s", json.dumps(
217-
document_loader.idx.keys(), indent=4))
187+
_logger.error("Document `%s` failed link checking:\n%s", args.document, e, exc_info=(e if args.debug else False))
188+
_logger.debug("Index is %s", json.dumps(document_loader.idx.keys(), indent=4))
218189
return 1
219190

220191
# Validate the schema document against the metaschema
221192
try:
222193
schema.validate_doc(avsc_names, document, document_loader, args.strict)
223194
except validate.ValidationException as e:
224-
_logger.error("While validating document `%s`:\n%s" %
225-
(args.document, str(e)))
195+
_logger.error("While validating document `%s`:\n%s" % (args.document, str(e)))
226196
return 1
227197

228198
# Optionally convert the document to RDF

0 commit comments

Comments
 (0)