From c81480a76af773c82242d142e2a6ba7e3a48e660 Mon Sep 17 00:00:00 2001 From: Phil Ewels Date: Thu, 10 Nov 2022 10:29:54 +0100 Subject: [PATCH 1/2] Refactor --hide-progress to be at the top level CLI --- .github/workflows/create-lint-wf.yml | 4 ++-- CHANGELOG.md | 1 + nf_core/__main__.py | 36 +++++++++++----------------- nf_core/modules/lint/__init__.py | 4 +++- 4 files changed, 20 insertions(+), 25 deletions(-) diff --git a/.github/workflows/create-lint-wf.yml b/.github/workflows/create-lint-wf.yml index 4dc87c0a14..4e19bc65d2 100644 --- a/.github/workflows/create-lint-wf.yml +++ b/.github/workflows/create-lint-wf.yml @@ -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 @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md index fbbc7c0ab8..68cb63b347 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/nf_core/__main__.py b/nf_core/__main__.py index 86ec88e1ee..771fe0de72 100755 --- a/nf_core/__main__.py +++ b/nf_core/__main__.py @@ -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="") -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. @@ -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() @@ -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="", help="File to write linting results to (Markdown)") @click.option("--json", type=str, metavar="", 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. @@ -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) @@ -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. @@ -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, diff --git a/nf_core/modules/lint/__init__.py b/nf_core/modules/lint/__init__.py index dff57f9da5..10063f90c5 100644 --- a/nf_core/modules/lint/__init__.py +++ b/nf_core/modules/lint/__init__.py @@ -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 = [] From b222d899db2560aa59ade89b0e1c2551cef236de Mon Sep 17 00:00:00 2001 From: Phil Ewels Date: Thu, 10 Nov 2022 11:32:15 +0100 Subject: [PATCH 2/2] Remove CLI param from pytest --- tests/test_cli.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index d8d9eb29c7..f991681b0f 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -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)