Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions nf_core/components/components_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion nf_core/modules/lint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
54 changes: 8 additions & 46 deletions nf_core/modules/modules_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}'"
Expand Down
4 changes: 2 additions & 2 deletions nf_core/modules/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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]
Expand Down