Skip to content

Commit

Permalink
Updated Python parsers
Browse files Browse the repository at this point in the history
  • Loading branch information
GlassOfWhiskey committed Nov 3, 2023
1 parent 9a8677b commit 5f06479
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 26 deletions.
8 changes: 6 additions & 2 deletions cwl_utils/parser/cwl_v1_0.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class LoadingOptions:
cache: CacheType
imports: List[str]
includes: List[str]
no_link_check: Optional[bool]

def __init__(
self,
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
9 changes: 3 additions & 6 deletions cwl_utils/parser/cwl_v1_0_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,7 @@ def load_inputfile(
if baseuri is None:
baseuri = cwl.file_uri(os.getcwd()) + "/"

Check warning on line 322 in cwl_utils/parser/cwl_v1_0_utils.py

View check run for this annotation

Codecov / codecov/patch

cwl_utils/parser/cwl_v1_0_utils.py#L322

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

Check warning on line 325 in cwl_utils/parser/cwl_v1_0_utils.py

View check run for this annotation

Codecov / codecov/patch

cwl_utils/parser/cwl_v1_0_utils.py#L324-L325

Added lines #L324 - L325 were not covered by tests
doc,
baseuri,
Expand All @@ -342,9 +341,8 @@ def load_inputfile_by_string(
add_lc_filename(result, uri)

Check warning on line 341 in cwl_utils/parser/cwl_v1_0_utils.py

View check run for this annotation

Codecov / codecov/patch

cwl_utils/parser/cwl_v1_0_utils.py#L339-L341

Added lines #L339 - L341 were not covered by tests

if loadingOptions is None:
loadingOptions = cwl.LoadingOptions(fileuri=uri)
loadingOptions = cwl.LoadingOptions(fileuri=uri, no_link_check=True)

Check warning on line 344 in cwl_utils/parser/cwl_v1_0_utils.py

View check run for this annotation

Codecov / codecov/patch

cwl_utils/parser/cwl_v1_0_utils.py#L344

Added line #L344 was not covered by tests

loadingOptions = cwl.LoadingOptions(copyfrom=loadingOptions, no_link_check=True)
result, metadata = _inputfile_load(

Check warning on line 346 in cwl_utils/parser/cwl_v1_0_utils.py

View check run for this annotation

Codecov / codecov/patch

cwl_utils/parser/cwl_v1_0_utils.py#L346

Added line #L346 was not covered by tests
result,
uri,
Expand All @@ -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)

Check warning on line 363 in cwl_utils/parser/cwl_v1_0_utils.py

View check run for this annotation

Codecov / codecov/patch

cwl_utils/parser/cwl_v1_0_utils.py#L363

Added line #L363 was not covered by tests

loadingOptions = cwl.LoadingOptions(copyfrom=loadingOptions, no_link_check=True)
result, metadata = _inputfile_load(
yaml,
uri,
Expand Down
8 changes: 6 additions & 2 deletions cwl_utils/parser/cwl_v1_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class LoadingOptions:
cache: CacheType
imports: List[str]
includes: List[str]
no_link_check: Optional[bool]

def __init__(
self,
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
9 changes: 3 additions & 6 deletions cwl_utils/parser/cwl_v1_1_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,8 @@ def load_inputfile(
if baseuri is None:
baseuri = cwl.file_uri(os.getcwd()) + "/"

Check warning on line 338 in cwl_utils/parser/cwl_v1_1_utils.py

View check run for this annotation

Codecov / codecov/patch

cwl_utils/parser/cwl_v1_1_utils.py#L338

Added line #L338 was not covered by tests
if loadingOptions is None:
loadingOptions = cwl.LoadingOptions()
loadingOptions = cwl.LoadingOptions(no_link_check=True)

Check warning on line 340 in cwl_utils/parser/cwl_v1_1_utils.py

View check run for this annotation

Codecov / codecov/patch

cwl_utils/parser/cwl_v1_1_utils.py#L340

Added line #L340 was not covered by tests

loadingOptions = cwl.LoadingOptions(copyfrom=loadingOptions, no_link_check=True)
result, metadata = _inputfile_load(

Check warning on line 342 in cwl_utils/parser/cwl_v1_1_utils.py

View check run for this annotation

Codecov / codecov/patch

cwl_utils/parser/cwl_v1_1_utils.py#L342

Added line #L342 was not covered by tests
doc,
baseuri,
Expand All @@ -359,9 +358,8 @@ def load_inputfile_by_string(
add_lc_filename(result, uri)

Check warning on line 358 in cwl_utils/parser/cwl_v1_1_utils.py

View check run for this annotation

Codecov / codecov/patch

cwl_utils/parser/cwl_v1_1_utils.py#L356-L358

Added lines #L356 - L358 were not covered by tests

if loadingOptions is None:
loadingOptions = cwl.LoadingOptions(fileuri=uri)
loadingOptions = cwl.LoadingOptions(fileuri=uri, no_link_check=True)

Check warning on line 361 in cwl_utils/parser/cwl_v1_1_utils.py

View check run for this annotation

Codecov / codecov/patch

cwl_utils/parser/cwl_v1_1_utils.py#L361

Added line #L361 was not covered by tests

loadingOptions = cwl.LoadingOptions(copyfrom=loadingOptions, no_link_check=True)
result, metadata = _inputfile_load(

Check warning on line 363 in cwl_utils/parser/cwl_v1_1_utils.py

View check run for this annotation

Codecov / codecov/patch

cwl_utils/parser/cwl_v1_1_utils.py#L363

Added line #L363 was not covered by tests
result,
uri,
Expand All @@ -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)

Check warning on line 380 in cwl_utils/parser/cwl_v1_1_utils.py

View check run for this annotation

Codecov / codecov/patch

cwl_utils/parser/cwl_v1_1_utils.py#L380

Added line #L380 was not covered by tests

loadingOptions = cwl.LoadingOptions(copyfrom=loadingOptions, no_link_check=True)
result, metadata = _inputfile_load(
yaml,
uri,
Expand Down
8 changes: 6 additions & 2 deletions cwl_utils/parser/cwl_v1_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class LoadingOptions:
cache: CacheType
imports: List[str]
includes: List[str]
no_link_check: Optional[bool]

def __init__(
self,
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
9 changes: 3 additions & 6 deletions cwl_utils/parser/cwl_v1_2_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,9 +400,8 @@ def load_inputfile(
if baseuri is None:
baseuri = cwl.file_uri(os.getcwd()) + "/"

Check warning on line 401 in cwl_utils/parser/cwl_v1_2_utils.py

View check run for this annotation

Codecov / codecov/patch

cwl_utils/parser/cwl_v1_2_utils.py#L401

Added line #L401 was not covered by tests
if loadingOptions is None:
loadingOptions = cwl.LoadingOptions()
loadingOptions = cwl.LoadingOptions(no_link_check=True)

Check warning on line 403 in cwl_utils/parser/cwl_v1_2_utils.py

View check run for this annotation

Codecov / codecov/patch

cwl_utils/parser/cwl_v1_2_utils.py#L403

Added line #L403 was not covered by tests

loadingOptions = cwl.LoadingOptions(copyfrom=loadingOptions, no_link_check=True)
result, metadata = _inputfile_load(

Check warning on line 405 in cwl_utils/parser/cwl_v1_2_utils.py

View check run for this annotation

Codecov / codecov/patch

cwl_utils/parser/cwl_v1_2_utils.py#L405

Added line #L405 was not covered by tests
doc,
baseuri,
Expand All @@ -422,9 +421,8 @@ def load_inputfile_by_string(
add_lc_filename(result, uri)

Check warning on line 421 in cwl_utils/parser/cwl_v1_2_utils.py

View check run for this annotation

Codecov / codecov/patch

cwl_utils/parser/cwl_v1_2_utils.py#L419-L421

Added lines #L419 - L421 were not covered by tests

if loadingOptions is None:
loadingOptions = cwl.LoadingOptions(fileuri=uri)
loadingOptions = cwl.LoadingOptions(fileuri=uri, no_link_check=True)

Check warning on line 424 in cwl_utils/parser/cwl_v1_2_utils.py

View check run for this annotation

Codecov / codecov/patch

cwl_utils/parser/cwl_v1_2_utils.py#L424

Added line #L424 was not covered by tests

loadingOptions = cwl.LoadingOptions(copyfrom=loadingOptions, no_link_check=True)
result, metadata = _inputfile_load(

Check warning on line 426 in cwl_utils/parser/cwl_v1_2_utils.py

View check run for this annotation

Codecov / codecov/patch

cwl_utils/parser/cwl_v1_2_utils.py#L426

Added line #L426 was not covered by tests
result,
uri,
Expand All @@ -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)

Check warning on line 443 in cwl_utils/parser/cwl_v1_2_utils.py

View check run for this annotation

Codecov / codecov/patch

cwl_utils/parser/cwl_v1_2_utils.py#L443

Added line #L443 was not covered by tests

loadingOptions = cwl.LoadingOptions(copyfrom=loadingOptions, no_link_check=True)
result, metadata = _inputfile_load(
yaml,
uri,
Expand Down
27 changes: 25 additions & 2 deletions cwl_utils/parser/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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")

Check warning on line 79 in cwl_utils/parser/utils.py

View check run for this annotation

Codecov / codecov/patch

cwl_utils/parser/utils.py#L79

Added line #L79 was not covered by tests
else:
raise ValidationException(

Check warning on line 81 in cwl_utils/parser/utils.py

View check run for this annotation

Codecov / codecov/patch

cwl_utils/parser/utils.py#L81

Added line #L81 was not covered by tests
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)
Expand Down

0 comments on commit 5f06479

Please sign in to comment.