diff --git a/nf_core/components/components_test.py b/nf_core/components/components_test.py index 6a2cba5001..eadb5ba0cb 100644 --- a/nf_core/components/components_test.py +++ b/nf_core/components/components_test.py @@ -80,10 +80,9 @@ def _check_inputs(self): else: modules_json = ModulesJson(self.dir) modules_json.check_up_to_date() - if self.component_type == "modules": - installed_components = modules_json.get_all_modules().get(self.modules_repo.remote_url) - elif self.component_type == "subworkflows": - modules_json.get_installed_subworkflows().get(self.modules_repo.remote_url) + installed_components = modules_json.get_all_components(self.component_type).get( + self.modules_repo.remote_url + ) # Get the component name if not specified if self.component_name is None: diff --git a/nf_core/modules/lint/__init__.py b/nf_core/modules/lint/__init__.py index e6786a1e7a..fcce0e982f 100644 --- a/nf_core/modules/lint/__init__.py +++ b/nf_core/modules/lint/__init__.py @@ -89,7 +89,7 @@ def __init__( if self.repo_type == "pipeline": modules_json = ModulesJson(self.dir) modules_json.check_up_to_date() - all_pipeline_modules = modules_json.get_all_modules() + all_pipeline_modules = modules_json.get_all_components(self.component_type) if self.modules_repo.remote_url in all_pipeline_modules: module_dir = Path(self.dir, "modules", "nf-core") self.all_remote_modules = [ diff --git a/nf_core/modules/modules_json.py b/nf_core/modules/modules_json.py index 5d4d494d8b..f3fc19225e 100644 --- a/nf_core/modules/modules_json.py +++ b/nf_core/modules/modules_json.py @@ -40,6 +40,14 @@ def __init__(self, pipeline_dir): self.pipeline_subworkflows = None self.pipeline_components = None + def __str__(self): + if self.modules_json is None: + self.load() + return json.dumps(self.modules_json, indent=4) + + def __repr__(self): + return self.__str__() + def create(self): """ Creates the modules.json file from the modules and subworkflows installed in the pipeline directory @@ -885,25 +893,6 @@ def get_subworkflow_version(self, subworkflow_name, repo_url, install_dir): .get("git_sha", None) ) - def get_all_modules(self): - """ - Retrieves all pipeline modules that are reported in the modules.json - - Returns: - (dict[str, [(str, str)]]): Dictionary indexed with the repo urls, with a - list of tuples (module_dir, module) as values - """ - if self.modules_json is None: - self.load() - if self.pipeline_modules is None: - self.pipeline_modules = {} - for repo, repo_entry in self.modules_json.get("repos", {}).items(): - if "modules" in repo_entry: - for dir, modules in repo_entry["modules"].items(): - self.pipeline_modules[repo] = [(dir, m) for m in modules] - - return self.pipeline_modules - def get_all_components(self, component_type): """ Retrieves all pipeline modules/subworkflows that are reported in the modules.json @@ -1004,33 +993,6 @@ def dump(self): json.dump(self.modules_json, fh, indent=4) fh.write("\n") - def __str__(self): - if self.modules_json is None: - self.load() - return json.dumps(self.modules_json, indent=4) - - def __repr__(self): - return self.__str__() - - def get_installed_subworkflows(self): - """ - Retrieves all pipeline subworkflows that are reported in the modules.json - - Returns: - (dict[str, [(str, str)]]): Dictionary indexed with the repo urls, with a - list of tuples (module_dir, subworkflow) as values - """ - if self.modules_json is None: - self.load() - if self.pipeline_subworkflows is None: - self.pipeline_subworkflows = {} - for repo, repo_entry in self.modules_json.get("repos", {}).items(): - if "subworkflows" in repo_entry: - for dir, subworkflow in repo_entry["subworkflows"].items(): - self.pipeline_subworkflows[repo] = [(dir, name) for name in subworkflow] - - return self.pipeline_subworkflows - def resolve_missing_installation(self, missing_installation, component_type): missing_but_in_mod_json = [ f"'{component_type}/{install_dir}/{component}'" diff --git a/nf_core/modules/patch.py b/nf_core/modules/patch.py index db2243dc4f..09e18af1d1 100644 --- a/nf_core/modules/patch.py +++ b/nf_core/modules/patch.py @@ -25,7 +25,7 @@ def param_check(self, module): if not self.has_valid_directory(): raise UserWarning() - modules = self.modules_json.get_all_modules()[self.modules_repo.remote_url] + modules = self.modules_json.get_all_components(self.component_type)[self.modules_repo.remote_url] module_names = [module for _, module in modules] if module is not None and module not in module_names: @@ -38,7 +38,7 @@ def patch(self, module=None): self.modules_json.check_up_to_date() self.param_check(module) - modules = self.modules_json.get_all_modules()[self.modules_repo.remote_url] + modules = self.modules_json.get_all_components(self.component_type)[self.modules_repo.remote_url] if module is None: choices = [module if dir == "nf-core" else f"{dir}/{module}" for dir, module in modules]