Skip to content

Commit fab4251

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 fab4251

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
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)

0 commit comments

Comments
 (0)