Skip to content

Commit d17112c

Browse files
GlassOfWhiskeymr-c
authored andcommitted
Import check_format from cwl-utils
1 parent 79fd363 commit d17112c

File tree

1 file changed

+3
-73
lines changed

1 file changed

+3
-73
lines changed

cwltool/builder.py

Lines changed: 3 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,11 @@
11
import copy
22
import logging
33
import math
4-
from typing import (
5-
IO,
6-
Any,
7-
Callable,
8-
Dict,
9-
List,
10-
MutableMapping,
11-
MutableSequence,
12-
Optional,
13-
Set,
14-
Union,
15-
cast,
16-
)
4+
from typing import (Any, Callable, Dict, IO, List, MutableMapping, MutableSequence, Optional, Union, cast)
175

186
from cwl_utils import expression
19-
from rdflib import Graph, URIRef
20-
from rdflib.namespace import OWL, RDFS
7+
from cwl_utils.format import check_format
8+
from rdflib import Graph
219
from ruamel.yaml.comments import CommentedMap
2210
from schema_salad.avro.schema import Names, Schema, make_avsc_object
2311
from schema_salad.exceptions import ValidationException
@@ -76,64 +64,6 @@ def substitute(value, replace): # type: (str, str) -> str
7664
return value + replace
7765

7866

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-
13767
class Builder(HasReqsHints):
13868
def __init__(
13969
self,

0 commit comments

Comments
 (0)