Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rocrate: Update crate with version bump and handle new contributor field #3334

Merged
merged 5 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
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
39 changes: 35 additions & 4 deletions nf_core/pipelines/rocrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -336,6 +348,25 @@ 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
# try to find a json file
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: 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)


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")
Loading