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 committed Dec 17, 2024
1 parent b926e33 commit 3da0300
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions cwl_utils/parser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,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 @@ -248,8 +246,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(

Check warning on line 264 in cwl_utils/parser/__init__.py

View check run for this annotation

Codecov / codecov/patch

cwl_utils/parser/__init__.py#L264

Added line #L264 was not covered by tests
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

0 comments on commit 3da0300

Please sign in to comment.