From 20de879078501417c6fe5c69a065e35da8b3622f Mon Sep 17 00:00:00 2001 From: mirpedrol Date: Fri, 20 Dec 2024 15:01:11 +0100 Subject: [PATCH 1/5] fix trailing spaces in conf/test.config --- nf_core/pipeline-template/conf/test.config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nf_core/pipeline-template/conf/test.config b/nf_core/pipeline-template/conf/test.config index bea6f670d0..54543cae1f 100644 --- a/nf_core/pipeline-template/conf/test.config +++ b/nf_core/pipeline-template/conf/test.config @@ -27,7 +27,7 @@ params { // TODO nf-core: Give any required params for the test so that command line flags are not needed input = params.pipelines_testdata_base_path + 'viralrecon/samplesheet/samplesheet_test_illumina_amplicon.csv' - {% if igenomes -%} + {%- if igenomes -%} // Genome references genome = 'R64-1-1' {%- endif %} From 3cb8775230583557698397bb07eeb69d8f73b2a5 Mon Sep 17 00:00:00 2001 From: mirpedrol Date: Fri, 20 Dec 2024 15:02:50 +0100 Subject: [PATCH 2/5] run pre-comit when rendering template for pipelines sync --- nf_core/pipelines/create/create.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/nf_core/pipelines/create/create.py b/nf_core/pipelines/create/create.py index 4f90ca17f9..439cd5a359 100644 --- a/nf_core/pipelines/create/create.py +++ b/nf_core/pipelines/create/create.py @@ -386,6 +386,9 @@ def render_template(self) -> None: yaml.dump(config_yml.model_dump(exclude_none=True), fh, Dumper=custom_yaml_dumper()) log.debug(f"Dumping pipeline template yml to pipeline config file '{config_fn.name}'") + # Run prettier on files for pipelines sync + run_prettier_on_file([str(f) for f in self.outdir.glob("**/*")]) + def fix_linting(self): """ Updates the .nf-core.yml with linting configurations From 6b43881c39e63f8ac5be9319efd2a849c7893982 Mon Sep 17 00:00:00 2001 From: mirpedrol Date: Fri, 20 Dec 2024 15:19:15 +0100 Subject: [PATCH 3/5] add newline --- nf_core/pipeline-template/conf/test.config | 1 + 1 file changed, 1 insertion(+) diff --git a/nf_core/pipeline-template/conf/test.config b/nf_core/pipeline-template/conf/test.config index 54543cae1f..ebe720f295 100644 --- a/nf_core/pipeline-template/conf/test.config +++ b/nf_core/pipeline-template/conf/test.config @@ -28,6 +28,7 @@ params { input = params.pipelines_testdata_base_path + 'viralrecon/samplesheet/samplesheet_test_illumina_amplicon.csv' {%- if igenomes -%} + // Genome references genome = 'R64-1-1' {%- endif %} From 4bd4d239744cd725be63c1a93aa3ab2f0e7a78e8 Mon Sep 17 00:00:00 2001 From: mirpedrol Date: Fri, 20 Dec 2024 15:21:14 +0100 Subject: [PATCH 4/5] bump to 3.1.2dev --- .gitpod.yml | 2 +- CHANGELOG.md | 16 ++++++++++++++++ setup.py | 2 +- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/.gitpod.yml b/.gitpod.yml index db31d01bed..d5948695bf 100644 --- a/.gitpod.yml +++ b/.gitpod.yml @@ -1,4 +1,4 @@ -image: nfcore/gitpod:latest +image: nfcore/gitpod:dev tasks: - name: install current state of nf-core/tools and setup pre-commit command: | diff --git a/CHANGELOG.md b/CHANGELOG.md index 926535077d..aa465b85b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,21 @@ # nf-core/tools: Changelog +## v3.1.2dev + +### Template + +### Linting + +### Modules + +### Subworkflows + +### General + +- run pre-comit when rendering template for pipelines sync + +### Version updates + ## [v3.1.1 - Brass Boxfish Patch](https://github.com/nf-core/tools/releases/tag/3.1.1) - [2024-12-20] ### Template diff --git a/setup.py b/setup.py index 5617520e91..fb1621adfc 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import find_packages, setup -version = "3.1.1" +version = "3.1.2" with open("README.md") as f: readme = f.read() From 80e06dcbeb197c66683d66b6bb8ab663fd2a0a39 Mon Sep 17 00:00:00 2001 From: mirpedrol Date: Mon, 13 Jan 2025 12:12:00 +0100 Subject: [PATCH 5/5] do not run pre-commit if we are not on a git repo --- nf_core/pipelines/create/create.py | 1 + nf_core/pipelines/lint_utils.py | 44 ++++++++++++++++++++---------- 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/nf_core/pipelines/create/create.py b/nf_core/pipelines/create/create.py index 439cd5a359..86ac022772 100644 --- a/nf_core/pipelines/create/create.py +++ b/nf_core/pipelines/create/create.py @@ -387,6 +387,7 @@ def render_template(self) -> None: log.debug(f"Dumping pipeline template yml to pipeline config file '{config_fn.name}'") # Run prettier on files for pipelines sync + log.debug("Running prettier on pipeline files") run_prettier_on_file([str(f) for f in self.outdir.glob("**/*")]) def fix_linting(self): diff --git a/nf_core/pipelines/lint_utils.py b/nf_core/pipelines/lint_utils.py index a6b98b1899..d41cf16b12 100644 --- a/nf_core/pipelines/lint_utils.py +++ b/nf_core/pipelines/lint_utils.py @@ -70,6 +70,15 @@ def print_fixes(lint_obj): ) +def check_git_repo() -> bool: + """Check if the current directory is a git repository.""" + try: + subprocess.check_output(["git", "rev-parse", "--is-inside-work-tree"]) + return True + except subprocess.CalledProcessError: + return False + + def run_prettier_on_file(file: Union[Path, str, List[str]]) -> None: """Run the pre-commit hook prettier on a file. @@ -80,6 +89,8 @@ def run_prettier_on_file(file: Union[Path, str, List[str]]) -> None: If Prettier is not installed, a warning is logged. """ + is_git = check_git_repo() + nf_core_pre_commit_config = Path(nf_core.__file__).parent / ".pre-commit-prettier-config.yaml" args = ["pre-commit", "run", "--config", str(nf_core_pre_commit_config), "prettier"] if isinstance(file, List): @@ -87,21 +98,24 @@ def run_prettier_on_file(file: Union[Path, str, List[str]]) -> None: else: args.extend(["--files", str(file)]) - try: - subprocess.run(args, capture_output=True, check=True) - log.debug(f"${subprocess.STDOUT}") - except subprocess.CalledProcessError as e: - if ": SyntaxError: " in e.stdout.decode(): - log.critical(f"Can't format {file} because it has a syntax error.\n{e.stdout.decode()}") - elif "files were modified by this hook" in e.stdout.decode(): - all_lines = [line for line in e.stdout.decode().split("\n")] - files = "\n".join(all_lines[3:]) - log.debug(f"The following files were modified by prettier:\n {files}") - else: - log.warning( - "There was an error running the prettier pre-commit hook.\n" - f"STDOUT: {e.stdout.decode()}\nSTDERR: {e.stderr.decode()}" - ) + if is_git: + try: + proc = subprocess.run(args, capture_output=True, check=True) + log.debug(f"{proc.stdout.decode()}") + except subprocess.CalledProcessError as e: + if ": SyntaxError: " in e.stdout.decode(): + log.critical(f"Can't format {file} because it has a syntax error.\n{e.stdout.decode()}") + elif "files were modified by this hook" in e.stdout.decode(): + all_lines = [line for line in e.stdout.decode().split("\n")] + files = "\n".join(all_lines[3:]) + log.debug(f"The following files were modified by prettier:\n {files}") + else: + log.warning( + "There was an error running the prettier pre-commit hook.\n" + f"STDOUT: {e.stdout.decode()}\nSTDERR: {e.stderr.decode()}" + ) + else: + log.debug("Not in a git repository, skipping pre-commit hook.") def dump_json_with_prettier(file_name, file_content):