diff --git a/CHANGELOG.md b/CHANGELOG.md index 3fa2700c46..a63de2682e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ - Bump promoted Python version from 3.7 to 3.8 ([#1971](https://github.com/nf-core/tools/pull/1971)) - Fix incorrect file deletion in `nf-core launch` when `--params_in` has the same name as `--params_out` - Updated GitHub actions ([#1998](https://github.com/nf-core/tools/pull/1998), [#2001](https://github.com/nf-core/tools/pull/2001)) +- Code maintenance ([#1818](https://github.com/nf-core/tools/pull/1818)) - Track from where modules and subworkflows are installed ([#1999](https://github.com/nf-core/tools/pull/1999)) - Substitute ModulesCommand and SubworkflowsCommand by ComponentsCommand ([#2000](https://github.com/nf-core/tools/pull/2000)) - Don't print source file + line number on logging messages (except when verbose) ([#2015](https://github.com/nf-core/tools/pull/2015)) @@ -55,7 +56,7 @@ - Update MultiQC module, update supplying MultiQC default and custom config and logo files to module - Add a 'recommend' methods description text to MultiQC to help pipeline users report pipeline usage in publications ([#1749](https://github.com/nf-core/tools/pull/1749)) - Fix template spacing modified by JINJA ([#1830](https://github.com/nf-core/tools/pull/1830)) -- Fix MultiQC execution on template [#1855](https://github.com/nf-core/tools/pull/1855) +- Fix MultiQC execution on template ([#1855](https://github.com/nf-core/tools/pull/1855)) - Don't skip including `base.config` when skipping nf-core/configs ### Linting diff --git a/nf_core/lint/__init__.py b/nf_core/lint/__init__.py index a0de378d82..5430dde275 100644 --- a/nf_core/lint/__init__.py +++ b/nf_core/lint/__init__.py @@ -123,7 +123,7 @@ def run_linting( lint_obj._print_results(show_passed) module_lint_obj._print_results(show_passed) nf_core.lint_utils.print_joint_summary(lint_obj, module_lint_obj) - nf_core.lint_utils.print_fixes(lint_obj, module_lint_obj) + nf_core.lint_utils.print_fixes(lint_obj) # Save results to Markdown file if md_fn is not None: diff --git a/nf_core/lint_utils.py b/nf_core/lint_utils.py index 19d253c53c..b2521daef9 100644 --- a/nf_core/lint_utils.py +++ b/nf_core/lint_utils.py @@ -34,19 +34,21 @@ def print_joint_summary(lint_obj, module_lint_obj): console.print(table) -def print_fixes(lint_obj, module_lint_obj): +def print_fixes(lint_obj): """Prints available and applied fixes""" - if len(lint_obj.could_fix): - fix_cmd = "nf-core lint {} --fix {}".format( - "" if lint_obj.wf_path == "." else f"--dir {lint_obj.wf_path}", " --fix ".join(lint_obj.could_fix) - ) + if lint_obj.could_fix: + fix_flags = "".join([f" --fix {fix}" for fix in lint_obj.could_fix]) + wf_dir = "" if lint_obj.wf_path == "." else f"--dir {lint_obj.wf_path}" + fix_cmd = f"nf-core lint {wf_dir} {fix_flags}" console.print( - f"\nTip: Some of these linting errors can automatically be resolved with the following command:\n\n[blue] {fix_cmd}\n" + "\nTip: Some of these linting errors can automatically be resolved with the following command:\n\n" + f"[blue] {fix_cmd}\n" ) if len(lint_obj.fix): console.print( - "Automatic fixes applied. Please check with 'git diff' and revert any changes you do not want with 'git checkout '." + "Automatic fixes applied. " + "Please check with 'git diff' and revert any changes you do not want with 'git checkout '." ) diff --git a/nf_core/modules/lint/__init__.py b/nf_core/modules/lint/__init__.py index 73c7f57d2b..64251d8e8c 100644 --- a/nf_core/modules/lint/__init__.py +++ b/nf_core/modules/lint/__init__.py @@ -134,7 +134,6 @@ def lint( module=None, key=(), all_modules=False, - hide_progress=False, print_results=True, show_passed=False, local=False, diff --git a/nf_core/modules/lint/main_nf.py b/nf_core/modules/lint/main_nf.py index f0098c8ab7..7eaa46a874 100644 --- a/nf_core/modules/lint/main_nf.py +++ b/nf_core/modules/lint/main_nf.py @@ -99,18 +99,18 @@ def main_nf(module_lint_object, module, fix_version, progress_bar): continue # Perform state-specific linting checks - if state == "process" and not _is_empty(module, l): + if state == "process" and not _is_empty(l): process_lines.append(l) - if state == "input" and not _is_empty(module, l): + if state == "input" and not _is_empty(l): inputs.extend(_parse_input(module, l)) - if state == "output" and not _is_empty(module, l): + if state == "output" and not _is_empty(l): outputs += _parse_output(module, l) outputs = list(set(outputs)) # remove duplicate 'meta's - if state == "when" and not _is_empty(module, l): + if state == "when" and not _is_empty(l): when_lines.append(l) - if state == "script" and not _is_empty(module, l): + if state == "script" and not _is_empty(l): script_lines.append(l) - if state == "shell" and not _is_empty(module, l): + if state == "shell" and not _is_empty(l): shell_lines.append(l) # Check that we have required sections @@ -390,7 +390,7 @@ def _parse_output(self, line): return output -def _is_empty(self, line): +def _is_empty(line): """Check whether a line is empty or a comment""" empty = False if line.strip().startswith("//"): @@ -421,7 +421,7 @@ def _fix_module_version(self, current_version, latest_version, singularity_tag, build_type = _container_type(l) if build_type == "bioconda": new_lines.append(re.sub(rf"{current_version}", f"{latest_version}", line)) - elif build_type == "singularity" or build_type == "docker": + elif build_type in ("singularity", "docker"): # Check that the new url is valid new_url = re.search( "(?:['\"])(.+)(?:['\"])", re.sub(rf"{singularity_tag}", f"{latest_version}--{build}", line) @@ -431,7 +431,8 @@ def _fix_module_version(self, current_version, latest_version, singularity_tag, "https://" + new_url if not new_url.startswith("https://") else new_url, stream=True ) log.debug( - f"Connected to URL: {'https://' + new_url if not new_url.startswith('https://') else new_url}, status_code: {response_new_container.status_code}" + f"Connected to URL: {'https://' + new_url if not new_url.startswith('https://') else new_url}, " + f"status_code: {response_new_container.status_code}" ) except (requests.exceptions.RequestException, sqlite3.InterfaceError) as e: log.debug(f"Unable to connect to url '{new_url}' due to error: {e}") diff --git a/nf_core/modules/lint/module_deprecations.py b/nf_core/modules/lint/module_deprecations.py index aa4cabd7b2..8ab5b68c2e 100644 --- a/nf_core/modules/lint/module_deprecations.py +++ b/nf_core/modules/lint/module_deprecations.py @@ -4,7 +4,7 @@ log = logging.getLogger(__name__) -def module_deprecations(module_lint_object, module): +def module_deprecations(_, module): """ Check that the modules are up to the latest nf-core standard """ diff --git a/nf_core/modules/lint/module_tests.py b/nf_core/modules/lint/module_tests.py index b0c9fa0ee2..0b76acb944 100644 --- a/nf_core/modules/lint/module_tests.py +++ b/nf_core/modules/lint/module_tests.py @@ -9,7 +9,7 @@ log = logging.getLogger(__name__) -def module_tests(module_lint_object, module): +def module_tests(_, module): """ Lint the tests of a module in ``nf-core/modules`` diff --git a/nf_core/modules/lint/module_todos.py b/nf_core/modules/lint/module_todos.py index 8b685a7172..b48725cd9e 100644 --- a/nf_core/modules/lint/module_todos.py +++ b/nf_core/modules/lint/module_todos.py @@ -5,7 +5,7 @@ log = logging.getLogger(__name__) -def module_todos(module_lint_object, module): +def module_todos(_, module): """ Look for TODO statements in the module files diff --git a/nf_core/modules/test_yml_builder.py b/nf_core/modules/test_yml_builder.py index 854700bb89..2d20785b7c 100644 --- a/nf_core/modules/test_yml_builder.py +++ b/nf_core/modules/test_yml_builder.py @@ -56,7 +56,8 @@ def run(self): """Run build steps""" if not self.no_prompts: log.info( - "[yellow]Press enter to use default values [cyan bold](shown in brackets) [yellow]or type your own responses" + "[yellow]Press enter to use default values " + "[cyan bold](shown in brackets) [yellow]or type your own responses" ) self.check_inputs() self.scrape_workflow_entry_points() @@ -170,7 +171,10 @@ def build_single_test(self, entry_point): while ep_test["command"] == "": # Don't think we need the last `-c` flag, but keeping to avoid having to update 100s modules. # See https://github.com/nf-core/tools/issues/1562 - default_val = f"nextflow run ./tests/modules/nf-core/{self.module_name} -entry {entry_point} -c ./tests/config/nextflow.config -c ./tests/modules/nf-core/{self.module_name}/nextflow.config" + default_val = ( + f"nextflow run ./tests/modules/nf-core/{self.module_name} -entry {entry_point} " + f"-c ./tests/config/nextflow.config -c ./tests/modules/nf-core/{self.module_name}/nextflow.config" + ) if self.no_prompts: ep_test["command"] = default_val else: @@ -192,7 +196,7 @@ def build_single_test(self, entry_point): ).strip() ep_test["tags"] = [t.strip() for t in prompt_tags.split(",")] - ep_test["files"] = self.get_md5_sums(entry_point, ep_test["command"]) + ep_test["files"] = self.get_md5_sums(ep_test["command"]) return ep_test @@ -253,7 +257,7 @@ def create_test_file_dict(self, results_dir, is_repeat=False): return test_files - def get_md5_sums(self, entry_point, command, results_dir=None, results_dir_repeat=None): + def get_md5_sums(self, command, results_dir=None, results_dir_repeat=None): """ Recursively go through directories and subdirectories and generate tuples of (, ) diff --git a/nf_core/utils.py b/nf_core/utils.py index f5a464b3c2..117c052e0a 100644 --- a/nf_core/utils.py +++ b/nf_core/utils.py @@ -338,7 +338,7 @@ def setup_requests_cachedir(): return config -def wait_cli_function(poll_func, poll_every=20): +def wait_cli_function(poll_func, refresh_per_second=20): """ Display a command-line spinner while calling a function repeatedly. @@ -346,14 +346,14 @@ def wait_cli_function(poll_func, poll_every=20): Arguments: poll_func (function): Function to call - poll_every (int): How many tenths of a second to wait between function calls. Default: 20. + refresh_per_second (int): Refresh this many times per second. Default: 20. Returns: None. Just sits in an infite loop until the function returns True. """ try: spinner = Spinner("dots2", "Use ctrl+c to stop waiting and force exit.") - with Live(spinner, refresh_per_second=20): + with Live(spinner, refresh_per_second=refresh_per_second): while True: if poll_func(): break diff --git a/tests/modules/create_test_yml.py b/tests/modules/create_test_yml.py index 0d06339375..dab2668c14 100644 --- a/tests/modules/create_test_yml.py +++ b/tests/modules/create_test_yml.py @@ -35,9 +35,7 @@ def test_modules_create_test_yml_get_md5(self, test_file_dir): meta_builder = nf_core.modules.ModulesTestYmlBuilder("test/tool", self.pipeline_dir, False, "./", False, True) with open(os.path.join(test_file_dir, "test_file.txt"), "w") as fh: fh.write("this line is just for testing") - test_files = meta_builder.get_md5_sums( - entry_point="dummy", command="dummy", results_dir=test_file_dir, results_dir_repeat=test_file_dir - ) + test_files = meta_builder.get_md5_sums(command="dummy", results_dir=test_file_dir, results_dir_repeat=test_file_dir) assert test_files[0]["md5sum"] == "2191e06b28b5ba82378bcc0672d01786"