From 5f06479ba592395519e413c4b577985d6cde9428 Mon Sep 17 00:00:00 2001 From: GlassOfWhiskey Date: Fri, 3 Nov 2023 00:50:20 +0100 Subject: [PATCH] Updated Python parsers --- cwl_utils/parser/cwl_v1_0.py | 8 ++++++-- cwl_utils/parser/cwl_v1_0_utils.py | 9 +++------ cwl_utils/parser/cwl_v1_1.py | 8 ++++++-- cwl_utils/parser/cwl_v1_1_utils.py | 9 +++------ cwl_utils/parser/cwl_v1_2.py | 8 ++++++-- cwl_utils/parser/cwl_v1_2_utils.py | 9 +++------ cwl_utils/parser/utils.py | 27 +++++++++++++++++++++++++-- 7 files changed, 52 insertions(+), 26 deletions(-) diff --git a/cwl_utils/parser/cwl_v1_0.py b/cwl_utils/parser/cwl_v1_0.py index 6df9537f..054b13d3 100644 --- a/cwl_utils/parser/cwl_v1_0.py +++ b/cwl_utils/parser/cwl_v1_0.py @@ -60,6 +60,7 @@ class LoadingOptions: cache: CacheType imports: List[str] includes: List[str] + no_link_check: Optional[bool] def __init__( self, @@ -74,7 +75,7 @@ def __init__( idx: Optional[IdxType] = None, imports: Optional[List[str]] = None, includes: Optional[List[str]] = None, - no_link_check: bool = False, + no_link_check: Optional[bool] = None, ) -> None: """Create a LoadingOptions object.""" self.original_doc = original_doc @@ -119,7 +120,10 @@ def __init__( else: self.includes = copyfrom.includes if copyfrom is not None else [] - self.no_link_check = no_link_check + if no_link_check is not None: + self.no_link_check = no_link_check + else: + self.no_link_check = copyfrom.no_link_check if copyfrom is not None else False if fetcher is not None: self.fetcher = fetcher diff --git a/cwl_utils/parser/cwl_v1_0_utils.py b/cwl_utils/parser/cwl_v1_0_utils.py index 30ee5e56..d649f1ca 100644 --- a/cwl_utils/parser/cwl_v1_0_utils.py +++ b/cwl_utils/parser/cwl_v1_0_utils.py @@ -321,8 +321,7 @@ def load_inputfile( if baseuri is None: baseuri = cwl.file_uri(os.getcwd()) + "/" if loadingOptions is None: - loadingOptions = cwl.LoadingOptions() - loadingOptions = cwl.LoadingOptions(copyfrom=loadingOptions, no_link_check=True) + loadingOptions = cwl.LoadingOptions(no_link_check=True) result, metadata = _inputfile_load( doc, baseuri, @@ -342,9 +341,8 @@ def load_inputfile_by_string( add_lc_filename(result, uri) if loadingOptions is None: - loadingOptions = cwl.LoadingOptions(fileuri=uri) + loadingOptions = cwl.LoadingOptions(fileuri=uri, no_link_check=True) - loadingOptions = cwl.LoadingOptions(copyfrom=loadingOptions, no_link_check=True) result, metadata = _inputfile_load( result, uri, @@ -362,9 +360,8 @@ def load_inputfile_by_yaml( add_lc_filename(yaml, uri) if loadingOptions is None: - loadingOptions = cwl.LoadingOptions(fileuri=uri) + loadingOptions = cwl.LoadingOptions(fileuri=uri, no_link_check=True) - loadingOptions = cwl.LoadingOptions(copyfrom=loadingOptions, no_link_check=True) result, metadata = _inputfile_load( yaml, uri, diff --git a/cwl_utils/parser/cwl_v1_1.py b/cwl_utils/parser/cwl_v1_1.py index 26ba854e..47dd088a 100644 --- a/cwl_utils/parser/cwl_v1_1.py +++ b/cwl_utils/parser/cwl_v1_1.py @@ -60,6 +60,7 @@ class LoadingOptions: cache: CacheType imports: List[str] includes: List[str] + no_link_check: Optional[bool] def __init__( self, @@ -74,7 +75,7 @@ def __init__( idx: Optional[IdxType] = None, imports: Optional[List[str]] = None, includes: Optional[List[str]] = None, - no_link_check: bool = False, + no_link_check: Optional[bool] = None, ) -> None: """Create a LoadingOptions object.""" self.original_doc = original_doc @@ -119,7 +120,10 @@ def __init__( else: self.includes = copyfrom.includes if copyfrom is not None else [] - self.no_link_check = no_link_check + if no_link_check is not None: + self.no_link_check = no_link_check + else: + self.no_link_check = copyfrom.no_link_check if copyfrom is not None else False if fetcher is not None: self.fetcher = fetcher diff --git a/cwl_utils/parser/cwl_v1_1_utils.py b/cwl_utils/parser/cwl_v1_1_utils.py index 87d5c1d8..91ef994e 100644 --- a/cwl_utils/parser/cwl_v1_1_utils.py +++ b/cwl_utils/parser/cwl_v1_1_utils.py @@ -337,9 +337,8 @@ def load_inputfile( if baseuri is None: baseuri = cwl.file_uri(os.getcwd()) + "/" if loadingOptions is None: - loadingOptions = cwl.LoadingOptions() + loadingOptions = cwl.LoadingOptions(no_link_check=True) - loadingOptions = cwl.LoadingOptions(copyfrom=loadingOptions, no_link_check=True) result, metadata = _inputfile_load( doc, baseuri, @@ -359,9 +358,8 @@ def load_inputfile_by_string( add_lc_filename(result, uri) if loadingOptions is None: - loadingOptions = cwl.LoadingOptions(fileuri=uri) + loadingOptions = cwl.LoadingOptions(fileuri=uri, no_link_check=True) - loadingOptions = cwl.LoadingOptions(copyfrom=loadingOptions, no_link_check=True) result, metadata = _inputfile_load( result, uri, @@ -379,9 +377,8 @@ def load_inputfile_by_yaml( add_lc_filename(yaml, uri) if loadingOptions is None: - loadingOptions = cwl.LoadingOptions(fileuri=uri) + loadingOptions = cwl.LoadingOptions(fileuri=uri, no_link_check=True) - loadingOptions = cwl.LoadingOptions(copyfrom=loadingOptions, no_link_check=True) result, metadata = _inputfile_load( yaml, uri, diff --git a/cwl_utils/parser/cwl_v1_2.py b/cwl_utils/parser/cwl_v1_2.py index 94b02aa2..2cbbc3a2 100644 --- a/cwl_utils/parser/cwl_v1_2.py +++ b/cwl_utils/parser/cwl_v1_2.py @@ -60,6 +60,7 @@ class LoadingOptions: cache: CacheType imports: List[str] includes: List[str] + no_link_check: Optional[bool] def __init__( self, @@ -74,7 +75,7 @@ def __init__( idx: Optional[IdxType] = None, imports: Optional[List[str]] = None, includes: Optional[List[str]] = None, - no_link_check: bool = False, + no_link_check: Optional[bool] = None, ) -> None: """Create a LoadingOptions object.""" self.original_doc = original_doc @@ -119,7 +120,10 @@ def __init__( else: self.includes = copyfrom.includes if copyfrom is not None else [] - self.no_link_check = no_link_check + if no_link_check is not None: + self.no_link_check = no_link_check + else: + self.no_link_check = copyfrom.no_link_check if copyfrom is not None else False if fetcher is not None: self.fetcher = fetcher diff --git a/cwl_utils/parser/cwl_v1_2_utils.py b/cwl_utils/parser/cwl_v1_2_utils.py index 045e5864..9de3a6ec 100644 --- a/cwl_utils/parser/cwl_v1_2_utils.py +++ b/cwl_utils/parser/cwl_v1_2_utils.py @@ -400,9 +400,8 @@ def load_inputfile( if baseuri is None: baseuri = cwl.file_uri(os.getcwd()) + "/" if loadingOptions is None: - loadingOptions = cwl.LoadingOptions() + loadingOptions = cwl.LoadingOptions(no_link_check=True) - loadingOptions = cwl.LoadingOptions(copyfrom=loadingOptions, no_link_check=True) result, metadata = _inputfile_load( doc, baseuri, @@ -422,9 +421,8 @@ def load_inputfile_by_string( add_lc_filename(result, uri) if loadingOptions is None: - loadingOptions = cwl.LoadingOptions(fileuri=uri) + loadingOptions = cwl.LoadingOptions(fileuri=uri, no_link_check=True) - loadingOptions = cwl.LoadingOptions(copyfrom=loadingOptions, no_link_check=True) result, metadata = _inputfile_load( result, uri, @@ -442,9 +440,8 @@ def load_inputfile_by_yaml( add_lc_filename(yaml, uri) if loadingOptions is None: - loadingOptions = cwl.LoadingOptions(fileuri=uri) + loadingOptions = cwl.LoadingOptions(fileuri=uri, no_link_check=True) - loadingOptions = cwl.LoadingOptions(copyfrom=loadingOptions, no_link_check=True) result, metadata = _inputfile_load( yaml, uri, diff --git a/cwl_utils/parser/utils.py b/cwl_utils/parser/utils.py index 2416340a..c01be7af 100644 --- a/cwl_utils/parser/utils.py +++ b/cwl_utils/parser/utils.py @@ -12,6 +12,7 @@ from schema_salad.utils import json_dumps, yaml_no_ts import cwl_utils +import cwl_utils.parser from . import ( LoadingOptions, Process, @@ -56,8 +57,30 @@ def load_inputfile_by_uri( baseuri = str(real_path) - if loadingOptions is None: - loadingOptions = cwl_v1_2.LoadingOptions(fileuri=baseuri) + if version == "v1.0": + loadingOptions = cwl_v1_0.LoadingOptions( + copyfrom=cast(Optional[cwl_v1_0.LoadingOptions], loadingOptions), + fileuri=loadingOptions.baseuri if loadingOptions is not None else baseuri, + no_link_check=True, + ) + elif version == "v1.1": + loadingOptions = cwl_v1_1.LoadingOptions( + copyfrom=cast(Optional[cwl_v1_1.LoadingOptions], loadingOptions), + fileuri=loadingOptions.baseuri if loadingOptions is not None else baseuri, + no_link_check=True, + ) + elif version == "v1.2": + loadingOptions = cwl_v1_2.LoadingOptions( + copyfrom=cast(Optional[cwl_v1_2.LoadingOptions], loadingOptions), + fileuri=loadingOptions.baseuri if loadingOptions is not None else baseuri, + no_link_check=True, + ) + elif version is None: + raise ValidationException("could not get the cwlVersion") + else: + raise ValidationException( + f"Version error. Did not recognise {version} as a CWL version" + ) doc = loadingOptions.fetcher.fetch_text(real_path) return load_inputfile_by_string(version, doc, baseuri, loadingOptions)