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

upgrade to cwl-utils 0.30 #67

Merged
merged 2 commits into from
Dec 6, 2023
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
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
bdbag>=1.4.1
click~=8.1
cwl-utils==0.31
cwl-utils==0.32
cwlprov==0.1.1
networkx==3.1
prov>=1.5.1
rocrate~=0.9
rocrate>=0.9,<1
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ python_requires=>=3.8, <4
install_requires=
bdbag>=1.4.1
click~=8.1
cwl-utils==0.31
cwl-utils==0.32
cwlprov==0.1.1
networkx==3.1
prov>=1.5.1
rocrate~=0.9
rocrate>=0.9,<1

[options.entry_points]
console_scripts=
Expand Down
25 changes: 13 additions & 12 deletions src/runcrate/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,18 @@ def convert_cwl_type(cwl_type):
return s.pop() if len(s) == 1 else sorted(s)
if isinstance(cwl_type, str):
return CWL_TYPE_MAP[cwl_type]
if cwl_type.type == "enum":
if cwl_type.type_ == "enum":
return "Text" # use actionOption to represent choices?
if cwl_type.type == "array":
if cwl_type.type_ == "array":
return convert_cwl_type(cwl_type.items)
if cwl_type.type == "record":
if cwl_type.type_ == "record":
return "PropertyValue"


def properties_from_cwl_param(cwl_p):
def is_structured(cwl_type):
return getattr(cwl_type, "type", None) in ("array", "record")
additional_type = "Collection" if cwl_p.secondaryFiles else convert_cwl_type(cwl_p.type)
return getattr(cwl_type, "type_", None) in ("array", "record")
additional_type = "Collection" if cwl_p.secondaryFiles else convert_cwl_type(cwl_p.type_)
properties = {
"@type": "FormalParameter",
"additionalType": additional_type
Expand All @@ -95,20 +95,21 @@ def is_structured(cwl_type):
properties["description"] = cwl_p.label
if cwl_p.format:
properties["encodingFormat"] = cwl_p.format
if isinstance(cwl_p.type, list) and "null" in cwl_p.type:
if isinstance(cwl_p.type_, list) and "null" in cwl_p.type_:
properties["valueRequired"] = "False"
if is_structured(cwl_p.type):
if is_structured(cwl_p.type_):
properties["multipleValues"] = "True"
if hasattr(cwl_p, "default"):
if hasattr(cwl_p.default, "class_") and cwl_p.default.class_ in ("File", "Directory"):
default = cwl_p.default.location or cwl_p.default.path
if isinstance(cwl_p.default, dict):
if cwl_p.default.get("class") in ("File", "Directory"):
default = cwl_p.default.get("location", cwl_p.default.get("path"))
if default:
properties["defaultValue"] = default
elif not is_structured(cwl_p.type) and cwl_p.default is not None:
elif not is_structured(cwl_p.type_) and cwl_p.default is not None:
properties["defaultValue"] = str(cwl_p.default)
# TODO: support more cases
if getattr(cwl_p.type, "type", None) == "enum":
properties["valuePattern"] = "|".join(_.rsplit("/", 1)[-1] for _ in cwl_p.type.symbols)
if getattr(cwl_p.type_, "type_", None) == "enum":
properties["valuePattern"] = "|".join(_.rsplit("/", 1)[-1] for _ in cwl_p.type_.symbols)
return properties


Expand Down
26 changes: 16 additions & 10 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ def test_cli_convert(data_dir, tmpdir, monkeypatch):
root = data_dir / "revsort-run-1"
runner = CliRunner()
args = ["convert", str(root)]
assert runner.invoke(cli, args).exit_code == 0
result = runner.invoke(cli, args)
assert result.exit_code == 0, result.exception
crate_zip = tmpdir / f"{root.name}.crate.zip"
assert crate_zip.is_file()
crate = ROCrate(crate_zip)
Expand All @@ -41,7 +42,8 @@ def test_cli_convert_output(data_dir, tmpdir):
crate_zip = tmpdir / "crate.zip"
runner = CliRunner()
args = ["convert", str(root), "-o", str(crate_zip)]
assert runner.invoke(cli, args).exit_code == 0
result = runner.invoke(cli, args)
assert result.exit_code == 0, result.exception
assert crate_zip.is_file()
crate = ROCrate(crate_zip)
assert not crate.root_dataset.get("license")
Expand All @@ -52,7 +54,8 @@ def test_cli_convert_output(data_dir, tmpdir):
crate_dir = tmpdir / "revsort-run-1-crate"
runner = CliRunner()
args = ["convert", str(root), "-o", str(crate_dir)]
assert runner.invoke(cli, args).exit_code == 0
result = runner.invoke(cli, args)
assert result.exit_code == 0, result.exception
assert crate_dir.is_dir()
crate = ROCrate(crate_dir)
assert not crate.root_dataset.get("license")
Expand All @@ -66,7 +69,8 @@ def test_cli_convert_license(data_dir, tmpdir):
license = "MIT"
runner = CliRunner()
args = ["convert", str(root), "-o", str(crate_dir), "-l", license]
assert runner.invoke(cli, args).exit_code == 0
result = runner.invoke(cli, args)
assert result.exit_code == 0, result.exception
crate = ROCrate(crate_dir)
assert crate.root_dataset["license"] == license

Expand All @@ -77,7 +81,8 @@ def test_cli_convert_workflow_name(data_dir, tmpdir):
workflow_name = "RevSort"
runner = CliRunner()
args = ["convert", str(root), "-o", str(crate_dir), "-w", workflow_name]
assert runner.invoke(cli, args).exit_code == 0
result = runner.invoke(cli, args)
assert result.exit_code == 0, result.exception
crate = ROCrate(crate_dir)
workflow = crate.mainEntity
assert workflow["name"] == workflow_name
Expand All @@ -89,7 +94,8 @@ def test_cli_convert_readme(data_dir, tmpdir):
readme = data_dir / "README.md"
runner = CliRunner()
args = ["convert", str(root), "-o", str(crate_dir), "--readme", readme]
assert runner.invoke(cli, args).exit_code == 0
result = runner.invoke(cli, args)
assert result.exit_code == 0, result.exception
crate = ROCrate(crate_dir)
assert crate.get(readme.name)

Expand All @@ -108,7 +114,7 @@ def test_cli_report_provenance_minimal(data_dir, caplog):
def test_cli_version():
runner = CliRunner()
result = runner.invoke(cli, ["version"])
assert result.exit_code == 0
assert result.exit_code == 0, result.exception
assert result.stdout.strip() == __version__


Expand All @@ -118,7 +124,7 @@ def test_cli_run(data_dir, tmpdir, monkeypatch):
args = ["run", str(crate_dir)]
monkeypatch.chdir(str(tmpdir))
result = runner.invoke(cli, args)
assert result.exit_code == 0
assert result.exit_code == 0, result.exception
out_path = Path("output.txt")
assert out_path.is_file()
crate_out_path = crate_dir / "4bd8e7e358488e833bf32cf5028695292cecb05b"
Expand All @@ -131,7 +137,7 @@ def test_cli_run_dir_array(data_dir, tmpdir, monkeypatch):
args = ["run", str(crate_dir)]
monkeypatch.chdir(str(tmpdir))
result = runner.invoke(cli, args)
assert result.exit_code == 0
assert result.exit_code == 0, result.exception


def test_cli_run_file_array(data_dir, tmpdir, monkeypatch):
Expand All @@ -140,4 +146,4 @@ def test_cli_run_file_array(data_dir, tmpdir, monkeypatch):
args = ["run", str(crate_dir)]
monkeypatch.chdir(str(tmpdir))
result = runner.invoke(cli, args)
assert result.exit_code == 0
assert result.exit_code == 0, result.exception