Skip to content

Commit 9359e56

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 9359e56

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

cwl_utils/parser/__init__.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@
4646
cwl_v1_2.InputRecordSchema,
4747
]
4848
"""Type union for a CWL v1.x InputRecordSchema object."""
49+
InputSchema = Union[
50+
cwl_v1_0.InputSchema, cwl_v1_1.InputSchema, cwl_v1_2.InputSchema
51+
]
52+
"""Type union for a CWL v1.x InputSchema object."""
4953
OutputParameter = Union[
5054
cwl_v1_0.OutputParameter, cwl_v1_1.OutputParameter, cwl_v1_2.OutputParameter
5155
]
@@ -232,8 +236,6 @@ def load_document_by_uri(
232236
load_all: bool = False,
233237
) -> Any:
234238
"""Load a CWL object from a URI or a path."""
235-
base_uri = ""
236-
real_uri = ""
237239
if isinstance(path, str):
238240
uri = urlparse(path)
239241
id_ = uri.fragment or None
@@ -248,8 +250,24 @@ def load_document_by_uri(
248250
base_uri = path.resolve().parent.as_uri()
249251
id_ = path.resolve().name.split("#")[1] if "#" in path.resolve().name else None
250252

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

254272
doc = loadingOptions.fetcher.fetch_text(real_uri)
255273
return load_document_by_string(doc, real_uri, loadingOptions, id_, load_all)

0 commit comments

Comments
 (0)