Skip to content

Commit

Permalink
update version in ro crate on version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
mashehu committed Dec 10, 2024
1 parent 55ca4d4 commit 3e81adb
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
4 changes: 4 additions & 0 deletions nf_core/pipelines/bump_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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.
Expand Down
22 changes: 22 additions & 0 deletions nf_core/pipelines/rocrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
"""
Expand Down
35 changes: 35 additions & 0 deletions tests/pipelines/test_rocrate.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Test the nf-core pipelines rocrate command"""

import json
import shutil
import tempfile
from pathlib import Path
Expand All @@ -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

Expand Down Expand Up @@ -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")

0 comments on commit 3e81adb

Please sign in to comment.