Skip to content

Commit 0561b73

Browse files
GlassOfWhiskeymr-c
authored andcommitted
Import check_format from cwl-utils
1 parent 49fc1c3 commit 0561b73

File tree

1 file changed

+2
-61
lines changed

1 file changed

+2
-61
lines changed

cwltool/builder.py

Lines changed: 2 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,13 @@
1010
MutableMapping,
1111
MutableSequence,
1212
Optional,
13-
Set,
1413
Union,
1514
cast,
1615
)
1716

1817
from cwl_utils import expression
19-
from rdflib import Graph, URIRef
20-
from rdflib.namespace import OWL, RDFS
18+
from cwl_utils.file_formats import check_format
19+
from rdflib import Graph
2120
from ruamel.yaml.comments import CommentedMap
2221
from schema_salad.avro.schema import Names, Schema, make_avsc_object
2322
from schema_salad.exceptions import ValidationException
@@ -76,64 +75,6 @@ def substitute(value, replace): # type: (str, str) -> str
7675
return value + replace
7776

7877

79-
def formatSubclassOf(
80-
fmt: str, cls: str, ontology: Optional[Graph], visited: Set[str]
81-
) -> bool:
82-
"""Determine if `fmt` is a subclass of `cls`."""
83-
if URIRef(fmt) == URIRef(cls):
84-
return True
85-
86-
if ontology is None:
87-
return False
88-
89-
if fmt in visited:
90-
return False
91-
92-
visited.add(fmt)
93-
94-
uriRefFmt = URIRef(fmt)
95-
96-
for _s, _p, o in ontology.triples((uriRefFmt, RDFS.subClassOf, None)):
97-
# Find parent classes of `fmt` and search upward
98-
if formatSubclassOf(o, cls, ontology, visited):
99-
return True
100-
101-
for _s, _p, o in ontology.triples((uriRefFmt, OWL.equivalentClass, None)):
102-
# Find equivalent classes of `fmt` and search horizontally
103-
if formatSubclassOf(o, cls, ontology, visited):
104-
return True
105-
106-
for s, _p, _o in ontology.triples((None, OWL.equivalentClass, uriRefFmt)):
107-
# Find equivalent classes of `fmt` and search horizontally
108-
if formatSubclassOf(s, cls, ontology, visited):
109-
return True
110-
111-
return False
112-
113-
114-
def check_format(
115-
actual_file: Union[CWLObjectType, List[CWLObjectType]],
116-
input_formats: Union[List[str], str],
117-
ontology: Optional[Graph],
118-
) -> None:
119-
"""Confirm that the format present is valid for the allowed formats."""
120-
for afile in aslist(actual_file):
121-
if not afile:
122-
continue
123-
if "format" not in afile:
124-
raise ValidationException(
125-
f"File has no 'format' defined: {json_dumps(afile, indent=4)}"
126-
)
127-
for inpf in aslist(input_formats):
128-
if afile["format"] == inpf or formatSubclassOf(
129-
afile["format"], inpf, ontology, set()
130-
):
131-
return
132-
raise ValidationException(
133-
f"File has an incompatible format: {json_dumps(afile, indent=4)}"
134-
)
135-
136-
13778
class Builder(HasReqsHints):
13879
def __init__(
13980
self,

0 commit comments

Comments
 (0)