From 3501683d2fce573b53a090a3b5daad43984cf935 Mon Sep 17 00:00:00 2001 From: mirpedrol Date: Sun, 27 Nov 2022 16:07:46 +0100 Subject: [PATCH 1/4] keep track of already removed components --- nf_core/components/remove.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/nf_core/components/remove.py b/nf_core/components/remove.py index 6fe59b6984..cf4a767f98 100644 --- a/nf_core/components/remove.py +++ b/nf_core/components/remove.py @@ -19,7 +19,7 @@ class ComponentRemove(ComponentCommand): def __init__(self, component_type, pipeline_dir, remote_url=None, branch=None, no_pull=False): super().__init__(component_type, pipeline_dir, remote_url, branch, no_pull) - def remove(self, component, removed_by=None, force=False): + def remove(self, component, removed_by=None, all_removed=None, force=False): """ Remove an already installed module/subworkflow This command only works for modules/subworkflows that are installed from 'nf-core/modules' @@ -51,6 +51,9 @@ def remove(self, component, removed_by=None, force=False): style=nf_core.utils.nfcore_question_style, ).unsafe_ask() + if all_removed is None: + all_removed = [] + # Get the module/subworkflow directory component_dir = Path(self.dir, self.component_type, repo_path, component) @@ -85,7 +88,7 @@ def remove(self, component, removed_by=None, force=False): include_stmts = self.check_if_in_include_stmts(str(removed_component_dir)) if include_stmts: # print the include statements - log.warn( + log.warning( f"The {self.component_type[:-1]} '{component}' is still included in the following workflow file{nf_core.utils.plural_s(include_stmts)}:" ) console = Console() @@ -120,14 +123,16 @@ def remove(self, component, removed_by=None, force=False): if not ComponentInstall(self.dir, self.component_type, force=True).install( component, silent=True ): - log.warn( + log.warning( f"Could not install the {self.component_type[:-1]} '{component}', please install it manually with 'nf-core {component_type} install {component}'." ) + all_removed.append(component) return removed # Remove the component files of all entries removed from modules.json removed = ( True if self.clear_component_dir(component, Path(self.dir, removed_component_dir)) or removed else False ) + all_removed.append(component) if removed: if self.component_type == "subworkflows": @@ -136,10 +141,12 @@ def remove(self, component, removed_by=None, force=False): self.component_type, component, self.modules_repo.remote_url, repo_path, {} ) for component_name, component_type in dependent_components.items(): - original_component_tyoe = self.component_type + if component_name in all_removed: + continue + original_component_type = self.component_type self.component_type = component_type - dependency_removed = self.remove(component_name, removed_by=removed_by) - self.component_type = original_component_tyoe + dependency_removed = self.remove(component_name, removed_by=removed_by, all_removed=all_removed) + self.component_type = original_component_type # remember removed dependencies if dependency_removed: removed_components.append(component_name.replace("/", "_")) From 5d37c8b628ef14a4f3372380e920bfb7eebc10db Mon Sep 17 00:00:00 2001 From: mashehu Date: Mon, 28 Nov 2022 11:59:26 +0100 Subject: [PATCH 2/4] remove duplicated log messages when removing a dependent file --- nf_core/components/remove.py | 4 ++-- nf_core/modules/modules_json.py | 9 --------- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/nf_core/components/remove.py b/nf_core/components/remove.py index cf4a767f98..46f9b4f2ad 100644 --- a/nf_core/components/remove.py +++ b/nf_core/components/remove.py @@ -161,9 +161,9 @@ def remove(self, component, removed_by=None, all_removed=None, force=False): ][component]["installed_by"] if installed_by == self.component_type: log.error( - f"Did not remove '{component}', because it was also manually installed. Only updated 'installed_by' in modules.json." + 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)}.""" + 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/modules_json.py b/nf_core/modules/modules_json.py index bad80631d3..3d80e60734 100644 --- a/nf_core/modules/modules_json.py +++ b/nf_core/modules/modules_json.py @@ -696,15 +696,6 @@ def remove_entry(self, component_type, name, repo_url, install_dir, removed_by=N # write the updated modules.json file self.dump() return True - # write the updated modules.json file - if removed_by == component_type: - log.info( - f"""Updated the 'installed_by' list for '{name}', but it is still installed, because it is required by {", ".join(f"'{d}'" for d in repo_entry[component_type][install_dir][name]['installed_by'])}.""" - ) - else: - log.info( - f"Removed {removed_by} from the 'installed_by' list of {name}, but it was also installed by other modules/subworkflows." - ) self.dump() return False else: From e0e4cf2f948e0d9f34692285ba67bcb8ea7fdc09 Mon Sep 17 00:00:00 2001 From: mirpedrol Date: Mon, 28 Nov 2022 12:55:39 +0100 Subject: [PATCH 3/4] change all_removed by removed_components and add docstring --- nf_core/components/remove.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/nf_core/components/remove.py b/nf_core/components/remove.py index 46f9b4f2ad..ac8cbaa6f9 100644 --- a/nf_core/components/remove.py +++ b/nf_core/components/remove.py @@ -19,13 +19,16 @@ class ComponentRemove(ComponentCommand): def __init__(self, component_type, pipeline_dir, remote_url=None, branch=None, no_pull=False): super().__init__(component_type, pipeline_dir, remote_url, branch, no_pull) - def remove(self, component, removed_by=None, all_removed=None, force=False): + def remove(self, component, removed_by=None, removed_components=None, force=False): """ Remove an already installed module/subworkflow This command only works for modules/subworkflows that are installed from 'nf-core/modules' Args: component (str): Name of the component to remove + removed_by (str): Name of the component that is removing the current component + (a subworkflow name if the component is a dependency or "modules" or "subworkflows" if it is not a dependency) + removed_components (list[str]): list of components that have been removed during a recursive remove of subworkflows force (bool): Force removal of component, even if there is still an include statement in a workflow file Returns: @@ -51,8 +54,8 @@ def remove(self, component, removed_by=None, all_removed=None, force=False): style=nf_core.utils.nfcore_question_style, ).unsafe_ask() - if all_removed is None: - all_removed = [] + if removed_components is None: + removed_components = [] # Get the module/subworkflow directory component_dir = Path(self.dir, self.component_type, repo_path, component) @@ -126,13 +129,13 @@ def remove(self, component, removed_by=None, all_removed=None, force=False): log.warning( f"Could not install the {self.component_type[:-1]} '{component}', please install it manually with 'nf-core {component_type} install {component}'." ) - all_removed.append(component) + removed_components.append(component) return removed # Remove the component files of all entries removed from modules.json removed = ( True if self.clear_component_dir(component, Path(self.dir, removed_component_dir)) or removed else False ) - all_removed.append(component) + removed_components.append(component) if removed: if self.component_type == "subworkflows": @@ -141,11 +144,13 @@ def remove(self, component, removed_by=None, all_removed=None, force=False): self.component_type, component, self.modules_repo.remote_url, repo_path, {} ) for component_name, component_type in dependent_components.items(): - if component_name in all_removed: + if component_name in removed_components: continue original_component_type = self.component_type self.component_type = component_type - dependency_removed = self.remove(component_name, removed_by=removed_by, all_removed=all_removed) + dependency_removed = self.remove( + component_name, removed_by=removed_by, removed_components=all_removed + ) self.component_type = original_component_type # remember removed dependencies if dependency_removed: From 58b33e88a4fc34a5ba04f570a1e6e515d2ff4b01 Mon Sep 17 00:00:00 2001 From: mirpedrol Date: Mon, 28 Nov 2022 13:17:50 +0100 Subject: [PATCH 4/4] change a name that i forgot --- nf_core/components/remove.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nf_core/components/remove.py b/nf_core/components/remove.py index ac8cbaa6f9..0916d56e85 100644 --- a/nf_core/components/remove.py +++ b/nf_core/components/remove.py @@ -149,7 +149,7 @@ def remove(self, component, removed_by=None, removed_components=None, force=Fals original_component_type = self.component_type self.component_type = component_type dependency_removed = self.remove( - component_name, removed_by=removed_by, removed_components=all_removed + component_name, removed_by=removed_by, removed_components=removed_components ) self.component_type = original_component_type # remember removed dependencies