From 3e81adb62de4649c17a0c7233c8d3feec77e82e8 Mon Sep 17 00:00:00 2001 From: mashehu Date: Tue, 10 Dec 2024 10:13:51 +0100 Subject: [PATCH 1/5] update version in ro crate on version bump --- nf_core/pipelines/bump_version.py | 4 ++++ nf_core/pipelines/rocrate.py | 22 +++++++++++++++++++ tests/pipelines/test_rocrate.py | 35 +++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+) diff --git a/nf_core/pipelines/bump_version.py b/nf_core/pipelines/bump_version.py index 3190ed70d..de0342c7f 100644 --- a/nf_core/pipelines/bump_version.py +++ b/nf_core/pipelines/bump_version.py @@ -11,6 +11,7 @@ from ruamel.yaml import YAML import nf_core.utils +from nf_core.pipelines.rocrate import ROCrate from nf_core.utils import Pipeline log = logging.getLogger(__name__) @@ -127,6 +128,9 @@ def bump_pipeline_version(pipeline_obj: Pipeline, new_version: str) -> None: yaml_key=["template", "version"], ) + # update rocrate + ROCrate(pipeline_obj.wf_path).update_rocrate() + def bump_nextflow_version(pipeline_obj: Pipeline, new_version: str) -> None: """Bumps the required Nextflow version number of a pipeline. diff --git a/nf_core/pipelines/rocrate.py b/nf_core/pipelines/rocrate.py index 21df0513a..ec2b23e02 100644 --- a/nf_core/pipelines/rocrate.py +++ b/nf_core/pipelines/rocrate.py @@ -336,6 +336,28 @@ def add_main_authors(self, wf_file: rocrate.model.entity.Entity) -> None: if author in authors: wf_file.append_to("maintainer", author_entitity) + def update_rocrate(self) -> bool: + """ + Update the rocrate file + """ + # check if we need to output a json file and/or a zip file based on the file extensions + json_path = None + zip_path = None + # try to find a json file + json_path = Path(self.pipeline_dir, "ro-crate-metadata.json") + if json_path.exists(): + json_path = json_path + else: + json_path = None + + # try to find a zip file + zip_path = Path(self.pipeline_dir, "ro-crate.crate.zip") + if zip_path.exists(): + zip_path = zip_path + else: + zip_path = None + return self.create_rocrate(json_path=json_path, zip_path=zip_path) + def get_orcid(name: str) -> Optional[str]: """ diff --git a/tests/pipelines/test_rocrate.py b/tests/pipelines/test_rocrate.py index 01a77ecd7..ac86e64bd 100644 --- a/tests/pipelines/test_rocrate.py +++ b/tests/pipelines/test_rocrate.py @@ -1,5 +1,6 @@ """Test the nf-core pipelines rocrate command""" +import json import shutil import tempfile from pathlib import Path @@ -12,6 +13,7 @@ import nf_core.pipelines.create.create import nf_core.pipelines.rocrate import nf_core.utils +from nf_core.pipelines.bump_version import bump_pipeline_version from ..test_pipelines import TestPipelines @@ -125,3 +127,36 @@ def test_rocrate_creation_for_fetchngs(self): # Clean up shutil.rmtree(tmp_dir) + + def test_update_rocrate(self): + """Run the nf-core rocrate command with a zip output""" + + assert self.rocrate_obj.create_rocrate(json_path=self.pipeline_dir, zip_path=self.pipeline_dir) + + # read the crate json file + with open(Path(self.pipeline_dir, "ro-crate-metadata.json")) as f: + crate = json.load(f) + + # check the old version + self.assertEqual(crate["@graph"][2]["version"][0], "1.0.0dev") + # check creativeWorkStatus is InProgress + self.assertEqual(crate["@graph"][0]["creativeWorkStatus"], "InProgress") + + # bump version + bump_pipeline_version(self.pipeline_obj, "1.1.0") + + # Check that the crate was created + self.assertTrue(Path(self.pipeline_dir, "ro-crate.crate.zip").exists()) + + # Check that the crate was updated + self.assertTrue(Path(self.pipeline_dir, "ro-crate-metadata.json").exists()) + + # read the crate json file + with open(Path(self.pipeline_dir, "ro-crate-metadata.json")) as f: + crate = json.load(f) + + # check that the version was updated + self.assertEqual(crate["@graph"][2]["version"][0], "1.1.0") + + # check creativeWorkStatus is Stable + self.assertEqual(crate["@graph"][0]["creativeWorkStatus"], "Stable") From 6ae3de544a77354c2276d4be16863b65ccaaa823 Mon Sep 17 00:00:00 2001 From: mashehu Date: Tue, 10 Dec 2024 10:14:47 +0100 Subject: [PATCH 2/5] handle new author field --- nf_core/pipelines/rocrate.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/nf_core/pipelines/rocrate.py b/nf_core/pipelines/rocrate.py index ec2b23e02..cbbda8d3d 100644 --- a/nf_core/pipelines/rocrate.py +++ b/nf_core/pipelines/rocrate.py @@ -267,14 +267,26 @@ def add_main_authors(self, wf_file: rocrate.model.entity.Entity) -> None: # add author entity to crate try: - authors = self.pipeline_obj.nf_config["manifest.author"].split(",") - # remove spaces - authors = [a.strip() for a in authors] + authors = [] + if "manifest.author" in self.pipeline_obj.nf_config: + authors.extend([a.strip() for a in self.pipeline_obj.nf_config["manifest.author"].split(",")]) + if "manifest.contributor" in self.pipeline_obj.nf_config: + authors.extend( + [ + c.get("name", "").strip() + for c in self.pipeline_obj.nf_config["manifest.contributor"] + if "name" in c + ] + ) + if not authors: + raise KeyError("No authors found") # add manifest authors as maintainer to crate except KeyError: - log.error("No author field found in manifest of nextflow.config") + log.error("No author or contributor fields found in manifest of nextflow.config") return + # remove duplicates + authors = list(set(authors)) # look at git contributors for author names try: git_contributors: Set[str] = set() From b976ec32a49f17e51784c425b2fc1a49be3a3307 Mon Sep 17 00:00:00 2001 From: mashehu Date: Tue, 10 Dec 2024 10:16:12 +0100 Subject: [PATCH 3/5] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bb897d76c..9015ac6da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -64,6 +64,7 @@ - build: Setup VS Code tests ([#3292](https://github.com/nf-core/tools/pull/3292)) - Don't break gitpod.yml with template string ([#3332](https://github.com/nf-core/tools/pull/3332)) - rocrate: remove duplicated entries for name and version ([#3333](https://github.com/nf-core/tools/pull/3333)) +- rocrate: Update crate with version bump and handle new contributor field ([#3334](https://github.com/nf-core/tools/pull/3334)) ### Version updates From 8a78d4bcf489c1073ca4376a93c763e4c4927154 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20H=C3=B6rtenhuber?= Date: Tue, 10 Dec 2024 10:51:44 +0100 Subject: [PATCH 4/5] Update nf_core/pipelines/rocrate.py --- nf_core/pipelines/rocrate.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/nf_core/pipelines/rocrate.py b/nf_core/pipelines/rocrate.py index cbbda8d3d..9af306aa2 100644 --- a/nf_core/pipelines/rocrate.py +++ b/nf_core/pipelines/rocrate.py @@ -353,8 +353,6 @@ def update_rocrate(self) -> bool: Update the rocrate file """ # check if we need to output a json file and/or a zip file based on the file extensions - json_path = None - zip_path = None # try to find a json file json_path = Path(self.pipeline_dir, "ro-crate-metadata.json") if json_path.exists(): From 953055d337811a6c45db9f49b71008485e51e6b0 Mon Sep 17 00:00:00 2001 From: mashehu Date: Tue, 10 Dec 2024 11:22:01 +0100 Subject: [PATCH 5/5] fix type error --- nf_core/pipelines/rocrate.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/nf_core/pipelines/rocrate.py b/nf_core/pipelines/rocrate.py index 9af306aa2..bc868273c 100644 --- a/nf_core/pipelines/rocrate.py +++ b/nf_core/pipelines/rocrate.py @@ -354,18 +354,17 @@ def update_rocrate(self) -> bool: """ # check if we need to output a json file and/or a zip file based on the file extensions # try to find a json file - json_path = Path(self.pipeline_dir, "ro-crate-metadata.json") - if json_path.exists(): - json_path = json_path - else: - json_path = None + json_path: Optional[Path] = None + potential_json_path = Path(self.pipeline_dir, "ro-crate-metadata.json") + if potential_json_path.exists(): + json_path = potential_json_path # try to find a zip file - zip_path = Path(self.pipeline_dir, "ro-crate.crate.zip") - if zip_path.exists(): - zip_path = zip_path - else: - zip_path = None + zip_path: Optional[Path] = None + potential_zip_path = Path(self.pipeline_dir, "ro-crate.crate.zip") + if potential_zip_path.exists(): + zip_path = potential_zip_path + return self.create_rocrate(json_path=json_path, zip_path=zip_path)