Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modules: fix bump-versions: only append module name if it is a dir and contains main.nf #3384

Merged
merged 3 commits into from
Jan 7, 2025
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
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
13 changes: 7 additions & 6 deletions nf_core/modules/modules_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
20 changes: 20 additions & 0 deletions tests/modules/test_modules_utils.py
Original file line number Diff line number Diff line change
@@ -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
Loading