Skip to content

Commit

Permalink
Merge pull request #1919 from bjlang/dev
Browse files Browse the repository at this point in the history
add nf-core subworkflows list and info commands
  • Loading branch information
mashehu committed Nov 17, 2022
2 parents c005f03 + dc60869 commit b70ba88
Show file tree
Hide file tree
Showing 4 changed files with 409 additions and 1 deletion.
102 changes: 101 additions & 1 deletion nf_core/__main__.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"nf-core subworkflows": [
{
"name": "For pipelines",
"commands": ["list", "install", "update"],
"commands": ["list", "info", "install", "update"],
},
{
"name": "Developing new subworkflows",
Expand Down Expand Up @@ -958,6 +958,106 @@ def create_test_yml(ctx, subworkflow, run_tests, output, force, no_prompts):
sys.exit(1)


# nf-core subworkflows list subcommands
@subworkflows.group()
@click.pass_context
def list(ctx):
"""
List subworkflows in a local pipeline or remote repository.
"""
pass


# nf-core subworkflows list remote
@list.command()
@click.pass_context
@click.argument("keywords", required=False, nargs=-1, metavar="<filter keywords>")
@click.option("-j", "--json", is_flag=True, help="Print as JSON to stdout")
def remote(ctx, keywords, json):
"""
List subworkflows in a remote GitHub repo [dim i](e.g [link=https://github.com/nf-core/modules]nf-core/modules[/])[/].
"""
try:
subworkflows_list = nf_core.subworkflows.SubworkflowList(
None,
True,
ctx.obj["modules_repo_url"],
ctx.obj["modules_repo_branch"],
ctx.obj["modules_repo_no_pull"],
)
stdout.print(subworkflows_list.list_subworkflows(keywords, json))
except (UserWarning, LookupError) as e:
log.critical(e)
sys.exit(1)


# nf-core subworkflows list local
@list.command()
@click.pass_context
@click.argument("keywords", required=False, nargs=-1, metavar="<filter keywords>")
@click.option("-j", "--json", is_flag=True, help="Print as JSON to stdout")
@click.option(
"-d",
"--dir",
type=click.Path(exists=True),
default=".",
help=r"Pipeline directory. [dim]\[default: Current working directory][/]",
)
def local(ctx, keywords, json, dir): # pylint: disable=redefined-builtin
"""
List subworkflows installed locally in a pipeline
"""
try:
subworkflows_list = nf_core.subworkflows.SubworkflowList(
dir,
False,
ctx.obj["modules_repo_url"],
ctx.obj["modules_repo_branch"],
ctx.obj["modules_repo_no_pull"],
)
stdout.print(subworkflows_list.list_subworkflows(keywords, json))
except (UserWarning, LookupError) as e:
log.error(e)
sys.exit(1)


# nf-core subworkflows info
@subworkflows.command()
@click.pass_context
@click.argument("tool", type=str, required=False, metavar="subworkflow name")
@click.option(
"-d",
"--dir",
type=click.Path(exists=True),
default=".",
help=r"Pipeline directory. [dim]\[default: Current working directory][/]",
)
def info(ctx, tool, dir):
"""
Show developer usage information about a given subworkflow.
Parses information from a subworkflow's [i]meta.yml[/] and renders help
on the command line. A handy equivalent to searching the
[link=https://nf-co.re/modules]nf-core website[/].
If run from a pipeline and a local copy of the subworkflow is found, the command
will print this usage info.
If not, usage from the remote subworkflows repo will be shown.
"""
try:
subworkflow_info = nf_core.subworkflows.SubworkflowInfo(
dir,
tool,
ctx.obj["modules_repo_url"],
ctx.obj["modules_repo_branch"],
ctx.obj["modules_repo_no_pull"],
)
stdout.print(subworkflow_info.get_subworkflow_info())
except (UserWarning, LookupError) as e:
log.error(e)
sys.exit(1)


# nf-core subworkflows install
@subworkflows.command()
@click.pass_context
Expand Down
18 changes: 18 additions & 0 deletions nf_core/modules/modules_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,3 +485,21 @@ def get_meta_yml(self, module_name):
with open(path) as fh:
contents = fh.read()
return contents

def get_subworkflow_meta_yml(self, subworkflow_name):
"""
Returns the contents of the 'meta.yml' file of a subworkflow
Args:
subworkflow_name (str): The name of the subworkflow
Returns:
(str): The contents of the file in text format
"""
self.checkout_branch()
path = os.path.join(self.subworkflows_dir, subworkflow_name, "meta.yml")
if not os.path.exists(path):
return None
with open(path) as fh:
contents = fh.read()
return contents
1 change: 1 addition & 0 deletions nf_core/subworkflows/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .create import SubworkflowCreate
from .info import SubworkflowInfo
from .install import SubworkflowInstall
from .list import SubworkflowList
from .subworkflows_test import SubworkflowsTest
Expand Down
Loading

0 comments on commit b70ba88

Please sign in to comment.