From 2e076d135b47952c68b5ded3b3b3b322cf9a0756 Mon Sep 17 00:00:00 2001 From: mashehu Date: Mon, 19 Feb 2024 17:01:48 +0100 Subject: [PATCH 1/3] move also subdirectories during update --- nf_core/components/update.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/nf_core/components/update.py b/nf_core/components/update.py index 46136bc8da..7972fe80f7 100644 --- a/nf_core/components/update.py +++ b/nf_core/components/update.py @@ -737,15 +737,18 @@ def move_files_from_tmp_dir(self, component: str, install_folder: str, repo_path new_version (str): The version of the module/subworkflow that was installed. """ temp_component_dir = Path(install_folder, component) - files = [f.name for f in temp_component_dir.iterdir() if f.is_file()] + files = [] + for file_path in Path(temp_component_dir).rglob("*"): + if file_path.is_file(): + files.append(file_path) pipeline_path = Path(self.dir, self.component_type, repo_path, component) if pipeline_path.exists(): pipeline_files = [f.name for f in pipeline_path.iterdir() if f.is_file()] # check if any *.config file exists in the pipeline - if any([f.endswith(".config") for f in pipeline_files]): + if any([str(f).endswith(".config") for f in pipeline_files]): # move the *.config file to the temporary directory - config_files = [f for f in files if f.endswith(".config")] + config_files = [f for f in files if str(f).endswith(".config")] for config_file in config_files: log.debug(f"Moving '{component}/{config_file}' to updated component") shutil.move(Path(pipeline_path, config_file), Path(temp_component_dir, config_file)) @@ -757,11 +760,16 @@ def move_files_from_tmp_dir(self, component: str, install_folder: str, repo_path log.debug(f"Removing old version of {self.component_type[:-1]} '{component}'") self.clear_component_dir(component, str(pipeline_path)) - os.makedirs(pipeline_path) + pipeline_path.mkdir(parents=True, exist_ok=True) for file in files: + file = file.relative_to(temp_component_dir) path = Path(temp_component_dir, file) - if os.path.exists(path): - shutil.move(path, Path(pipeline_path, file)) + if path.exists(): + log.debug(f"Moving '{file}' to updated component") + dest = Path(pipeline_path, file) + dest.parent.mkdir(parents=True, exist_ok=True) + shutil.move(path, dest) + log.debug(f"{os.listdir(pipeline_path)}") log.info(f"Updating '{repo_path}/{component}'") log.debug(f"Updating {self.component_type[:-1]} '{component}' to {new_version} from {repo_path}") From e070ebbba8daa2a173f6e154588b30042d0a9f23 Mon Sep 17 00:00:00 2001 From: mashehu Date: Tue, 20 Feb 2024 08:56:29 +0100 Subject: [PATCH 2/3] add code review suggestions --- nf_core/components/update.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/nf_core/components/update.py b/nf_core/components/update.py index 7972fe80f7..f6765bed69 100644 --- a/nf_core/components/update.py +++ b/nf_core/components/update.py @@ -3,6 +3,7 @@ import shutil import tempfile from pathlib import Path +from typing import List import questionary @@ -737,7 +738,7 @@ def move_files_from_tmp_dir(self, component: str, install_folder: str, repo_path new_version (str): The version of the module/subworkflow that was installed. """ temp_component_dir = Path(install_folder, component) - files = [] + files: List[Path] = [] for file_path in Path(temp_component_dir).rglob("*"): if file_path.is_file(): files.append(file_path) @@ -746,13 +747,11 @@ def move_files_from_tmp_dir(self, component: str, install_folder: str, repo_path if pipeline_path.exists(): pipeline_files = [f.name for f in pipeline_path.iterdir() if f.is_file()] # check if any *.config file exists in the pipeline - if any([str(f).endswith(".config") for f in pipeline_files]): - # move the *.config file to the temporary directory - config_files = [f for f in files if str(f).endswith(".config")] - for config_file in config_files: - log.debug(f"Moving '{component}/{config_file}' to updated component") - shutil.move(Path(pipeline_path, config_file), Path(temp_component_dir, config_file)) - files.append(config_file) + config_files = [f for f in pipeline_files if str(f).endswith(".config")] + for config_file in config_files: + log.debug(f"Moving '{component}/{config_file}' to updated component") + shutil.move(Path(pipeline_path, config_file), Path(temp_component_dir, config_file)) + files.append(Path(config_file)) else: log.debug(f"Creating new {self.component_type[:-1]} '{component}' in '{self.component_type}/{repo_path}'") @@ -769,7 +768,6 @@ def move_files_from_tmp_dir(self, component: str, install_folder: str, repo_path dest = Path(pipeline_path, file) dest.parent.mkdir(parents=True, exist_ok=True) shutil.move(path, dest) - log.debug(f"{os.listdir(pipeline_path)}") log.info(f"Updating '{repo_path}/{component}'") log.debug(f"Updating {self.component_type[:-1]} '{component}' to {new_version} from {repo_path}") From 89a31548888cd844392afe578484c585440e3fb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BAlia=20Mir=20Pedrol?= Date: Tue, 20 Feb 2024 10:25:11 +0000 Subject: [PATCH 3/3] add full path of nextflow.config to update files --- nf_core/components/update.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/nf_core/components/update.py b/nf_core/components/update.py index f6765bed69..a54c47232e 100644 --- a/nf_core/components/update.py +++ b/nf_core/components/update.py @@ -3,7 +3,6 @@ import shutil import tempfile from pathlib import Path -from typing import List import questionary @@ -738,10 +737,7 @@ def move_files_from_tmp_dir(self, component: str, install_folder: str, repo_path new_version (str): The version of the module/subworkflow that was installed. """ temp_component_dir = Path(install_folder, component) - files: List[Path] = [] - for file_path in Path(temp_component_dir).rglob("*"): - if file_path.is_file(): - files.append(file_path) + files = [file_path for file_path in temp_component_dir.rglob("*") if file_path.is_file()] pipeline_path = Path(self.dir, self.component_type, repo_path, component) if pipeline_path.exists(): @@ -750,8 +746,8 @@ def move_files_from_tmp_dir(self, component: str, install_folder: str, repo_path config_files = [f for f in pipeline_files if str(f).endswith(".config")] for config_file in config_files: log.debug(f"Moving '{component}/{config_file}' to updated component") - shutil.move(Path(pipeline_path, config_file), Path(temp_component_dir, config_file)) - files.append(Path(config_file)) + shutil.move(pipeline_path / config_file, temp_component_dir / config_file) + files.append(temp_component_dir / config_file) else: log.debug(f"Creating new {self.component_type[:-1]} '{component}' in '{self.component_type}/{repo_path}'")