Skip to content

Commit 53865cd

Browse files
committed
move fix_module_version to environment.yml file and fix test fixture
1 parent f73c268 commit 53865cd

5 files changed

Lines changed: 24 additions & 24 deletions

File tree

nf_core/modules/lint/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
log = logging.getLogger(__name__)
3030

31-
from .environment_yml import environment_yml
31+
from .environment_yml import lint_environment_yml
3232
from .main_nf import main_nf
3333
from .meta_yml import meta_yml, meta_yml_containers, obtain_inputs, obtain_outputs, obtain_topics, read_meta_yml
3434
from .module_changes import module_changes
@@ -46,7 +46,7 @@ class ModuleLint(ComponentLint):
4646
"""
4747

4848
# Import lint functions
49-
environment_yml = environment_yml
49+
environment_yml = lint_environment_yml
5050
main_nf = main_nf
5151
meta_yml = meta_yml
5252
obtain_inputs = obtain_inputs

nf_core/modules/lint/environment_yml.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,17 @@
1818
yaml.indent(mapping=2, sequence=2, offset=2)
1919

2020

21-
def environment_yml(
21+
def _fix_module_version(self, current_version, latest_version, response):
22+
"""Update the conda package version in environment.yml."""
23+
with open(self.environment_yml) as source:
24+
content = source.read()
25+
new_content = content.replace(f"={current_version}", f"={latest_version}", 1)
26+
with open(self.environment_yml, "w") as source:
27+
source.write(new_content)
28+
return True
29+
30+
31+
def lint_environment_yml(
2232
module_lint_object: ComponentLint,
2333
module: NFCoreComponent,
2434
allow_missing: bool = False,
@@ -340,8 +350,6 @@ def sort_key(x):
340350
package, ver = bp.split("=", 1)
341351
if fix_version:
342352
try:
343-
from nf_core.modules.lint.main_nf import _fix_module_version
344-
345353
fixed = _fix_module_version(module, bioconda_version, last_ver, response)
346354
except FileNotFoundError as e:
347355
fixed = False

nf_core/modules/lint/main_nf.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -780,20 +780,6 @@ def _is_empty(line):
780780
return empty
781781

782782

783-
def _fix_module_version(self, current_version, latest_version, response):
784-
"""Updates the module conda version in environment.yml."""
785-
786-
with open(self.environment_yml) as source:
787-
content = source.read()
788-
789-
new_content = content.replace(f"={current_version}", f"={latest_version}", 1)
790-
791-
with open(self.environment_yml, "w") as source:
792-
source.write(new_content)
793-
794-
return True
795-
796-
797783
def _get_build(response):
798784
"""Get the latest build of the container version"""
799785
build_times = []

tests/modules/lint/test_environment_yml.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import nf_core.modules.lint
88
from nf_core.components.lint import ComponentLint
99
from nf_core.components.nfcore_component import NFCoreComponent
10-
from nf_core.modules.lint.environment_yml import environment_yml
10+
from nf_core.modules.lint.environment_yml import lint_environment_yml as environment_yml
1111

1212
from ...test_modules import TestModules
1313

@@ -25,6 +25,7 @@ class DummyModule(NFCoreComponent):
2525
def __init__(self, path):
2626
self.environment_yml = path
2727
self.component_dir = path.parent
28+
self.base_dir = path.parent
2829
self.component_name = "dummy"
2930
self.passed = []
3031
self.failed = []
@@ -266,7 +267,7 @@ def test_fix_version_fix_fails(tmp_path):
266267

267268
with (
268269
patch("nf_core.utils.anaconda_package", return_value=fake_response),
269-
patch("nf_core.modules.lint.main_nf._fix_module_version", return_value=False),
270+
patch("nf_core.modules.lint.environment_yml._fix_module_version", return_value=False),
270271
):
271272
environment_yml(lint, module, fix_version=True)
272273

tests/test_modules.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,20 @@ def create_modules_repo_dummy(tmp_dir):
7070
name="quay.io/biocontainers/bpipe:0.9.13--hdfd78af_0", build_id="", scan_id=""
7171
)
7272
sing = MetaYmlContainers.SingularityContainer(
73-
name="https://depot.galaxyproject.org/singularity/bpipe:0.9.13--hdfd78af_0",
73+
name="oras://community.wave.seqera.io/library/bpipe:0.9.13--hdfd78af_0",
7474
build_id="",
7575
https="https://depot.galaxyproject.org/singularity/bpipe:0.9.13--hdfd78af_0",
7676
)
77-
conda = MetaYmlContainers.CondaEnvironment(lock_file="")
77+
conda_amd64 = MetaYmlContainers.CondaEnvironment(
78+
lock_file="modules/nf-core/bpipe/test/.conda-lock/linux_amd64-bd-dummy_1.txt"
79+
)
80+
conda_arm64 = MetaYmlContainers.CondaEnvironment(
81+
lock_file="modules/nf-core/bpipe/test/.conda-lock/linux_arm64-bd-dummy_1.txt"
82+
)
7883
containers = MetaYmlContainers(
7984
docker={"linux/amd64": docker, "linux/arm64": docker},
8085
singularity={"linux/amd64": sing, "linux/arm64": sing},
81-
conda={"linux/amd64": conda, "linux/arm64": conda},
86+
conda={"linux/amd64": conda_amd64, "linux/arm64": conda_arm64},
8287
)
8388
meta_yml["containers"] = containers.model_dump()
8489
with open(str(meta_yml_path), "w") as fh:

0 commit comments

Comments
 (0)