diff --git a/CHANGELOG.md b/CHANGELOG.md index e51660e52c..61ca21ffed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ - Mock biocontainers and anaconda api calls in modules and subworkflows tests [#1967](https://github.com/nf-core/tools/pull/1967) - Run tests with Python 3.11 ([#1970](https://github.com/nf-core/tools/pull/1970)) - 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` ### Modules diff --git a/nf_core/launch.py b/nf_core/launch.py index d57d9f112f..53fce1f43f 100644 --- a/nf_core/launch.py +++ b/nf_core/launch.py @@ -120,12 +120,19 @@ def launch_pipeline(self): # Check if the output file exists already if os.path.exists(self.params_out): - log.warning(f"Parameter output file already exists! {os.path.relpath(self.params_out)}") + # if params_in has the same name as params_out, don't ask to overwrite + if self.params_in and os.path.abspath(self.params_in) == os.path.abspath(self.params_out): + log.warning( + f"The parameter input file has the same name as the output file! {os.path.relpath(self.params_out)} will be overwritten." + ) + else: + log.warning(f"Parameter output file already exists! {os.path.relpath(self.params_out)}") if Confirm.ask("[yellow]Do you want to overwrite this file?"): - os.remove(self.params_out) - log.info(f"Deleted {self.params_out}\n") + if not (self.params_in and os.path.abspath(self.params_in) == os.path.abspath(self.params_out)): + os.remove(self.params_out) + log.info(f"Deleted {self.params_out}\n") else: - log.info("Exiting. Use --params-out to specify a custom filename.") + log.info("Exiting. Use --params-out to specify a custom output filename.") return False log.info( @@ -716,6 +723,6 @@ def launch_workflow(self): """Launch nextflow if required""" log.info(f"[bold underline]Nextflow command:[/]\n[magenta]{self.nextflow_cmd}\n\n") - if Confirm.ask("Do you want to run this command now? "): + if Confirm.ask("Do you want to run this command now? ", default=True): log.info("Launching workflow! :rocket:") subprocess.call(self.nextflow_cmd, shell=True)