From a335212e8cd0a65f07b9deed4ea1a31ae3f35648 Mon Sep 17 00:00:00 2001 From: mirpedrol Date: Tue, 7 Jan 2025 15:01:56 +0100 Subject: [PATCH 1/3] only append module name if it is a dir and contains main.nf --- nf_core/modules/modules_utils.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/nf_core/modules/modules_utils.py b/nf_core/modules/modules_utils.py index ecfe5f24ee..0f42d1bcea 100644 --- a/nf_core/modules/modules_utils.py +++ b/nf_core/modules/modules_utils.py @@ -65,19 +65,20 @@ def get_installed_modules(directory: Path, repo_type="modules") -> Tuple[List[st local_modules = sorted([x for x in local_modules if x.endswith(".nf")]) # Get nf-core modules - if os.path.exists(nfcore_modules_dir): - for m in sorted([m for m in os.listdir(nfcore_modules_dir) if not m == "lib"]): - if not os.path.isdir(os.path.join(nfcore_modules_dir, m)): + if nfcore_modules_dir.exists(): + for m in sorted([m for m in nfcore_modules_dir.iterdir() if not m == "lib"]): + if not m.is_dir(): raise ModuleExceptionError( f"File found in '{nfcore_modules_dir}': '{m}'! This directory should only contain module directories." ) - m_content = os.listdir(os.path.join(nfcore_modules_dir, m)) + m_content = [d.name for d in m.iterdir()] # Not a module, but contains sub-modules if "main.nf" not in m_content: for tool in m_content: - nfcore_modules_names.append(os.path.join(m, tool)) + if (m / tool).is_dir() and "main.nf" in [d.name for d in (m / tool).iterdir()]: + nfcore_modules_names.append(str(Path(m.name, tool))) else: - nfcore_modules_names.append(m) + nfcore_modules_names.append(m.name) # Make full (relative) file paths and create NFCoreComponent objects if local_modules_dir: From 983dcedfb1414f135049cb8460e8897fa15800b3 Mon Sep 17 00:00:00 2001 From: mirpedrol Date: Tue, 7 Jan 2025 15:07:17 +0100 Subject: [PATCH 2/3] update changelog --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f2f92f5fe..1b006c98f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,12 +8,12 @@ ### Modules +- Fix bump-versions: only append module name if it is a dir and contains main.nf ([#3384](https://github.com/nf-core/tools/pull/3384)) + ### Subworkflows ### General -- bump to 3.2.0dev ([#3370](https://github.com/nf-core/tools/pull/3370)) - ### Version updates ## [v3.1.1 - Brass Boxfish Patch](https://github.com/nf-core/tools/releases/tag/3.1.1) - [2024-12-20] From 069fce2c0a181c3731d21a8ae48838e248ca2c81 Mon Sep 17 00:00:00 2001 From: mirpedrol Date: Tue, 7 Jan 2025 15:43:06 +0100 Subject: [PATCH 3/3] add tests for get_installed_modules() utils function --- tests/modules/test_modules_utils.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 tests/modules/test_modules_utils.py diff --git a/tests/modules/test_modules_utils.py b/tests/modules/test_modules_utils.py new file mode 100644 index 0000000000..763725337b --- /dev/null +++ b/tests/modules/test_modules_utils.py @@ -0,0 +1,20 @@ +import nf_core.modules.modules_utils + +from ..test_modules import TestModules + + +class TestModulesUtils(TestModules): + def test_get_installed_modules(self): + """Test getting installed modules""" + _, nfcore_modules = nf_core.modules.modules_utils.get_installed_modules(self.nfcore_modules) + assert len(nfcore_modules) == 1 + assert nfcore_modules[0].component_name == "bpipe/test" + + def test_get_installed_modules_with_files(self): + """Test getting installed modules. When a module contains a file in its directory, it shouldn't be picked up as a tool/subtool""" + # Create a file in the module directory + with open(self.nfcore_modules / "modules" / "nf-core" / "bpipe" / "test_file.txt", "w") as fh: + fh.write("test") + + _, nfcore_modules = nf_core.modules.modules_utils.get_installed_modules(self.nfcore_modules) + assert len(nfcore_modules) == 1