Skip to content

Commit

Permalink
Merge branch 'dev' into modules-lint-sort
Browse files Browse the repository at this point in the history
  • Loading branch information
awgymer authored Dec 2, 2022
2 parents 79745a7 + ea9dd92 commit e8aa448
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 0 deletions.
10 changes: 10 additions & 0 deletions nf_core/modules/modules_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,16 @@ def check_up_to_date(self):
self.load()
if not self.has_git_url_and_modules():
raise UserWarning
# check that all "installed_by" entries are lists and not strings
# [these strings come from an older dev version, so this check can probably be removed in a future release]
for _, repo_entry in self.modules_json.get("repos", {}).items():
for component_type in ["modules", "subworkflows"]:
if component_type in repo_entry:
for install_dir, install_dir_entry in repo_entry[component_type].items():
for _, component in install_dir_entry.items():
if "installed_by" in component and isinstance(component["installed_by"], str):
log.debug(f"Updating {component} in modules.json")
component["installed_by"] = [component["installed_by"]]
except UserWarning:
log.info("The 'modules.json' file is not up to date. Recreating the 'modules.json' file.")
self.create()
Expand Down
12 changes: 12 additions & 0 deletions tests/modules/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,15 @@ def test_modules_install_different_branch_succeed(self):
modules_json.get_component_branch(self.component_type, "fastp", GITLAB_URL, GITLAB_REPO)
== GITLAB_BRANCH_TEST_BRANCH
)


def test_modules_install_tracking(self):
"""Test installing a module and finding 'modules' in the installed_by section of modules.json"""
self.mods_install.install("trimgalore")

# Verify that the installed_by entry was added correctly
modules_json = ModulesJson(self.pipeline_dir)
mod_json = modules_json.get_modules_json()
assert mod_json["repos"]["https://github.com/nf-core/modules.git"]["modules"]["nf-core"]["trimgalore"][
"installed_by"
] == ["modules"]
64 changes: 64 additions & 0 deletions tests/subworkflows/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,67 @@ def test_subworkflows_install_different_branch_fail(self):
install_obj = SubworkflowInstall(self.pipeline_dir, remote_url=GITLAB_URL, branch=GITLAB_BRANCH_TEST_BRANCH)
# The bam_stats_samtools subworkflow does not exists in the branch-test branch
assert install_obj.install("bam_stats_samtools") is False


def test_subworkflows_install_tracking(self):
"""Test installing a subworkflow and finding the correct entries in installed_by section of modules.json"""
self.subworkflow_install.install("bam_sort_stats_samtools")

# Verify that the installed_by entry was added correctly
modules_json = ModulesJson(self.pipeline_dir)
mod_json = modules_json.get_modules_json()
assert mod_json["repos"]["https://github.com/nf-core/modules.git"]["subworkflows"]["nf-core"][
"bam_sort_stats_samtools"
]["installed_by"] == ["subworkflows"]
assert mod_json["repos"]["https://github.com/nf-core/modules.git"]["subworkflows"]["nf-core"]["bam_stats_samtools"][
"installed_by"
] == ["bam_sort_stats_samtools"]
assert mod_json["repos"]["https://github.com/nf-core/modules.git"]["modules"]["nf-core"]["samtools/stats"][
"installed_by"
] == ["bam_stats_samtools"]
assert mod_json["repos"]["https://github.com/nf-core/modules.git"]["modules"]["nf-core"]["samtools/sort"][
"installed_by"
] == ["bam_sort_stats_samtools"]

# Clean directory
self.subworkflow_remove.remove("bam_sort_stats_samtools")


def test_subworkflows_install_tracking_added_already_installed(self):
"""Test installing a subworkflow and finding the correct entries in installed_by section of modules.json"""
self.subworkflow_install.install("bam_sort_stats_samtools")
self.subworkflow_install.install("bam_stats_samtools")

# Verify that the installed_by entry was added correctly
modules_json = ModulesJson(self.pipeline_dir)
mod_json = modules_json.get_modules_json()
assert mod_json["repos"]["https://github.com/nf-core/modules.git"]["subworkflows"]["nf-core"][
"bam_sort_stats_samtools"
]["installed_by"] == ["subworkflows"]
assert sorted(
mod_json["repos"]["https://github.com/nf-core/modules.git"]["subworkflows"]["nf-core"]["bam_stats_samtools"][
"installed_by"
]
) == sorted(["bam_sort_stats_samtools", "subworkflows"])

# Clean directory
self.subworkflow_remove.remove("bam_sort_stats_samtools")
self.subworkflow_remove.remove("bam_stats_samtools")


def test_subworkflows_install_tracking_added_super_subworkflow(self):
"""Test installing a subworkflow and finding the correct entries in installed_by section of modules.json"""
self.subworkflow_install.install("bam_stats_samtools")
self.subworkflow_install.install("bam_sort_stats_samtools")

# Verify that the installed_by entry was added correctly
modules_json = ModulesJson(self.pipeline_dir)
mod_json = modules_json.get_modules_json()
assert mod_json["repos"]["https://github.com/nf-core/modules.git"]["subworkflows"]["nf-core"][
"bam_sort_stats_samtools"
]["installed_by"] == ["subworkflows"]
assert sorted(
mod_json["repos"]["https://github.com/nf-core/modules.git"]["subworkflows"]["nf-core"]["bam_stats_samtools"][
"installed_by"
]
) == sorted(["subworkflows", "bam_sort_stats_samtools"])
1 change: 1 addition & 0 deletions tests/test_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ def test_modulesrepo_class(self):
test_modules_install_from_gitlab,
test_modules_install_nomodule,
test_modules_install_nopipeline,
test_modules_install_tracking,
test_modules_install_trimgalore,
test_modules_install_trimgalore_twice,
)
Expand Down
3 changes: 3 additions & 0 deletions tests/test_subworkflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ def tearDown(self):
test_subworkflows_install_emptypipeline,
test_subworkflows_install_from_gitlab,
test_subworkflows_install_nosubworkflow,
test_subworkflows_install_tracking,
test_subworkflows_install_tracking_added_already_installed,
test_subworkflows_install_tracking_added_super_subworkflow,
)
from .subworkflows.list import (
test_subworkflows_install_and_list_subworkflows,
Expand Down

0 comments on commit e8aa448

Please sign in to comment.