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

Refactor --hide-progress to be at the top level CLI #2016

Merged
merged 2 commits into from
Nov 10, 2022
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
4 changes: 2 additions & 2 deletions .github/workflows/create-lint-wf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ jobs:

# Run nf-core linting
- name: nf-core lint
run: nf-core --log-file log.txt lint --dir nf-core-testpipeline --fail-ignored --fail-warned
run: nf-core --log-file log.txt --hide-progress lint --dir nf-core-testpipeline --fail-ignored --fail-warned

# Run the other nf-core commands
- name: nf-core list
Expand All @@ -102,7 +102,7 @@ jobs:
run: nf-core --log-file log.txt bump-version --dir nf-core-testpipeline/ 1.1

- name: nf-core lint in release mode
run: nf-core --log-file log.txt lint --dir nf-core-testpipeline --fail-ignored --fail-warned --release
run: nf-core --log-file log.txt --hide-progress lint --dir nf-core-testpipeline --fail-ignored --fail-warned --release

- name: nf-core modules install
run: nf-core --log-file log.txt modules install fastqc --dir nf-core-testpipeline/ --force
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

### General

- Refactor CLI flag `--hide-progress` to be at the top-level group, like `--verbose` ([#2016](https://github.com/nf-core/tools/pull/2016))
- Fix error in tagging GitPod docker images during releases
- `nf-core sync` now supports the template YAML file using `-t/--template-yaml`.
- Fix bug when updating modules from old version in old folder structure
Expand Down
36 changes: 14 additions & 22 deletions nf_core/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,23 +104,13 @@ def run_nf_core():
nf_core_cli(auto_envvar_prefix="NFCORE")


# taken from https://github.com/pallets/click/issues/108#issuecomment-194465429
_common_options = [
click.option("--hide-progress", is_flag=True, default=False, help="Don't show progress bars."),
]


def common_options(func):
for option in reversed(_common_options):
func = option(func)
return func


@click.group(context_settings=dict(help_option_names=["-h", "--help"]))
@click.version_option(nf_core.__version__)
@click.option("-v", "--verbose", is_flag=True, default=False, help="Print verbose output to the console.")
@click.option("--hide-progress", is_flag=True, default=False, help="Don't show progress bars.")
@click.option("-l", "--log-file", help="Save a verbose log to a file.", metavar="<filename>")
def nf_core_cli(verbose, log_file):
@click.pass_context
def nf_core_cli(ctx, verbose, hide_progress, log_file):
"""
nf-core/tools provides a set of helper tools for use with nf-core Nextflow pipelines.

Expand All @@ -146,6 +136,11 @@ def nf_core_cli(verbose, log_file):
log_fh.setFormatter(logging.Formatter("[%(asctime)s] %(name)-20s [%(levelname)-7s] %(message)s"))
log.addHandler(log_fh)

ctx.obj = {
"verbose": verbose,
"hide_progress": hide_progress or verbose, # Always hide progress bar with verbose logging
}


# nf-core list
@nf_core_cli.command()
Expand Down Expand Up @@ -328,8 +323,8 @@ def create(name, description, author, version, no_git, force, outdir, template_y
@click.option("-w", "--fail-warned", is_flag=True, help="Convert warn tests to failures")
@click.option("--markdown", type=str, metavar="<filename>", help="File to write linting results to (Markdown)")
@click.option("--json", type=str, metavar="<filename>", help="File to write linting results to (JSON)")
@common_options
def lint(dir, release, fix, key, show_passed, fail_ignored, fail_warned, markdown, json, hide_progress):
@click.pass_context
def lint(ctx, dir, release, fix, key, show_passed, fail_ignored, fail_warned, markdown, json):
"""
Check pipeline code against nf-core guidelines.

Expand All @@ -351,7 +346,7 @@ def lint(dir, release, fix, key, show_passed, fail_ignored, fail_warned, markdow
# Run the lint tests!
try:
lint_obj, module_lint_obj = nf_core.lint.run_linting(
dir, release, fix, key, show_passed, fail_ignored, fail_warned, markdown, json, hide_progress
dir, release, fix, key, show_passed, fail_ignored, fail_warned, markdown, json, ctx.obj["hide_progress"]
)
if len(lint_obj.failed) + len(module_lint_obj.failed) > 0:
sys.exit(1)
Expand Down Expand Up @@ -729,10 +724,7 @@ def create_test_yml(ctx, tool, run_tests, output, force, no_prompts):
@click.option("--local", is_flag=True, help="Run additional lint tests for local modules")
@click.option("--passed", is_flag=True, help="Show passed tests")
@click.option("--fix-version", is_flag=True, help="Fix the module version if a newer version is available")
@common_options
def lint(
ctx, tool, dir, key, all, fail_warned, local, passed, fix_version, hide_progress
): # pylint: disable=redefined-outer-name
def lint(ctx, tool, dir, key, all, fail_warned, local, passed, fix_version): # pylint: disable=redefined-outer-name
"""
Lint one or more modules in a directory.

Expand All @@ -749,13 +741,13 @@ def lint(
ctx.obj["modules_repo_url"],
ctx.obj["modules_repo_branch"],
ctx.obj["modules_repo_no_pull"],
hide_progress,
ctx.obj["hide_progress"],
)
module_lint.lint(
module=tool,
key=key,
all_modules=all,
hide_progress=hide_progress,
hide_progress=ctx.obj["hide_progress"],
print_results=True,
local=local,
show_passed=passed,
Expand Down
4 changes: 3 additions & 1 deletion nf_core/modules/lint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ def __init__(
no_pull=False,
hide_progress=False,
):
super().__init__("modules", dir=dir, remote_url=remote_url, branch=branch, no_pull=no_pull, hide_progress=False)
super().__init__(
"modules", dir=dir, remote_url=remote_url, branch=branch, no_pull=no_pull, hide_progress=hide_progress
)

self.fail_warned = fail_warned
self.passed = []
Expand Down
1 change: 0 additions & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,6 @@ def test_lint(self, mock_lint, mock_is_pipeline):
"fail-warned": None,
"markdown": "output_file.md",
"json": "output_file.json",
"hide-progress": None,
}

cmd = ["lint"] + self.assemble_params(params)
Expand Down