From 9f61e8584ffc2f7a8417c226c04d8e15fc4dc2a4 Mon Sep 17 00:00:00 2001 From: mirpedrol Date: Fri, 13 Dec 2024 13:30:05 +0100 Subject: [PATCH] run pre-commit from a git repo --- nf_core/pipelines/create/create.py | 8 +++++--- nf_core/pipelines/lint_utils.py | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/nf_core/pipelines/create/create.py b/nf_core/pipelines/create/create.py index 0e2c683e6..9c3db544f 100644 --- a/nf_core/pipelines/create/create.py +++ b/nf_core/pipelines/create/create.py @@ -266,6 +266,11 @@ def init_pipeline(self): # Init the git repository and make the first commit if not self.no_git: self.git_init_pipeline() + # Run prettier on files + current_dir = Path.cwd() + os.chdir(self.outdir) + run_prettier_on_file([str(f) for f in self.outdir.glob("**/*")]) + os.chdir(current_dir) if self.config.is_nfcore and not self.is_interactive: log.info( @@ -378,9 +383,6 @@ def render_template(self) -> None: yaml.safe_dump(config_yml.model_dump(exclude_none=True), fh) log.debug(f"Dumping pipeline template yml to pipeline config file '{config_fn.name}'") - # Run prettier on files - run_prettier_on_file([str(f) for f in self.outdir.glob("**/*")]) - def fix_linting(self): """ Updates the .nf-core.yml with linting configurations diff --git a/nf_core/pipelines/lint_utils.py b/nf_core/pipelines/lint_utils.py index b4c56c600..a6b98b189 100644 --- a/nf_core/pipelines/lint_utils.py +++ b/nf_core/pipelines/lint_utils.py @@ -97,7 +97,7 @@ def run_prettier_on_file(file: Union[Path, str, List[str]]) -> None: 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}") - elif e.stderr.decode(): + else: log.warning( "There was an error running the prettier pre-commit hook.\n" f"STDOUT: {e.stdout.decode()}\nSTDERR: {e.stderr.decode()}"