From 577ac0032a6f265f2dd67f9b3e0d633c9f6ff5ae Mon Sep 17 00:00:00 2001 From: mashehu Date: Thu, 18 Jan 2024 10:58:40 +0100 Subject: [PATCH 1/5] fix empty json output for modules list local --- nf_core/components/list.py | 1 + 1 file changed, 1 insertion(+) diff --git a/nf_core/components/list.py b/nf_core/components/list.py index 47c0eaad62..7f785b9307 100644 --- a/nf_core/components/list.py +++ b/nf_core/components/list.py @@ -141,6 +141,7 @@ def pattern_msg(keywords: List[str]) -> str: date = "[red]Not Available" message = "[red]Not Available" table.add_row(component, repo_url, version_sha, message, date) + components.append(component) if print_json: return json.dumps(components, sort_keys=True, indent=4) From 15fb9803cf671deddd5465aca63cc67606b9a70e Mon Sep 17 00:00:00 2001 From: nf-core-bot Date: Thu, 18 Jan 2024 10:03:54 +0000 Subject: [PATCH 2/5] [automated] Update CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e98986191..c9447af93c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,8 @@ ### Modules +- Fix empty json output for `nf-core list local` ([#2668](https://github.com/nf-core/tools/pull/2668)) + ### Subworkflows ### General From 4e8a99c04d32cd87f39a8324269515b7da557162 Mon Sep 17 00:00:00 2001 From: mashehu Date: Thu, 18 Jan 2024 11:24:08 +0100 Subject: [PATCH 3/5] add tests for json output --- tests/modules/list.py | 20 ++++++++++++++++++++ tests/test_modules.py | 2 ++ 2 files changed, 22 insertions(+) diff --git a/tests/modules/list.py b/tests/modules/list.py index d92cd58dd5..5a5dd10a1c 100644 --- a/tests/modules/list.py +++ b/tests/modules/list.py @@ -1,3 +1,5 @@ +import json + from rich.console import Console import nf_core.modules @@ -56,3 +58,21 @@ def test_modules_install_gitlab_and_list_pipeline(self): console.print(listed_mods) output = console.export_text() assert "fastqc" in output + + +def test_modules_list_local_json(self): + """Test listing locally installed modules as JSON""" + mods_list = nf_core.modules.ModuleList(self.pipeline_dir, remote=False) + listed_mods = mods_list.list_components(print_json=True) + listed_mods = json.loads(listed_mods) + assert "fastqc" in listed_mods + assert "multiqc" in listed_mods + + +def test_modules_list_remote_json(self): + """Test listing available modules as JSON""" + mods_list = nf_core.modules.ModuleList(None, remote=True) + listed_mods = mods_list.list_components(print_json=True) + listed_mods = json.loads(listed_mods) + assert "fastqc" in listed_mods + assert "multiqc" in listed_mods diff --git a/tests/test_modules.py b/tests/test_modules.py index f7ada2a483..9a91e82d6c 100644 --- a/tests/test_modules.py +++ b/tests/test_modules.py @@ -212,9 +212,11 @@ def test_modulesrepo_class(self): from .modules.list import ( # type: ignore[misc] test_modules_install_and_list_pipeline, test_modules_install_gitlab_and_list_pipeline, + test_modules_list_local_json, test_modules_list_pipeline, test_modules_list_remote, test_modules_list_remote_gitlab, + test_modules_list_remote_json, ) from .modules.modules_json import ( # type: ignore[misc] test_get_modules_json, From a791d45a3ef0fbe665803c9df9ac52fdf3637269 Mon Sep 17 00:00:00 2001 From: mashehu Date: Thu, 18 Jan 2024 11:49:21 +0100 Subject: [PATCH 4/5] add tests for keyword filtering --- tests/modules/list.py | 20 ++++++++++++++++++++ tests/test_modules.py | 2 ++ 2 files changed, 22 insertions(+) diff --git a/tests/modules/list.py b/tests/modules/list.py index 5a5dd10a1c..53b124d169 100644 --- a/tests/modules/list.py +++ b/tests/modules/list.py @@ -76,3 +76,23 @@ def test_modules_list_remote_json(self): listed_mods = json.loads(listed_mods) assert "fastqc" in listed_mods assert "multiqc" in listed_mods + + +def test_modules_list_with_one_keyword(self): + """Test listing available modules with keywords""" + mods_list = nf_core.modules.ModuleList(None, remote=True) + listed_mods = mods_list.list_components(keywords=["qc"]) + console = Console(record=True) + console.print(listed_mods) + output = console.export_text() + assert "multiqc" in output + + +def test_modules_list_with_keywords(self): + """Test listing available modules with keywords""" + mods_list = nf_core.modules.ModuleList(None, remote=True) + listed_mods = mods_list.list_components(keywords=["fastq", "qc"]) + console = Console(record=True) + console.print(listed_mods) + output = console.export_text() + assert "fastqc" in output diff --git a/tests/test_modules.py b/tests/test_modules.py index 9a91e82d6c..8043c5a060 100644 --- a/tests/test_modules.py +++ b/tests/test_modules.py @@ -217,6 +217,8 @@ def test_modulesrepo_class(self): test_modules_list_remote, test_modules_list_remote_gitlab, test_modules_list_remote_json, + test_modules_list_with_keywords, + test_modules_list_with_one_keyword, ) from .modules.modules_json import ( # type: ignore[misc] test_get_modules_json, From 3912bba2f57199ece59fe40f666824dfa0e1cead Mon Sep 17 00:00:00 2001 From: mashehu Date: Thu, 18 Jan 2024 13:42:44 +0100 Subject: [PATCH 5/5] add tests for unknown keywords and wrong repo location --- nf_core/components/list.py | 2 +- tests/modules/list.py | 40 ++++++++++++++++++++++++++++++++++++-- tests/test_modules.py | 2 ++ 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/nf_core/components/list.py b/nf_core/components/list.py index 7f785b9307..b0c5af219f 100644 --- a/nf_core/components/list.py +++ b/nf_core/components/list.py @@ -70,7 +70,7 @@ def pattern_msg(keywords: List[str]) -> str: # We have a pipeline - list what's installed else: # Check that we are in a pipeline directory - + print(f"{self.repo_type=}") try: if self.repo_type != "pipeline": raise UserWarning( diff --git a/tests/modules/list.py b/tests/modules/list.py index 53b124d169..3cb00a84d6 100644 --- a/tests/modules/list.py +++ b/tests/modules/list.py @@ -1,5 +1,7 @@ import json +from pathlib import Path +import yaml from rich.console import Console import nf_core.modules @@ -79,7 +81,7 @@ def test_modules_list_remote_json(self): def test_modules_list_with_one_keyword(self): - """Test listing available modules with keywords""" + """Test listing available modules with one keyword""" mods_list = nf_core.modules.ModuleList(None, remote=True) listed_mods = mods_list.list_components(keywords=["qc"]) console = Console(record=True) @@ -89,10 +91,44 @@ def test_modules_list_with_one_keyword(self): def test_modules_list_with_keywords(self): - """Test listing available modules with keywords""" + """Test listing available modules with multiple keywords""" mods_list = nf_core.modules.ModuleList(None, remote=True) listed_mods = mods_list.list_components(keywords=["fastq", "qc"]) console = Console(record=True) console.print(listed_mods) output = console.export_text() assert "fastqc" in output + + +def test_modules_list_with_unused_keyword(self): + """Test listing available modules with an unused keyword""" + mods_list = nf_core.modules.ModuleList(None, remote=True) + with self.assertLogs(level="INFO") as log: + listed_mods = mods_list.list_components(keywords=["you_will_never_find_me"]) + self.assertIn("No available", log.output[0]) + # expect empty list + assert listed_mods == "" + + +def test_modules_list_in_wrong_repo_fail(self): + """Test listing available modules in a non-pipeline repo""" + # modify repotype in .nf-core.yml + with open(Path(self.pipeline_dir, ".nf-core.yml")) as fh: + nf_core_yml = yaml.safe_load(fh) + nf_core_yml_orig = nf_core_yml.copy() + nf_core_yml["repository_type"] = "modules" + nf_core_yml["org_path"] = "nf-core" + + print(nf_core_yml) + with open(Path(self.pipeline_dir, ".nf-core.yml"), "w") as fh: + yaml.safe_dump(nf_core_yml, fh) + # expect error logged + with self.assertLogs(level="ERROR") as log: + mods_list = nf_core.modules.ModuleList(self.pipeline_dir, remote=False) + listed_mods = mods_list.list_components() + self.assertIn("must be run from a pipeline directory", log.output[0]) + # expect empty list + assert listed_mods == "" + # restore .nf-core.yml + with open(Path(self.pipeline_dir, ".nf-core.yml"), "w") as fh: + yaml.safe_dump(nf_core_yml_orig, fh) diff --git a/tests/test_modules.py b/tests/test_modules.py index 8043c5a060..f9c3b6f2a7 100644 --- a/tests/test_modules.py +++ b/tests/test_modules.py @@ -212,6 +212,7 @@ def test_modulesrepo_class(self): from .modules.list import ( # type: ignore[misc] test_modules_install_and_list_pipeline, test_modules_install_gitlab_and_list_pipeline, + test_modules_list_in_wrong_repo_fail, test_modules_list_local_json, test_modules_list_pipeline, test_modules_list_remote, @@ -219,6 +220,7 @@ def test_modulesrepo_class(self): test_modules_list_remote_json, test_modules_list_with_keywords, test_modules_list_with_one_keyword, + test_modules_list_with_unused_keyword, ) from .modules.modules_json import ( # type: ignore[misc] test_get_modules_json,