Skip to content

Commit

Permalink
ro_crate -> rocrate
Browse files Browse the repository at this point in the history
  • Loading branch information
mashehu committed Oct 17, 2024
1 parent 49592cb commit c1d08d7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 18 deletions.
11 changes: 6 additions & 5 deletions nf_core/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
pipelines_launch,
pipelines_lint,
pipelines_list,
pipelines_rocrate,
pipelines_schema_build,
pipelines_schema_docs,
pipelines_schema_lint,
Expand Down Expand Up @@ -85,7 +86,7 @@
},
{
"name": "For developers",
"commands": ["create", "lint", "bump-version", "sync", "schema", "create-logo"],
"commands": ["create", "lint", "bump-version", "sync", "schema", "rocrate", "create-logo"],
},
],
"nf-core modules": [
Expand Down Expand Up @@ -569,8 +570,8 @@ def command_pipelines_list(ctx, keywords, sort, json, show_archived):
pipelines_list(ctx, keywords, sort, json, show_archived)


# nf-core pipelines ro-crate
@pipelines.command("ro-crate")
# nf-core pipelines rocrate
@pipelines.command("rocrate")
@click.argument(
"pipeline_dir",
type=click.Path(exists=True),
Expand All @@ -594,7 +595,7 @@ def command_pipelines_list(ctx, keywords, sort, json, show_archived):
default="",
)
@click.pass_context
def ro_crate(
def rocrate(
ctx,
pipeline_dir: str,
json_path: str,
Expand All @@ -604,7 +605,7 @@ def ro_crate(
"""
Make an Research Object Crate
"""
pipelines_ro_crate(ctx, pipeline_dir, json_path, zip_path, pipeline_version)
pipelines_rocrate(ctx, pipeline_dir, json_path, zip_path, pipeline_version)


# nf-core pipelines sync
Expand Down
6 changes: 3 additions & 3 deletions nf_core/commands_pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,8 @@ def pipelines_list(ctx, keywords, sort, json, show_archived):
stdout.print(list_workflows(keywords, sort, json, show_archived))


# nf-core pipelines ro-crate
def pipelines_ro_crate(
# nf-core pipelines rocrate
def pipelines_rocrate(
ctx,
pipeline_dir: Union[str, Path],
json_path: Optional[Union[str, Path]],
Expand All @@ -299,7 +299,7 @@ def pipelines_ro_crate(
zip_path = Path(zip_path)
try:
rocrate_obj = ROCrate(pipeline_dir, pipeline_version)
rocrate_obj.create_ro_crate(pipeline_dir, metadata_path=json_path, zip_path=zip_path)
rocrate_obj.create_rocrate(pipeline_dir, metadata_path=json_path, zip_path=zip_path)
except (UserWarning, LookupError, FileNotFoundError) as e:
log.error(e)
sys.exit(1)
Expand Down
21 changes: 12 additions & 9 deletions nf_core/pipelines/rocrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@

import logging
import os
import re
import sys
import tempfile
from datetime import datetime
from pathlib import Path
from typing import Dict, List, Optional, Set, Union
from urllib.parse import quote

import requests
import rocrate.model.entity
import rocrate.rocrate
from git import GitCommandError, InvalidGitRepositoryError
from rich.progress import BarColumn, Progress
Expand Down Expand Up @@ -52,7 +51,7 @@ def __init__(self, pipeline_dir: Path, version="") -> None:

setup_requests_cachedir()

def create_ro_crate(
def create_rocrate(
self, outdir: Path, metadata_path: Union[None, Path] = None, zip_path: Union[None, Path] = None
) -> None:
"""
Expand Down Expand Up @@ -96,7 +95,7 @@ def create_ro_crate(
log.error(f"Could not checkout version {self.version}")
sys.exit(1)
self.version = self.pipeline_obj.nf_config.get("manifest.version", "")
self.make_workflow_ro_crate()
self.make_workflow_rocrate()

# Save just the JSON metadata file
if metadata_path is not None:
Expand All @@ -123,7 +122,7 @@ def create_ro_crate(
# Change back to the original directory
os.chdir(current_path)

def make_workflow_ro_crate(self) -> None:
def make_workflow_rocrate(self) -> None:
"""
Create an RO Crate for a pipeline
"""
Expand Down Expand Up @@ -258,7 +257,7 @@ def set_main_entity(self, main_entity_filename: str):
log.debug(f"Adding topics: {topics}")
self.crate.mainEntity.append_to("keywords", topics)

# self.add_main_authors(self.crate.mainEntity)
self.add_main_authors(self.crate.mainEntity)

self.crate.mainEntity = self.crate.mainEntity

Expand Down Expand Up @@ -323,9 +322,14 @@ def add_main_authors(self, wf_file: rocrate.model.entity.Entity) -> None:

for author in named_contributors:
log.debug(f"Adding author: {author}")
assert self.pipeline_obj.repo is not None # mypy
# get email from git log
email = self.pipeline_obj.repo.git.log(f"--author={author}", "--pretty=format:%ae", "-1")
orcid = get_orcid(author)
author_entitity = self.crate.add(
Person(self.crate, orcid if orcid is not None else "#" + quote(author), properties={"name": author})
Person(
self.crate, orcid if orcid is not None else "#" + email, properties={"name": author, "email": email}
)
)
wf_file.append_to("creator", author_entitity)
if author in authors:
Expand All @@ -335,7 +339,6 @@ def add_workflow_files(self):
"""
Add workflow files to the RO Crate
"""
import re

import nf_core.utils

Expand All @@ -360,7 +363,7 @@ def add_workflow_files(self):
wf_dir,
dest_path=wf_dir,
properties={
"description": f"nf-core {component_type} [{component_name}](https://nf-co.re/{component_type}/{component_name}) installed from the [nf-core/modules repository](https://github.com/nf-core/modules/)."
"description": f"nf-core {re.sub('s$', '', component_type)} [{component_name}](https://nf-co.re/{component_type}/{component_name}) installed from the [nf-core/modules repository](https://github.com/nf-core/modules/)."
},
)
wf_locals = [
Expand Down
2 changes: 1 addition & 1 deletion tests/test_rocrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def test_rocrate_creation(self):

# Run the command
self.rocrate_obj = nf_core.pipelines.rocrate.ROCrate(self.test_pipeline_dir)
self.rocrate_obj.create_ro_crate(self.test_pipeline_dir, metadata_path=Path(self.test_pipeline_dir))
self.rocrate_obj.create_rocrate(self.test_pipeline_dir, metadata_path=Path(self.test_pipeline_dir))

# Check that the crate was created
self.assertTrue(Path(self.test_pipeline_dir, "ro-crate-metadata.json").exists())
Expand Down

0 comments on commit c1d08d7

Please sign in to comment.