|
1 | 1 | import copy
|
2 | 2 | import logging
|
3 | 3 | 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) |
17 | 5 |
|
18 | 6 | 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 |
21 | 9 | from ruamel.yaml.comments import CommentedMap
|
22 | 10 | from schema_salad.avro.schema import Names, Schema, make_avsc_object
|
23 | 11 | from schema_salad.exceptions import ValidationException
|
@@ -76,64 +64,6 @@ def substitute(value, replace): # type: (str, str) -> str
|
76 | 64 | return value + replace
|
77 | 65 |
|
78 | 66 |
|
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 |
| - |
137 | 67 | class Builder(HasReqsHints):
|
138 | 68 | def __init__(
|
139 | 69 | self,
|
|
0 commit comments