From fab4251b17e990bb3e7b3ff646e51c8ac110ee48 Mon Sep 17 00:00:00 2001 From: GlassOfWhiskey Date: Tue, 17 Dec 2024 13:38:36 +0100 Subject: [PATCH] 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`. --- cwl_utils/parser/__init__.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/cwl_utils/parser/__init__.py b/cwl_utils/parser/__init__.py index 36d977b1..74ebd5bc 100644 --- a/cwl_utils/parser/__init__.py +++ b/cwl_utils/parser/__init__.py @@ -46,6 +46,8 @@ cwl_v1_2.InputRecordSchema, ] """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 ] @@ -232,8 +234,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 @@ -248,8 +248,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)