Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #77: Unify v1*_only parameter into target_version #79

Merged
merged 7 commits into from
Nov 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 46 additions & 11 deletions cwlupgrader/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,43 +76,78 @@ def run(args: argparse.Namespace) -> int:
if args.v1_1_only:
_logger.info("Skipping v1.1 document as requested: %s.", path)
continue

if args.v1_only:
target_version = "v1.0"
elif args.v1_1_only:
target_version = "v1.1"
else:
target_version = "latest"
upgraded_document = upgrade_document(
document, args.v1_only, args.v1_1_only, args.dir, imports
document,
args.dir,
target_version=target_version,
imports=imports,
)
write_cwl_document(upgraded_document, Path(path).name, args.dir)
return 0


def upgrade_document(
document: Any, v1_only: bool, v1_1_only: bool, output_dir: str, imports: Set[str]
document: Any,
output_dir: str,
target_version: Optional[str] = "latest",
imports: Optional[Set[str]] = None,
) -> Any:
if imports is None:
imports = set()
supported_versions = ["v1.0", "v1.1", "v1.2", "latest"]
if target_version not in supported_versions:
_logger.error(f"Unsupported target cwlVersion: {target_version}")
return
version = document["cwlVersion"]
if version == "cwl:draft-3" or version == "draft-3":
if v1_only:
if target_version == "v1.0":
main_updater = draft3_to_v1_0
inner_updater = _draft3_to_v1_0
elif v1_1_only:
elif target_version == "v1.1":
main_updater = draft3_to_v1_1
inner_updater = _draft3_to_v1_1
else:
elif target_version == "v1.2":
main_updater = draft3_to_v1_2
inner_updater = _draft3_to_v1_2
elif target_version == "latest":
main_updater = draft3_to_v1_2
inner_updater = _draft3_to_v1_2
else:
pass # does not happen
elif version == "v1.0":
if v1_only:
if target_version == "v1.0":
_logger.info("Skipping v1.0 document as requested.")
return
elif v1_1_only:
elif target_version == "v1.1":
main_updater = v1_0_to_v1_1
inner_updater = _v1_0_to_v1_1
else:
elif target_version == "v1.2":
main_updater = v1_0_to_v1_2
inner_updater = _v1_0_to_v1_2
elif target_version == "latest":
main_updater = v1_0_to_v1_2
inner_updater = _v1_0_to_v1_2
else:
pass # does not happen
elif version == "v1.1":
if v1_1_only:
if target_version == "v1.1":
_logger.info("Skipping v1.1 document as requested.")
return
main_updater = v1_1_to_v1_2
inner_updater = _v1_1_to_v1_2
elif target_version == "v1.2":
main_updater = v1_1_to_v1_2
inner_updater = _v1_1_to_v1_2
elif target_version == "latest":
main_updater = v1_1_to_v1_2
inner_updater = _v1_1_to_v1_2
else:
pass # does not happen? How to do the case that base version is v1.0?
else:
_logger.error(f"Unsupported cwlVersion: {version}")
process_imports(document, imports, inner_updater, output_dir)
Expand Down
13 changes: 13 additions & 0 deletions testdata/v1.0/listing_deep1.cwl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env cwl-runner
class: CommandLineTool
cwlVersion: v1.0
requirements:
InlineJavascriptRequirement: {}
inputs:
d: Directory
outputs:
out:
type: boolean
outputBinding:
outputEval: '$(inputs.d.listing.length === 1 && inputs.d.listing[0].listing.length === 1)'
baseCommand: "true"
15 changes: 15 additions & 0 deletions testdata/v1.1/listing_deep1.cwl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env cwl-runner
class: CommandLineTool
cwlVersion: v1.1
requirements:
LoadListingRequirement:
loadListing: deep_listing
InlineJavascriptRequirement: {}
inputs:
d: Directory
outputs:
out:
type: boolean
outputBinding:
outputEval: '$(inputs.d.listing.length === 1 && inputs.d.listing[0].listing.length === 1)'
baseCommand: "true"
15 changes: 15 additions & 0 deletions testdata/v1.2/listing_deep1.cwl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env cwl-runner
class: CommandLineTool
cwlVersion: v1.2
requirements:
LoadListingRequirement:
loadListing: deep_listing
InlineJavascriptRequirement: {}
inputs:
d: Directory
outputs:
out:
type: boolean
outputBinding:
outputEval: '$(inputs.d.listing.length === 1 && inputs.d.listing[0].listing.length === 1)'
baseCommand: "true"
23 changes: 22 additions & 1 deletion tests/test_complete.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import filecmp
from pathlib import Path

from cwlupgrader.main import main
from cwlupgrader.main import load_cwl_document, main, upgrade_document

from .util import get_data

Expand All @@ -15,3 +15,24 @@ def test_draft3_workflow(tmp_path: Path) -> None:
shallow=False,
)
assert result


def test_invalid_target(tmp_path: Path) -> None:
"""Test for invalid target version"""
doc = load_cwl_document(get_data("testdata/v1.0/listing_deep1.cwl"))
result = upgrade_document(doc, str(tmp_path), "invalid-version")
assert result is None


def test_v1_0_to_v1_1(tmp_path: Path) -> None:
"""Basic CWL v1.0 to CWL v1.1 test."""
doc = load_cwl_document(get_data("testdata/v1.0/listing_deep1.cwl"))
upgraded = upgrade_document(doc, str(tmp_path), "v1.1")
assert doc == upgraded


def test_v1_1_to_v1_2(tmp_path: Path) -> None:
"""Basic CWL v1.1 to CWL v1.2 test."""
doc = load_cwl_document(get_data("testdata/v1.1/listing_deep1.cwl"))
upgraded = upgrade_document(doc, str(tmp_path), "v1.2")
assert doc == upgraded