Skip to content

Commit 05e7b95

Browse files
authored
Merge pull request #3334 from mashehu/update-crate-with-version-bump
rocrate: Update crate with version bump and handle new contributor field
2 parents 55ca4d4 + 953055d commit 05e7b95

File tree

4 files changed

+75
-4
lines changed

4 files changed

+75
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
- build: Setup VS Code tests ([#3292](https://github.com/nf-core/tools/pull/3292))
6565
- Don't break gitpod.yml with template string ([#3332](https://github.com/nf-core/tools/pull/3332))
6666
- rocrate: remove duplicated entries for name and version ([#3333](https://github.com/nf-core/tools/pull/3333))
67+
- rocrate: Update crate with version bump and handle new contributor field ([#3334](https://github.com/nf-core/tools/pull/3334))
6768

6869
### Version updates
6970

nf_core/pipelines/bump_version.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from ruamel.yaml import YAML
1212

1313
import nf_core.utils
14+
from nf_core.pipelines.rocrate import ROCrate
1415
from nf_core.utils import Pipeline
1516

1617
log = logging.getLogger(__name__)
@@ -127,6 +128,9 @@ def bump_pipeline_version(pipeline_obj: Pipeline, new_version: str) -> None:
127128
yaml_key=["template", "version"],
128129
)
129130

131+
# update rocrate
132+
ROCrate(pipeline_obj.wf_path).update_rocrate()
133+
130134

131135
def bump_nextflow_version(pipeline_obj: Pipeline, new_version: str) -> None:
132136
"""Bumps the required Nextflow version number of a pipeline.

nf_core/pipelines/rocrate.py

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,14 +267,26 @@ def add_main_authors(self, wf_file: rocrate.model.entity.Entity) -> None:
267267
# add author entity to crate
268268

269269
try:
270-
authors = self.pipeline_obj.nf_config["manifest.author"].split(",")
271-
# remove spaces
272-
authors = [a.strip() for a in authors]
270+
authors = []
271+
if "manifest.author" in self.pipeline_obj.nf_config:
272+
authors.extend([a.strip() for a in self.pipeline_obj.nf_config["manifest.author"].split(",")])
273+
if "manifest.contributor" in self.pipeline_obj.nf_config:
274+
authors.extend(
275+
[
276+
c.get("name", "").strip()
277+
for c in self.pipeline_obj.nf_config["manifest.contributor"]
278+
if "name" in c
279+
]
280+
)
281+
if not authors:
282+
raise KeyError("No authors found")
273283
# add manifest authors as maintainer to crate
274284

275285
except KeyError:
276-
log.error("No author field found in manifest of nextflow.config")
286+
log.error("No author or contributor fields found in manifest of nextflow.config")
277287
return
288+
# remove duplicates
289+
authors = list(set(authors))
278290
# look at git contributors for author names
279291
try:
280292
git_contributors: Set[str] = set()
@@ -336,6 +348,25 @@ def add_main_authors(self, wf_file: rocrate.model.entity.Entity) -> None:
336348
if author in authors:
337349
wf_file.append_to("maintainer", author_entitity)
338350

351+
def update_rocrate(self) -> bool:
352+
"""
353+
Update the rocrate file
354+
"""
355+
# check if we need to output a json file and/or a zip file based on the file extensions
356+
# try to find a json file
357+
json_path: Optional[Path] = None
358+
potential_json_path = Path(self.pipeline_dir, "ro-crate-metadata.json")
359+
if potential_json_path.exists():
360+
json_path = potential_json_path
361+
362+
# try to find a zip file
363+
zip_path: Optional[Path] = None
364+
potential_zip_path = Path(self.pipeline_dir, "ro-crate.crate.zip")
365+
if potential_zip_path.exists():
366+
zip_path = potential_zip_path
367+
368+
return self.create_rocrate(json_path=json_path, zip_path=zip_path)
369+
339370

340371
def get_orcid(name: str) -> Optional[str]:
341372
"""

tests/pipelines/test_rocrate.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Test the nf-core pipelines rocrate command"""
22

3+
import json
34
import shutil
45
import tempfile
56
from pathlib import Path
@@ -12,6 +13,7 @@
1213
import nf_core.pipelines.create.create
1314
import nf_core.pipelines.rocrate
1415
import nf_core.utils
16+
from nf_core.pipelines.bump_version import bump_pipeline_version
1517

1618
from ..test_pipelines import TestPipelines
1719

@@ -125,3 +127,36 @@ def test_rocrate_creation_for_fetchngs(self):
125127

126128
# Clean up
127129
shutil.rmtree(tmp_dir)
130+
131+
def test_update_rocrate(self):
132+
"""Run the nf-core rocrate command with a zip output"""
133+
134+
assert self.rocrate_obj.create_rocrate(json_path=self.pipeline_dir, zip_path=self.pipeline_dir)
135+
136+
# read the crate json file
137+
with open(Path(self.pipeline_dir, "ro-crate-metadata.json")) as f:
138+
crate = json.load(f)
139+
140+
# check the old version
141+
self.assertEqual(crate["@graph"][2]["version"][0], "1.0.0dev")
142+
# check creativeWorkStatus is InProgress
143+
self.assertEqual(crate["@graph"][0]["creativeWorkStatus"], "InProgress")
144+
145+
# bump version
146+
bump_pipeline_version(self.pipeline_obj, "1.1.0")
147+
148+
# Check that the crate was created
149+
self.assertTrue(Path(self.pipeline_dir, "ro-crate.crate.zip").exists())
150+
151+
# Check that the crate was updated
152+
self.assertTrue(Path(self.pipeline_dir, "ro-crate-metadata.json").exists())
153+
154+
# read the crate json file
155+
with open(Path(self.pipeline_dir, "ro-crate-metadata.json")) as f:
156+
crate = json.load(f)
157+
158+
# check that the version was updated
159+
self.assertEqual(crate["@graph"][2]["version"][0], "1.1.0")
160+
161+
# check creativeWorkStatus is Stable
162+
self.assertEqual(crate["@graph"][0]["creativeWorkStatus"], "Stable")

0 commit comments

Comments
 (0)