diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1827289b7..b902ab3ea 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.8.6 + rev: v0.9.3 hooks: - id: ruff # linter args: [--fix, --exit-non-zero-on-fix] # sort imports and fix diff --git a/nf_core/components/components_differ.py b/nf_core/components/components_differ.py index db51c1910..18454471f 100644 --- a/nf_core/components/components_differ.py +++ b/nf_core/components/components_differ.py @@ -271,9 +271,7 @@ def print_diff( console = Console(force_terminal=nf_core.utils.rich_force_colors()) if current_version is not None and new_version is not None: log.info( - f"Changes in component '{Path(repo_path, component)}' between" - f" ({current_version}) and" - f" ({new_version})" + f"Changes in component '{Path(repo_path, component)}' between ({current_version}) and ({new_version})" ) else: log.info(f"Changes in component '{Path(repo_path, component)}'") diff --git a/nf_core/components/info.py b/nf_core/components/info.py index 31769785a..4cf7dc946 100644 --- a/nf_core/components/info.py +++ b/nf_core/components/info.py @@ -265,9 +265,9 @@ def generate_component_info_help(self): intro_text.append( Text.from_markup( ":globe_with_meridians: Repository: " - f"{ '[link={self.remote_location}]' if self.remote_location.startswith('http') else ''}" + f"{'[link={self.remote_location}]' if self.remote_location.startswith('http') else ''}" f"{self.remote_location}" - f"{'[/link]' if self.remote_location.startswith('http') else '' }" + f"{'[/link]' if self.remote_location.startswith('http') else ''}" "\n" ) ) diff --git a/nf_core/components/lint/__init__.py b/nf_core/components/lint/__init__.py index 96b611cc2..0a4fcbb3d 100644 --- a/nf_core/components/lint/__init__.py +++ b/nf_core/components/lint/__init__.py @@ -102,7 +102,7 @@ def __init__( continue if isinstance(components, str): raise LookupError( - f"Error parsing modules.json: {components}. " f"Please check the file for errors or try again." + f"Error parsing modules.json: {components}. Please check the file for errors or try again." ) for org, comp in components: self.all_remote_components.append( diff --git a/nf_core/components/remove.py b/nf_core/components/remove.py index 37208629c..316b8e7cb 100644 --- a/nf_core/components/remove.py +++ b/nf_core/components/remove.py @@ -176,6 +176,6 @@ def remove(self, component, removed_by=None, removed_components=None, force=Fals f"Did not remove '{component}', because it was also manually installed. Only updated 'installed_by' entry in modules.json." ) log.info( - f"""Did not remove {self.component_type[:-1]} '{component}', because it was also installed by {', '.join(f"'{d}'" for d in installed_by)}. Only updated the 'installed_by' entry in modules.json.""" + f"""Did not remove {self.component_type[:-1]} '{component}', because it was also installed by {", ".join(f"'{d}'" for d in installed_by)}. Only updated the 'installed_by' entry in modules.json.""" ) return removed diff --git a/nf_core/modules/lint/meta_yml.py b/nf_core/modules/lint/meta_yml.py index 76345bdcb..977ea819a 100644 --- a/nf_core/modules/lint/meta_yml.py +++ b/nf_core/modules/lint/meta_yml.py @@ -62,7 +62,7 @@ def meta_yml(module_lint_object: ComponentLint, module: NFCoreComponent, allow_m ).get("meta.yml") if lines is not None: yaml = ruamel.yaml.YAML() - meta_yaml = yaml.safe_load("".join(lines)) + meta_yaml = yaml.load("".join(lines)) if meta_yaml is None: module.failed.append(("meta_yml_exists", "Module `meta.yml` does not exist", module.meta_yml)) return @@ -82,7 +82,7 @@ def meta_yml(module_lint_object: ComponentLint, module: NFCoreComponent, allow_m if len(e.path) > 0: hint = f"\nCheck the entry for `{e.path[0]}`." if e.message.startswith("None is not of type 'object'") and len(e.path) > 2: - hint = f"\nCheck that the child entries of {str(e.path[0])+'.'+str(e.path[2])} are indented correctly." + hint = f"\nCheck that the child entries of {str(e.path[0]) + '.' + str(e.path[2])} are indented correctly." if e.schema and isinstance(e.schema, dict) and "message" in e.schema: e.message = e.schema["message"] incorrect_value = meta_yaml diff --git a/nf_core/pipelines/download.py b/nf_core/pipelines/download.py index c0f6e8c2f..3d371ca68 100644 --- a/nf_core/pipelines/download.py +++ b/nf_core/pipelines/download.py @@ -202,7 +202,7 @@ def download_workflow(self): raise DownloadError(e) from e summary_log = [ - f"Pipeline revision: '{', '.join(self.revision) if len(self.revision) < 5 else self.revision[0]+',['+str(len(self.revision)-2)+' more revisions],'+self.revision[-1]}'", + f"Pipeline revision: '{', '.join(self.revision) if len(self.revision) < 5 else self.revision[0] + ',[' + str(len(self.revision) - 2) + ' more revisions],' + self.revision[-1]}'", f"Use containers: '{self.container_system}'", ] if self.container_system: @@ -1908,8 +1908,8 @@ def __init__( log.error(self.error_type.message) log.info(self.error_type.helpmessage) - log.debug(f'Failed command:\n{" ".join(singularity_command)}') - log.debug(f'Singularity error messages:\n{"".join(error_msg)}') + log.debug(f"Failed command:\n{' '.join(singularity_command)}") + log.debug(f"Singularity error messages:\n{''.join(error_msg)}") raise self.error_type diff --git a/nf_core/pipelines/lint/multiqc_config.py b/nf_core/pipelines/lint/multiqc_config.py index fec5b518e..49f632faa 100644 --- a/nf_core/pipelines/lint/multiqc_config.py +++ b/nf_core/pipelines/lint/multiqc_config.py @@ -122,7 +122,7 @@ def multiqc_config(self) -> Dict[str, List[str]]: f"The expected comment is: \n" f"```{hint}``` \n" f"The current comment is: \n" - f"```{ mqc_yml['report_comment'].strip()}```" + f"```{mqc_yml['report_comment'].strip()}```" ) else: passed.append("`assets/multiqc_config.yml` contains a matching 'report_comment'.") diff --git a/nf_core/pipelines/lint/version_consistency.py b/nf_core/pipelines/lint/version_consistency.py index 2f9cead83..e347e8e82 100644 --- a/nf_core/pipelines/lint/version_consistency.py +++ b/nf_core/pipelines/lint/version_consistency.py @@ -53,7 +53,7 @@ def version_consistency(self): # Check if they are consistent if len(set(versions.values())) != 1: failed.append( - "The versioning is not consistent between container, release tag " "and config. Found {}".format( + "The versioning is not consistent between container, release tag and config. Found {}".format( ", ".join([f"{k} = {v}" for k, v in versions.items()]) ) ) diff --git a/nf_core/pipelines/params_file.py b/nf_core/pipelines/params_file.py index 69326c142..48e4dfe46 100644 --- a/nf_core/pipelines/params_file.py +++ b/nf_core/pipelines/params_file.py @@ -19,7 +19,7 @@ "of nextflow run with the {pipeline_name} pipeline." ) -USAGE = "Uncomment lines with a single '#' if you want to pass the parameter " "to the pipeline." +USAGE = "Uncomment lines with a single '#' if you want to pass the parameter to the pipeline." H1_SEPERATOR = "## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" H2_SEPERATOR = "## ----------------------------------------------------------------------------" @@ -107,7 +107,7 @@ def get_pipeline(self) -> Optional[bool]: # Prompt for pipeline if not supplied if self.pipeline is None: launch_type = questionary.select( - "Generate parameter file for local pipeline " "or remote GitHub pipeline?", + "Generate parameter file for local pipeline or remote GitHub pipeline?", choices=["Remote pipeline", "Local path"], style=nf_core.utils.nfcore_question_style, ).unsafe_ask() diff --git a/nf_core/pipelines/rocrate.py b/nf_core/pipelines/rocrate.py index b0f9611f1..2bf46beed 100644 --- a/nf_core/pipelines/rocrate.py +++ b/nf_core/pipelines/rocrate.py @@ -212,7 +212,7 @@ def set_main_entity(self, main_entity_filename: str): else: url = self.version self.crate.mainEntity.append_to( - "url", f"https://nf-co.re/{self.crate.name.replace('nf-core/','')}/{url}/", compact=True + "url", f"https://nf-co.re/{self.crate.name.replace('nf-core/', '')}/{url}/", compact=True ) self.crate.mainEntity.append_to("version", self.version, compact=True) diff --git a/nf_core/pipelines/schema.py b/nf_core/pipelines/schema.py index b425ec64e..47990b106 100644 --- a/nf_core/pipelines/schema.py +++ b/nf_core/pipelines/schema.py @@ -770,7 +770,7 @@ def build_schema(self, pipeline_dir, no_prompts, web_only, url): if self.web_schema_build_web_url: log.info( "To save your work, open {}\n" - f"Click the blue 'Finished' button, copy the schema and paste into this file: { self.web_schema_build_web_url, self.schema_filename}" + f"Click the blue 'Finished' button, copy the schema and paste into this file: {self.web_schema_build_web_url, self.schema_filename}" ) return False diff --git a/nf_core/pipelines/sync.py b/nf_core/pipelines/sync.py index 14365da3f..f0c8f4a32 100644 --- a/nf_core/pipelines/sync.py +++ b/nf_core/pipelines/sync.py @@ -345,7 +345,7 @@ def create_merge_base_branch(self): if merge_branch_format.match(branch) ] ) - new_branch = f"{self.original_merge_branch}-{max_branch+1}" + new_branch = f"{self.original_merge_branch}-{max_branch + 1}" log.info(f"Branch already existed: '{self.merge_branch}', creating branch '{new_branch}' instead.") self.merge_branch = new_branch diff --git a/nf_core/subworkflows/lint/meta_yml.py b/nf_core/subworkflows/lint/meta_yml.py index 262c80f94..8a2120ed0 100644 --- a/nf_core/subworkflows/lint/meta_yml.py +++ b/nf_core/subworkflows/lint/meta_yml.py @@ -3,7 +3,7 @@ from pathlib import Path import jsonschema.validators -import yaml +import ruamel.yaml import nf_core.components.components_utils from nf_core.components.lint import LintExceptionError @@ -43,7 +43,8 @@ def meta_yml(subworkflow_lint_object, subworkflow, allow_missing: bool = False): try: with open(subworkflow.meta_yml) as fh: - meta_yaml = yaml.safe_load(fh) + yaml = ruamel.yaml.YAML(typ="safe") + meta_yaml = yaml.load(fh) subworkflow.passed.append(("meta_yml_exists", "Subworkflow `meta.yml` exists", subworkflow.meta_yml)) except FileNotFoundError: subworkflow.failed.append(("meta_yml_exists", "Subworkflow `meta.yml` does not exist", subworkflow.meta_yml)) @@ -62,7 +63,7 @@ def meta_yml(subworkflow_lint_object, subworkflow, allow_missing: bool = False): if len(e.path) > 0: hint = f"\nCheck the entry for `{e.path[0]}`." if e.message.startswith("None is not of type 'object'") and len(e.path) > 2: - hint = f"\nCheck that the child entries of {e.path[0]}.{e.path[2]} are indented correctly." + hint = f"\nCheck that the child entries of {str(e.path[0]) + '.' + str(e.path[2])} are indented correctly." subworkflow.failed.append( ( "meta_yml_valid", diff --git a/tests/modules/test_lint.py b/tests/modules/test_lint.py index b71c729d1..c641b6dc9 100644 --- a/tests/modules/test_lint.py +++ b/tests/modules/test_lint.py @@ -296,15 +296,15 @@ def test_modules_lint_check_url(self): if line.strip(): check_container_link_line(mocked_ModuleLint, line, registry="quay.io") - assert ( - len(mocked_ModuleLint.passed) == passed - ), f"{test}: Expected {passed} PASS, got {len(mocked_ModuleLint.passed)}." - assert ( - len(mocked_ModuleLint.warned) == warned - ), f"{test}: Expected {warned} WARN, got {len(mocked_ModuleLint.warned)}." - assert ( - len(mocked_ModuleLint.failed) == failed - ), f"{test}: Expected {failed} FAIL, got {len(mocked_ModuleLint.failed)}." + assert len(mocked_ModuleLint.passed) == passed, ( + f"{test}: Expected {passed} PASS, got {len(mocked_ModuleLint.passed)}." + ) + assert len(mocked_ModuleLint.warned) == warned, ( + f"{test}: Expected {warned} WARN, got {len(mocked_ModuleLint.warned)}." + ) + assert len(mocked_ModuleLint.failed) == failed, ( + f"{test}: Expected {failed} FAIL, got {len(mocked_ModuleLint.failed)}." + ) def test_modules_lint_update_meta_yml(self): """update the meta.yml of a module""" diff --git a/tests/pipelines/test_create.py b/tests/pipelines/test_create.py index f83cc274f..7c0eebe7d 100644 --- a/tests/pipelines/test_create.py +++ b/tests/pipelines/test_create.py @@ -158,9 +158,9 @@ def test_template_customisation_all_files_grouping(self): str_path = str((Path(root) / file).relative_to(PIPELINE_TEMPLATE)) if str_path not in base_required_files: try: - assert ( - str_path in all_skipped_files - ), f"Template file `{str_path}` not present in a group for pipeline customisation in `template_features.yml`." + assert str_path in all_skipped_files, ( + f"Template file `{str_path}` not present in a group for pipeline customisation in `template_features.yml`." + ) except AssertionError: if "/" in str_path: # Check if the parent directory is in the skipped files @@ -170,6 +170,8 @@ def test_template_customisation_all_files_grouping(self): if upper_dir in all_skipped_files: upper_dir_present = True break - assert upper_dir_present, f"Template file `{str_path}` not present in a group for pipeline customisation in `template_features.yml`." + assert upper_dir_present, ( + f"Template file `{str_path}` not present in a group for pipeline customisation in `template_features.yml`." + ) else: raise