Skip to content

Commit

Permalink
remove version from ComputerLanguage
Browse files Browse the repository at this point in the history
  • Loading branch information
simleo committed May 19, 2023
1 parent b2086a7 commit fe714f6
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 51 deletions.
64 changes: 18 additions & 46 deletions rocrate/model/computerlanguage.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,46 +59,24 @@ def url(self):
def url(self, url):
self["url"] = url

# Not listed as a property in "https://schema.org/ComputerLanguage"
@property
def version(self):
return self.get("version")

@version.setter
def version(self, version):
self["version"] = version


# For workflow ro-crates. Note that
# https://about.workflowhub.eu/Workflow-RO-Crate/ does not specify versions.

CWL_DEFAULT_VERSION = "1.2"
# https://github.com/galaxyproject/gxformat2 has some info on gxformat2 versions
# version can probably be simply ignored for "native" *.ga workflows
GALAXY_DEFAULT_VERSION = "21.09"
KNIME_DEFAULT_VERSION = "4.5.0"
NEXTFLOW_DEFAULT_VERSION = "21.10"
SNAKEMAKE_DEFAULT_VERSION = "6.13"
COMPSS_DEFAULT_VERSION = "2.10"
AUTOSUBMIT_DEFAULT_VERSION = "3.14"
# See https://w3id.org/workflowhub/workflow-ro-crate/1.0


def cwl(crate, version=CWL_DEFAULT_VERSION):
def cwl(crate):
id_ = "https://w3id.org/workflowhub/workflow-ro-crate#cwl"
return ComputerLanguage(crate, identifier=id_, properties={
"name": "Common Workflow Language",
"alternateName": "CWL",
"identifier": {
"@id": f"https://w3id.org/cwl/{version}/"
"@id": "https://w3id.org/cwl/"
},
"url": {
"@id": "https://www.commonwl.org/"
},
"version": version
}
})


def galaxy(crate, version=GALAXY_DEFAULT_VERSION):
def galaxy(crate):
id_ = "https://w3id.org/workflowhub/workflow-ro-crate#galaxy"
return ComputerLanguage(crate, identifier=id_, properties={
"name": "Galaxy",
Expand All @@ -107,12 +85,11 @@ def galaxy(crate, version=GALAXY_DEFAULT_VERSION):
},
"url": {
"@id": "https://galaxyproject.org/"
},
"version": version
}
})


def knime(crate, version=KNIME_DEFAULT_VERSION):
def knime(crate):
id_ = "https://w3id.org/workflowhub/workflow-ro-crate#knime"
return ComputerLanguage(crate, identifier=id_, properties={
"name": "KNIME",
Expand All @@ -121,12 +98,11 @@ def knime(crate, version=KNIME_DEFAULT_VERSION):
},
"url": {
"@id": "https://www.knime.com/"
},
"version": version
}
})


def nextflow(crate, version=NEXTFLOW_DEFAULT_VERSION):
def nextflow(crate):
id_ = "https://w3id.org/workflowhub/workflow-ro-crate#nextflow"
return ComputerLanguage(crate, identifier=id_, properties={
"name": "Nextflow",
Expand All @@ -135,12 +111,11 @@ def nextflow(crate, version=NEXTFLOW_DEFAULT_VERSION):
},
"url": {
"@id": "https://www.nextflow.io/"
},
"version": version
}
})


def snakemake(crate, version=SNAKEMAKE_DEFAULT_VERSION):
def snakemake(crate):
id_ = "https://w3id.org/workflowhub/workflow-ro-crate#snakemake"
return ComputerLanguage(crate, identifier=id_, properties={
"name": "Snakemake",
Expand All @@ -149,28 +124,25 @@ def snakemake(crate, version=SNAKEMAKE_DEFAULT_VERSION):
},
"url": {
"@id": "https://snakemake.readthedocs.io"
},
"version": version
}
})


def compss(crate, version=COMPSS_DEFAULT_VERSION):
def compss(crate):
return ComputerLanguage(crate, identifier="#compss", properties={
"name": "COMPSs Programming Model",
"alternateName": "COMPSs",
"url": "http://compss.bsc.es/",
"citation": "https://doi.org/10.1007/s10723-013-9272-5",
"version": version
"citation": "https://doi.org/10.1007/s10723-013-9272-5"
})


def autosubmit(crate, version=AUTOSUBMIT_DEFAULT_VERSION):
def autosubmit(crate):
return ComputerLanguage(crate, identifier="#autosubmit", properties={
"name": "Autosubmit",
"alternateName": "AS",
"url": "https://autosubmit.readthedocs.io/",
"citation": "https://doi.org/10.1109/HPCSim.2016.7568429",
"version": version
"citation": "https://doi.org/10.1109/HPCSim.2016.7568429"
})


Expand All @@ -185,9 +157,9 @@ def autosubmit(crate, version=AUTOSUBMIT_DEFAULT_VERSION):
}


def get_lang(crate, name, version=None):
def get_lang(crate, name):
try:
func = LANG_MAP[name.lower()]
except KeyError:
raise ValueError(f"Unknown language: {name}")
return func(crate, version=version) if version else func(crate)
return func(crate)
5 changes: 4 additions & 1 deletion rocrate/rocrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,11 @@ def add_workflow(
if isinstance(lang, ComputerLanguage):
assert lang.crate is self
else:
kwargs = {"version": lang_version} if lang_version else {}
kwargs = {}
lang_str = lang
lang = get_lang(self, lang, **kwargs)
if lang_str.lower() == "cwl" and lang_version:
lang["identifier"] = f"https://w3id.org/cwl/{lang_version}/"
self.add(lang)
lang_str = lang.id.rsplit("#", 1)[1]
workflow.lang = lang
Expand Down
19 changes: 15 additions & 4 deletions test/test_workflow_ro_crate.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import pytest

from rocrate.rocrate import ROCrate, make_workflow_rocrate
from rocrate.model.computerlanguage import CWL_DEFAULT_VERSION, GALAXY_DEFAULT_VERSION

WF_CRATE = "https://w3id.org/workflowhub/workflow-ro-crate"

Expand All @@ -33,7 +34,6 @@ def test_galaxy_wf_crate(test_data_dir, tmpdir, helpers):
assert wf_crate.mainEntity is wf
lang = wf_crate.dereference(f"{WF_CRATE}#galaxy")
assert hasattr(lang, "name")
assert lang.version == GALAXY_DEFAULT_VERSION
assert wf.get("programmingLanguage") is lang
assert wf.get("subjectOf") is not None
assert helpers.WORKFLOW_DESC_TYPES.issubset(wf["subjectOf"].type)
Expand Down Expand Up @@ -68,7 +68,6 @@ def test_cwl_wf_crate(test_data_dir, tmpdir, helpers):
assert wf_crate.mainEntity is wf
lang = wf_crate.dereference(f"{WF_CRATE}#cwl")
assert hasattr(lang, "name")
assert lang.version == CWL_DEFAULT_VERSION
assert wf.get("programmingLanguage") is lang
assert "subjectOf" not in wf

Expand Down Expand Up @@ -99,7 +98,6 @@ def test_create_wf_include(test_data_dir, tmpdir, helpers):
assert wf_crate.mainEntity is wf
lang = wf_crate.dereference(f"{WF_CRATE}#galaxy")
assert hasattr(lang, "name")
assert lang.version == GALAXY_DEFAULT_VERSION
assert wf.get("programmingLanguage") is lang
assert wf.get("subjectOf") is not None
assert helpers.WORKFLOW_DESC_TYPES.issubset(wf["subjectOf"].type)
Expand All @@ -124,3 +122,16 @@ def test_create_wf_include(test_data_dir, tmpdir, helpers):
assert file2.exists()
with open(extra_file2) as f1, open(file2) as f2:
assert f1.read() == f2.read()


@pytest.mark.parametrize("lang_version", [None, "1.2"])
def test_cwl_lang_version(test_data_dir, lang_version):
wf_id = 'sample_cwl_wf.cwl'
wf_path = test_data_dir / wf_id
crate = ROCrate()
workflow = crate.add_workflow(wf_path, wf_id, lang_version=lang_version)
lang_id = workflow["programmingLanguage"]["identifier"]
if lang_version is None:
assert lang_id == "https://w3id.org/cwl/"
else:
assert lang_id == "https://w3id.org/cwl/1.2/"

0 comments on commit fe714f6

Please sign in to comment.