From f3c55a9d293d46064bb75e44765aa0223b4a57a2 Mon Sep 17 00:00:00 2001 From: "Michael R. Crusoe" Date: Thu, 25 May 2023 19:04:19 +0200 Subject: [PATCH] Unpin and upgrade cwl-utils version --- .github/dependabot.yml | 16 ++++++++++++++++ requirements.txt | 2 +- setup.cfg | 2 +- src/runcrate/convert.py | 37 +++++++++++++++++++------------------ 4 files changed, 37 insertions(+), 20 deletions(-) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..c0a96e6 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,16 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for all configuration options: +# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + - package-ecosystem: "pip" # See documentation for possible values + directory: "/" # Location of package manifests + schedule: + interval: "daily" + # Maintain dependencies for GitHub Actions + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "daily" diff --git a/requirements.txt b/requirements.txt index 97f6f54..0fcd5d7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ bdbag>=1.4.1 click~=8.1 -cwl-utils==0.13 +cwl-utils>=0.27 cwlprov==0.1.1 networkx==2.8 prov>=1.5.1 diff --git a/setup.cfg b/setup.cfg index 7bc0931..af27bfd 100644 --- a/setup.cfg +++ b/setup.cfg @@ -32,7 +32,7 @@ python_requires=>=3.8, <4 install_requires= bdbag>=1.4.1 click~=8.1 - cwl-utils==0.13 + cwl-utils>=0.27 cwlprov==0.1.1 networkx==2.8 prov>=1.5.1 diff --git a/src/runcrate/convert.py b/src/runcrate/convert.py index 2cbd53c..2df565f 100644 --- a/src/runcrate/convert.py +++ b/src/runcrate/convert.py @@ -25,7 +25,7 @@ import networkx as nx import prov.model from bdbag.bdbagit import BDBag -from cwl_utils.parser import load_document_by_yaml +from cwl_utils.parser import ProcessRequirement, load_document_by_yaml from cwlprov.prov import Entity, Provenance from cwlprov.ro import ResearchObject from cwlprov.utils import first @@ -95,16 +95,12 @@ def is_structured(cwl_type): if is_structured(cwl_p.type): properties["multipleValues"] = "True" if hasattr(cwl_p, "default"): - try: - default_type = cwl_p.default["class"] - except (TypeError, KeyError): - if not is_structured(cwl_p.type) and cwl_p.default is not None: - properties["defaultValue"] = str(cwl_p.default) - else: - if default_type in ("File", "Directory"): - default = cwl_p.default.get("location", cwl_p.default.get("path")) - if default: - properties["defaultValue"] = 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: + 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) @@ -163,7 +159,7 @@ def get_workflow(wf_path): ns = n.pop("$namespaces", {}) if ns: json_wf.setdefault("$namespaces", {}).update(ns) - defs = load_document_by_yaml(json_wf, wf_path.absolute().as_uri()) + defs = load_document_by_yaml(json_wf, wf_path.absolute().as_uri(), load_all=True) if not isinstance(defs, list): defs = [defs] def_map = {} @@ -362,13 +358,18 @@ def add_tool(self, crate, workflow, cwl_tool): properties["@type"] = "SoftwareApplication" if hasattr(cwl_tool, "intent") and cwl_tool.intent: properties["featureList"] = cwl_tool.intent + if hasattr(cwl_tool, "requirements") and cwl_tool.requirements: + for req in cwl_tool.requirements: + if req.class_ == "ResourceRequirement": + ramMin = req.ramMin + if ramMin: + properties["memoryRequirements"] = f"{int(ramMin)} MiB" if hasattr(cwl_tool, "hints") and cwl_tool.hints: - hints_map = {_["class"]: _ for _ in cwl_tool.hints} - rreq = hints_map.get("ResourceRequirement") - if rreq: - ramMin = rreq.get("ramMin") - if ramMin: - properties["memoryRequirements"] = f"{int(ramMin)} MiB" + for req in cwl_tool.hints: + if isinstance(req, ProcessRequirement) and req.class_ == "ResourceRequirement": + ramMin = req.ramMin + if ramMin: + properties["memoryRequirements"] = f"{int(ramMin)} MiB" tool = crate.add(ContextEntity(crate, tool_id, properties=properties)) tool["input"] = self.add_params(crate, cwl_tool.inputs) tool["output"] = self.add_params(crate, cwl_tool.outputs)