Skip to content

Commit 0e2ced5

Browse files
Import check_format from cwl-utils (#1717)
1 parent 49fc1c3 commit 0e2ced5

File tree

4 files changed

+5
-64
lines changed

4 files changed

+5
-64
lines changed

cwltool/builder.py

+2-61
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,

mypy-requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
mypy==0.971
22
ruamel.yaml>=0.16.0,<0.17.22
33
schema-salad>=8.2.20211104054942,<9
4-
cwl-utils>=0.14
4+
cwl-utils>=0.15
55
types-requests
66
types-setuptools
77
types-psutil

requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ pydot>=1.4.1
1515
argcomplete>=1.12.0
1616
pyparsing != 3.0.2 # breaks --print-dot (pydot) https://github.com/pyparsing/pyparsing/issues/319
1717
pyparsing < 3;python_version<='3.6' # breaks --print-dot
18-
cwl-utils>=0.14
18+
cwl-utils>=0.15

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121
"pyparsing != 3.0.2", # breaks --print-dot (pydot) https://github.com/pyparsing/pyparsing/issues/319
122122
"pyparsing < 3 ;python_version<='3.6'", # breaks --print-dot (pydot)
123123
"argcomplete",
124-
"cwl-utils >= 0.14",
124+
"cwl-utils >= 0.15",
125125
],
126126
extras_require={
127127
"deps": ["galaxy-tool-util >= 21.1.0"],

0 commit comments

Comments
 (0)