diff --git a/nf_core/components/install.py b/nf_core/components/install.py index f7a5fe6680..6385ee4092 100644 --- a/nf_core/components/install.py +++ b/nf_core/components/install.py @@ -127,6 +127,8 @@ def install(self, component, silent=False): self.install_included_components(component_dir) if not silent: + modules_json.load() + modules_json.dump(run_prettier=True) # Print include statement component_name = "_".join(component.upper().split("/")) log.info(f"Use the following statement to include this {self.component_type[:-1]}:") diff --git a/nf_core/components/update.py b/nf_core/components/update.py index 6fc6e03544..077cb2b840 100644 --- a/nf_core/components/update.py +++ b/nf_core/components/update.py @@ -288,20 +288,21 @@ def update(self, component=None, silent=False, updated=None, check_diff_exist=Tr updated.append(component) recursive_update = True modules_to_update, subworkflows_to_update = self.get_components_to_update(component) - if not silent and not self.update_all and len(modules_to_update + subworkflows_to_update) > 0: - log.warning( - f"All modules and subworkflows linked to the updated {self.component_type[:-1]} will be {'asked for update' if self.show_diff else 'automatically updated'}.\n" - "It is advised to keep all your modules and subworkflows up to date.\n" - "It is not guaranteed that a subworkflow will continue working as expected if all modules/subworkflows used in it are not up to date.\n" - ) - if self.update_deps: - recursive_update = True - else: - recursive_update = questionary.confirm( - "Would you like to continue updating all modules and subworkflows?", - default=True, - style=nf_core.utils.nfcore_question_style, - ).unsafe_ask() + if not silent and len(modules_to_update + subworkflows_to_update) > 0: + if not self.update_all: + log.warning( + f"All modules and subworkflows linked to the updated {self.component_type[:-1]} will be {'asked for update' if self.show_diff else 'automatically updated'}.\n" + "It is advised to keep all your modules and subworkflows up to date.\n" + "It is not guaranteed that a subworkflow will continue working as expected if all modules/subworkflows used in it are not up to date.\n" + ) + if self.update_deps: + recursive_update = True + else: + recursive_update = questionary.confirm( + "Would you like to continue updating all modules and subworkflows?", + default=True, + style=nf_core.utils.nfcore_question_style, + ).unsafe_ask() if recursive_update and len(modules_to_update + subworkflows_to_update) > 0: # Update linked components self.update_linked_components(modules_to_update, subworkflows_to_update, updated) @@ -323,8 +324,12 @@ def update(self, component=None, silent=False, updated=None, check_diff_exist=Tr ) elif not all_patches_successful and not silent: log.info(f"Updates complete. Please apply failed patch{plural_es(components_info)} manually.") + self.modules_json.load() + self.modules_json.dump(run_prettier=True) elif not silent: log.info("Updates complete :sparkles:") + self.modules_json.load() + self.modules_json.dump(run_prettier=True) return exit_value diff --git a/nf_core/modules/modules_json.py b/nf_core/modules/modules_json.py index 9c3d1ae9b1..354a61dac9 100644 --- a/nf_core/modules/modules_json.py +++ b/nf_core/modules/modules_json.py @@ -6,6 +6,7 @@ import shutil import tempfile from pathlib import Path +from typing import Union import git import questionary @@ -41,7 +42,7 @@ def __init__(self, pipeline_dir): self.modules_dir = Path(self.dir, "modules") self.subworkflows_dir = Path(self.dir, "subworkflows") self.modules_json_path = Path(self.dir, "modules.json") - self.modules_json = None + self.modules_json: Union(dict, None) = None self.pipeline_modules = None self.pipeline_subworkflows = None self.pipeline_components = None @@ -1035,13 +1036,17 @@ def get_component_branch(self, component_type, component, repo_url, install_dir) ) return branch - def dump(self): + def dump(self, run_prettier: bool = False): """ Sort the modules.json, and write it to file """ # Sort the modules.json self.modules_json["repos"] = nf_core.utils.sort_dictionary(self.modules_json["repos"]) - dump_json_with_prettier(self.modules_json_path, self.modules_json) + if run_prettier: + dump_json_with_prettier(self.modules_json_path, self.modules_json) + else: + with open(self.modules_json_path, "w") as fh: + json.dump(self.modules_json, fh, indent=4) def resolve_missing_installation(self, missing_installation, component_type): missing_but_in_mod_json = [