Skip to content

Commit 5fdce36

Browse files
committed
enable loading all parts of a $graph document
Fixes: #200
1 parent 0ce4ab5 commit 5fdce36

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

cwl_utils/parser/__init__.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ def cwl_version(yaml: Any) -> Optional[str]:
134134
def load_document_by_uri(
135135
path: Union[str, Path],
136136
loadingOptions: Optional[LoadingOptions] = None,
137+
load_all: bool = False,
137138
) -> Any:
138139
"""Load a CWL object from a URI or a path."""
139140
if isinstance(path, str):
@@ -153,44 +154,47 @@ def load_document_by_uri(
153154
loadingOptions = cwl_v1_2.LoadingOptions(fileuri=baseuri)
154155

155156
doc = loadingOptions.fetcher.fetch_text(real_path)
156-
return load_document_by_string(doc, baseuri, loadingOptions, id_)
157+
return load_document_by_string(doc, baseuri, loadingOptions, id_, load_all)
157158

158159

159160
def load_document(
160161
doc: Any,
161162
baseuri: Optional[str] = None,
162163
loadingOptions: Optional[LoadingOptions] = None,
163164
id_: Optional[str] = None,
165+
load_all: bool = False,
164166
) -> Any:
165167
"""Load a CWL object from a serialized YAML string or a YAML object."""
166168
if baseuri is None:
167169
baseuri = cwl_v1_0.file_uri(os.getcwd()) + "/"
168170
if isinstance(doc, str):
169171
return load_document_by_string(doc, baseuri, loadingOptions, id_)
170-
return load_document_by_yaml(doc, baseuri, loadingOptions, id_)
172+
return load_document_by_yaml(doc, baseuri, loadingOptions, id_, load_all)
171173

172174

173175
def load_document_by_string(
174176
string: str,
175177
uri: str,
176178
loadingOptions: Optional[LoadingOptions] = None,
177179
id_: Optional[str] = None,
180+
load_all: bool = False,
178181
) -> Any:
179182
"""Load a CWL object from a serialized YAML string."""
180183
yaml = yaml_no_ts()
181184
result = yaml.load(string)
182-
return load_document_by_yaml(result, uri, loadingOptions, id_)
185+
return load_document_by_yaml(result, uri, loadingOptions, id_, load_all)
183186

184187

185188
def load_document_by_yaml(
186189
yaml: Any,
187190
uri: str,
188191
loadingOptions: Optional[LoadingOptions] = None,
189192
id_: Optional[str] = None,
193+
load_all: bool = False,
190194
) -> Any:
191195
"""Load a CWL object from a YAML object."""
192196
version = cwl_version(yaml)
193-
if "$graph" in yaml:
197+
if "$graph" in yaml and not load_all:
194198
yaml = _get_id_from_graph(yaml, id_)
195199
yaml["cwlVersion"] = version
196200
if version == "v1.0":

tests/test_parser.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,10 @@ def test_get_default_id_from_graph_without_main() -> None:
114114
with raises(GraphTargetMissingException):
115115
uri = Path(get_data("testdata/js-expr-req-wf.cwl")).resolve().as_uri()
116116
load_document_by_uri(uri)
117+
118+
119+
def test_graph_load_all() -> None:
120+
"""Test that we can get all object in a $graph file."""
121+
uri = Path(get_data("testdata/js-expr-req-wf.cwl")).resolve().as_uri()
122+
cwl_objs = load_document_by_uri(uri, load_all=True)
123+
assert len(cwl_objs) == 2

0 commit comments

Comments
 (0)