Skip to content

Commit

Permalink
Fix load_document_by_uri method
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
GlassOfWhiskey authored and mr-c committed Dec 25, 2024
1 parent 3fbfa1b commit 33a706b
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 8 deletions.
22 changes: 19 additions & 3 deletions cwl_utils/parser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
cwl_v1_2.InputRecordField,
]
"""Type union for a CWL v1.x InputRecordSchema object."""
InputSchema = Union[cwl_v1_0.InputSchema, cwl_v1_1.InputSchema, cwl_v1_2.InputSchema]
"""Type union for a CWL v1.x InputSchema object."""
OutputParameter = Union[
cwl_v1_0.OutputParameter, cwl_v1_1.OutputParameter, cwl_v1_2.OutputParameter
]
Expand Down Expand Up @@ -243,8 +245,6 @@ def load_document_by_uri(
load_all: bool = False,
) -> Any:
"""Load a CWL object from a URI or a path."""
base_uri = ""
real_uri = ""
if isinstance(path, str):
uri = urlparse(path)
id_ = uri.fragment or None
Expand All @@ -259,8 +259,24 @@ def load_document_by_uri(
base_uri = path.resolve().parent.as_uri()
id_ = path.resolve().name.split("#")[1] if "#" in path.resolve().name else None

if loadingOptions is None:
if isinstance(loadingOptions, cwl_v1_0.LoadingOptions):
loadingOptions = cwl_v1_0.LoadingOptions(
fileuri=real_uri, baseuri=base_uri, copyfrom=loadingOptions
)
elif isinstance(loadingOptions, cwl_v1_1.LoadingOptions):
loadingOptions = cwl_v1_1.LoadingOptions(
fileuri=real_uri, baseuri=base_uri, copyfrom=loadingOptions
)
elif isinstance(loadingOptions, cwl_v1_2.LoadingOptions):
loadingOptions = cwl_v1_2.LoadingOptions(
fileuri=real_uri, baseuri=base_uri, copyfrom=loadingOptions
)
elif loadingOptions is None:
loadingOptions = cwl_v1_2.LoadingOptions(fileuri=real_uri, baseuri=base_uri)
else:
raise ValidationException(
f"Unsupported loadingOptions type: {type(loadingOptions)}"
)

doc = loadingOptions.fetcher.fetch_text(real_uri)
return load_document_by_string(doc, real_uri, loadingOptions, id_, load_all)
Expand Down
2 changes: 1 addition & 1 deletion testdata/remote-cwl/tool1.cwl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# We have this tool to test both local and remote packing

class: CommandLineTool
cwlVersion: v1.0
cwlVersion: v1.2
inputs:
in1:
type: string
Expand Down
2 changes: 1 addition & 1 deletion testdata/remote-cwl/tool2.cwl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# We have this tool to test both local and remote packing

class: CommandLineTool
cwlVersion: v1.0
cwlVersion: v1.2
inputs:
in1:
type: ../types/testtypes.yml#my_boolean_array
Expand Down
2 changes: 1 addition & 1 deletion testdata/remote-cwl/wf1.cwl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env cwl-runner
class: Workflow
cwlVersion: v1.0
cwlVersion: v1.2
inputs:
- id: in1
type: ../types/testtypes.yml#my_boolean_array
Expand Down
2 changes: 1 addition & 1 deletion testdata/wf2.cwl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env cwl-runner
class: Workflow
cwlVersion: v1.0
cwlVersion: v1.2
inputs:
in1: types/testtypes.yml#my_boolean_array
in2:
Expand Down
2 changes: 1 addition & 1 deletion testdata/workflows/wf5.cwl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Checks symbolic links on github

class: Workflow
cwlVersion: v1.0
cwlVersion: v1.2
inputs:
in1:
type: ../types/recursive.yml#file_with_sample_meta
Expand Down
1 change: 1 addition & 0 deletions tests/test_parser_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ def test_static_checker_success(cwlVersion: str) -> None:
"testdata/cond-single-source-wf-005.1.cwl",
"testdata/extensions/all-output-loop_v1_2.cwl",
"testdata/extensions/single-var-loop_v1_2.cwl",
"testdata/wf2.cwl",
]
)
for test_file in test_files:
Expand Down

0 comments on commit 33a706b

Please sign in to comment.