From ee783ab7ffb32d0201219d34853b7c0a69c516f8 Mon Sep 17 00:00:00 2001 From: "Michael R. Crusoe" Date: Mon, 6 Nov 2023 12:03:03 +0100 Subject: [PATCH 1/2] upgrade to cwl-utils 0.32 --- requirements.txt | 4 ++-- setup.cfg | 4 ++-- src/runcrate/convert.py | 18 +++++++++--------- tests/test_cli.py | 26 ++++++++++++++++---------- 4 files changed, 29 insertions(+), 23 deletions(-) diff --git a/requirements.txt b/requirements.txt index 659b82e..44fc119 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 diff --git a/setup.cfg b/setup.cfg index 0ff1a52..a212e71 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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= diff --git a/src/runcrate/convert.py b/src/runcrate/convert.py index 9e0eecf..c2631fd 100644 --- a/src/runcrate/convert.py +++ b/src/runcrate/convert.py @@ -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) + additional_type = "Collection" if cwl_p.secondaryFiles else convert_cwl_type(cwl_p.type_) properties = { "@type": "FormalParameter", "additionalType": additional_type @@ -95,20 +95,20 @@ 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 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 diff --git a/tests/test_cli.py b/tests/test_cli.py index f1a5679..7f4e36c 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -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) @@ -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") @@ -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") @@ -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 @@ -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 @@ -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) @@ -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__ @@ -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" @@ -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): @@ -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 From ccd54f6a90542588f406af6c64223976fc1f9e3c Mon Sep 17 00:00:00 2001 From: simleo Date: Wed, 6 Dec 2023 15:25:07 +0100 Subject: [PATCH 2/2] more updates for cwl-utils 0.32 --- src/runcrate/convert.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/runcrate/convert.py b/src/runcrate/convert.py index c2631fd..7d80dc4 100644 --- a/src/runcrate/convert.py +++ b/src/runcrate/convert.py @@ -82,7 +82,7 @@ def convert_cwl_type(cwl_type): def properties_from_cwl_param(cwl_p): def is_structured(cwl_type): - return getattr(cwl_type, "type", None) in ("array", "record") + 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", @@ -100,14 +100,15 @@ def is_structured(cwl_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: properties["defaultValue"] = str(cwl_p.default) # TODO: support more cases - if getattr(cwl_p.type_, "type", None) == "enum": + if getattr(cwl_p.type_, "type_", None) == "enum": properties["valuePattern"] = "|".join(_.rsplit("/", 1)[-1] for _ in cwl_p.type_.symbols) return properties