Skip to content

Commit 9ebc741

Browse files
Fix load_document_by_uri method
This commit adjusts the `load_document_by_uri` method, ensuring that the `LoadingOptions` object used to parse the document contains the correct values for `fileuri` and `baseuri`.
1 parent b926e33 commit 9ebc741

File tree

7 files changed

+25
-8
lines changed

7 files changed

+25
-8
lines changed

cwl_utils/parser/__init__.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
cwl_v1_2.InputRecordSchema,
4747
]
4848
"""Type union for a CWL v1.x InputRecordSchema object."""
49+
InputSchema = Union[cwl_v1_0.InputSchema, cwl_v1_1.InputSchema, cwl_v1_2.InputSchema]
50+
"""Type union for a CWL v1.x InputSchema object."""
4951
OutputParameter = Union[
5052
cwl_v1_0.OutputParameter, cwl_v1_1.OutputParameter, cwl_v1_2.OutputParameter
5153
]
@@ -232,8 +234,6 @@ def load_document_by_uri(
232234
load_all: bool = False,
233235
) -> Any:
234236
"""Load a CWL object from a URI or a path."""
235-
base_uri = ""
236-
real_uri = ""
237237
if isinstance(path, str):
238238
uri = urlparse(path)
239239
id_ = uri.fragment or None
@@ -248,8 +248,24 @@ def load_document_by_uri(
248248
base_uri = path.resolve().parent.as_uri()
249249
id_ = path.resolve().name.split("#")[1] if "#" in path.resolve().name else None
250250

251-
if loadingOptions is None:
251+
if isinstance(loadingOptions, cwl_v1_0.LoadingOptions):
252+
loadingOptions = cwl_v1_0.LoadingOptions(
253+
fileuri=real_uri, baseuri=base_uri, copyfrom=loadingOptions
254+
)
255+
elif isinstance(loadingOptions, cwl_v1_1.LoadingOptions):
256+
loadingOptions = cwl_v1_1.LoadingOptions(
257+
fileuri=real_uri, baseuri=base_uri, copyfrom=loadingOptions
258+
)
259+
elif isinstance(loadingOptions, cwl_v1_2.LoadingOptions):
260+
loadingOptions = cwl_v1_2.LoadingOptions(
261+
fileuri=real_uri, baseuri=base_uri, copyfrom=loadingOptions
262+
)
263+
elif loadingOptions is None:
252264
loadingOptions = cwl_v1_2.LoadingOptions(fileuri=real_uri, baseuri=base_uri)
265+
else:
266+
raise ValidationException(
267+
f"Unsupported loadingOptions type: {type(loadingOptions)}"
268+
)
253269

254270
doc = loadingOptions.fetcher.fetch_text(real_uri)
255271
return load_document_by_string(doc, real_uri, loadingOptions, id_, load_all)

testdata/remote-cwl/tool1.cwl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# We have this tool to test both local and remote packing
33

44
class: CommandLineTool
5-
cwlVersion: v1.0
5+
cwlVersion: v1.2
66
inputs:
77
in1:
88
type: string

testdata/remote-cwl/tool2.cwl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# We have this tool to test both local and remote packing
33

44
class: CommandLineTool
5-
cwlVersion: v1.0
5+
cwlVersion: v1.2
66
inputs:
77
in1:
88
type: ../types/testtypes.yml#my_boolean_array

testdata/remote-cwl/wf1.cwl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env cwl-runner
22
class: Workflow
3-
cwlVersion: v1.0
3+
cwlVersion: v1.2
44
inputs:
55
- id: in1
66
type: ../types/testtypes.yml#my_boolean_array

testdata/wf2.cwl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env cwl-runner
22
class: Workflow
3-
cwlVersion: v1.0
3+
cwlVersion: v1.2
44
inputs:
55
in1: types/testtypes.yml#my_boolean_array
66
in2:

testdata/workflows/wf5.cwl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Checks symbolic links on github
33

44
class: Workflow
5-
cwlVersion: v1.0
5+
cwlVersion: v1.2
66
inputs:
77
in1:
88
type: ../types/recursive.yml#file_with_sample_meta

tests/test_parser_utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ def test_static_checker_success(cwlVersion: str) -> None:
105105
"testdata/cond-single-source-wf-005.1.cwl",
106106
"testdata/extensions/all-output-loop_v1_2.cwl",
107107
"testdata/extensions/single-var-loop_v1_2.cwl",
108+
"testdata/wf2.cwl",
108109
]
109110
)
110111
for test_file in test_files:

0 commit comments

Comments
 (0)