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

add --dir/-d option to schema commands #3247

Merged
merged 8 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
2 changes: 1 addition & 1 deletion .github/.coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
omit = nf_core/*-template/*
source = nf_core
relative_files = True

data_file = ".coverage"
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
- Update python:3.12-slim Docker digest to 032c526 ([#3232](https://github.com/nf-core/tools/pull/3232))
- use correct `--profile` options for `nf-core subworkflows test` ([#3233](https://github.com/nf-core/tools/pull/3233))
- Update GitHub Actions ([#3237](https://github.com/nf-core/tools/pull/3237))
- add `--dir/-d` option to schema commands ([#3247](https://github.com/nf-core/tools/pull/3247))

## [v3.0.2 - Titanium Tapir Patch](https://github.com/nf-core/tools/releases/tag/3.0.2) - [2024-10-11]

Expand Down
43 changes: 36 additions & 7 deletions nf_core/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import logging
import os
import sys
from pathlib import Path

import rich
import rich.console
Expand Down Expand Up @@ -696,12 +697,24 @@ def pipeline_schema():

# nf-core pipelines schema validate
@pipeline_schema.command("validate")
@click.option(
"-d",
"--dir",
"directory",
type=click.Path(exists=True),
default=".",
help=r"Pipeline directory. [dim]\[default: current working directory][/]",
)
@click.argument("pipeline", required=True, metavar="<pipeline name>")
@click.argument("params", type=click.Path(exists=True), required=True, metavar="<JSON params file>")
def command_pipelines_schema_validate(pipeline, params):
def command_pipelines_schema_validate(directory, pipeline, params):
"""
Validate a set of parameters against a pipeline schema.
"""
if Path(directory, pipeline).exists():
# this is a local pipeline
pipeline = Path(directory, pipeline)

pipelines_schema_validate(pipeline, params)


Expand Down Expand Up @@ -740,23 +753,39 @@ def command_pipelines_schema_build(directory, no_prompts, web_only, url):

# nf-core pipelines schema lint
@pipeline_schema.command("lint")
@click.option(
"-d",
"--dir",
"directory",
type=click.Path(exists=True),
default=".",
help=r"Pipeline directory. [dim]\[default: current working directory][/]",
)
@click.argument(
"schema_path",
"schema_file",
type=click.Path(exists=True),
default="nextflow_schema.json",
metavar="<pipeline schema>",
)
def command_pipelines_schema_lint(schema_path):
def command_pipelines_schema_lint(directory, schema_file):
"""
Check that a given pipeline schema is valid.
"""
pipelines_schema_lint(schema_path)
pipelines_schema_lint(Path(directory, schema_file))


# nf-core pipelines schema docs
@pipeline_schema.command("docs")
@click.option(
"-d",
"--dir",
"directory",
type=click.Path(exists=True),
default=".",
help=r"Pipeline directory. [dim]\[default: current working directory][/]",
)
@click.argument(
"schema_path",
"schema_file",
type=click.Path(exists=True),
default="nextflow_schema.json",
required=False,
Expand Down Expand Up @@ -785,11 +814,11 @@ def command_pipelines_schema_lint(schema_path):
help="CSV list of columns to include in the parameter tables (parameter,description,type,default,required,hidden)",
default="parameter,description,type,default,required,hidden",
)
def command_pipelines_schema_docs(schema_path, output, format, force, columns):
def command_pipelines_schema_docs(directory, schema_file, output, format, force, columns):
"""
Outputs parameter documentation for a pipeline schema.
"""
pipelines_schema_docs(schema_path, output, format, force, columns)
pipelines_schema_docs(Path(directory, schema_file), output, format, force, columns)


# nf-core modules subcommands
Expand Down
4 changes: 2 additions & 2 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ def test_schema_lint(self, mock_get_schema_path):
with open("nextflow_schema.json", "w") as f:
f.write("{}")
self.invoke_cli(cmd)
mock_get_schema_path.assert_called_with("nextflow_schema.json")
mock_get_schema_path.assert_called_with(Path("nextflow_schema.json"))

@mock.patch("nf_core.pipelines.schema.PipelineSchema.get_schema_path")
def test_schema_lint_filename(self, mock_get_schema_path):
Expand All @@ -368,7 +368,7 @@ def test_schema_lint_filename(self, mock_get_schema_path):
with open("some_other_filename", "w") as f:
f.write("{}")
self.invoke_cli(cmd)
mock_get_schema_path.assert_called_with("some_other_filename")
mock_get_schema_path.assert_called_with(Path("some_other_filename"))

@mock.patch("nf_core.pipelines.create_logo.create_logo")
def test_create_logo(self, mock_create_logo):
Expand Down
Loading