From d9f8443eac2421042144d3a7d1fe7d953a7cd284 Mon Sep 17 00:00:00 2001 From: mashehu Date: Fri, 16 Feb 2024 13:03:13 +0100 Subject: [PATCH 1/6] add profile parameter to nf-test command fixes #2753 --- nf_core/__main__.py | 20 ++++++++++++++++++-- nf_core/components/components_test.py | 7 ++++++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/nf_core/__main__.py b/nf_core/__main__.py index a39c3cf732..9387236b9a 100644 --- a/nf_core/__main__.py +++ b/nf_core/__main__.py @@ -1134,7 +1134,14 @@ def create_module( default=False, help="Run tests only once. Don't check snapshot stability", ) -def test_module(ctx, tool, dir, no_prompts, update, once): +@click.option( + "--profile", + type=str, + default=None, + help="Run tests with a specific profile", + options=["docker", "singularity", "conda"], +) +def test_module(ctx, tool, dir, no_prompts, update, once, profile): """ Run nf-test for a module. @@ -1153,6 +1160,7 @@ def test_module(ctx, tool, dir, no_prompts, update, once): remote_url=ctx.obj["modules_repo_url"], branch=ctx.obj["modules_repo_branch"], verbose=ctx.obj["verbose"], + profile=profile, ) module_tester.run() except (UserWarning, LookupError) as e: @@ -1398,7 +1406,14 @@ def create_subworkflow(ctx, subworkflow, dir, author, force, migrate_pytest): default=False, help="Run tests only once. Don't check snapshot stability", ) -def test_subworkflow(ctx, subworkflow, dir, no_prompts, update, once): +@click.option( + "--profile", + type=str, + default=None, + help="Run tests with a specific profile", + options=["docker", "singularity", "conda"], +) +def test_subworkflow(ctx, subworkflow, dir, no_prompts, update, once, profile): """ Run nf-test for a subworkflow. @@ -1417,6 +1432,7 @@ def test_subworkflow(ctx, subworkflow, dir, no_prompts, update, once): remote_url=ctx.obj["modules_repo_url"], branch=ctx.obj["modules_repo_branch"], verbose=ctx.obj["verbose"], + profile=profile, ) sw_tester.run() except (UserWarning, LookupError) as e: diff --git a/nf_core/components/components_test.py b/nf_core/components/components_test.py index 3294c2878b..a94441ae8d 100644 --- a/nf_core/components/components_test.py +++ b/nf_core/components/components_test.py @@ -48,6 +48,8 @@ class ComponentsTest(ComponentCommand): # type: ignore[misc] flag indicating if the existing snapshot should be updated once : bool flag indicating if the test should be run only once + profile : str + container software to use (docker, singularity or conda) Methods ------- @@ -72,6 +74,7 @@ def __init__( verbose: bool = False, update: bool = False, once: bool = False, + profile: Optional[str] = None, ): super().__init__(component_type, directory, remote_url, branch, no_prompts=no_prompts) self.component_name = component_name @@ -82,6 +85,7 @@ def __init__( self.obsolete_snapshots: bool = False self.update = update self.once = once + self.profile = profile def run(self) -> None: """Run build steps""" @@ -190,10 +194,11 @@ def generate_snapshot(self) -> bool: update = "--update-snapshot" if self.update else "" self.update = False # reset self.update to False to test if the new snapshot is stable tag = f"subworkflows/{self.component_name}" if self.component_type == "subworkflows" else self.component_name + profile = self.profile if self.profile else os.environ["PROFILE"] result = nf_core.utils.run_cmd( "nf-test", - f"test --tag {tag} --profile {os.environ['PROFILE']} {verbose} {update}", + f"test --tag {tag} --profile {profile} {verbose} {update}", ) if result is not None: nftest_out, nftest_err = result From bb7e6388cea12c4d649b6f4f2c1f142d6038e87f Mon Sep 17 00:00:00 2001 From: nf-core-bot Date: Fri, 16 Feb 2024 16:30:24 +0000 Subject: [PATCH 2/6] [automated] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a37e6e5ff7..ba3f01e79b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ ### Modules - Handle dirty local module repos by force checkout of commits and branches if needed ([#2734](https://github.com/nf-core/tools/pull/2734)) +- Add `--profile` parameter to nf-test command ([#2767](https://github.com/nf-core/tools/pull/2767)) ### General From fba4272e6c2170b0f50180a0314d9995d34589dc Mon Sep 17 00:00:00 2001 From: mashehu Date: Fri, 16 Feb 2024 17:54:31 +0100 Subject: [PATCH 3/6] fix tests --- nf_core/__main__.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/nf_core/__main__.py b/nf_core/__main__.py index 9387236b9a..804f024136 100644 --- a/nf_core/__main__.py +++ b/nf_core/__main__.py @@ -1136,10 +1136,9 @@ def create_module( ) @click.option( "--profile", - type=str, + type=click.Choice(["docker", "singularity", "conda"]), default=None, help="Run tests with a specific profile", - options=["docker", "singularity", "conda"], ) def test_module(ctx, tool, dir, no_prompts, update, once, profile): """ From 6a7980d65537e5d9fde90adb3dc891de2fce2e3f Mon Sep 17 00:00:00 2001 From: mashehu Date: Fri, 16 Feb 2024 17:56:17 +0100 Subject: [PATCH 4/6] fix all occurences --- nf_core/__main__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nf_core/__main__.py b/nf_core/__main__.py index 804f024136..9d7291694a 100644 --- a/nf_core/__main__.py +++ b/nf_core/__main__.py @@ -1407,7 +1407,7 @@ def create_subworkflow(ctx, subworkflow, dir, author, force, migrate_pytest): ) @click.option( "--profile", - type=str, + type=click.Choice(["none", "singularity"]), default=None, help="Run tests with a specific profile", options=["docker", "singularity", "conda"], From 75f6f19cef0fadcd7c23bbcf66692fd52dc04942 Mon Sep 17 00:00:00 2001 From: mashehu Date: Fri, 16 Feb 2024 17:59:31 +0100 Subject: [PATCH 5/6] remove options --- nf_core/__main__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/nf_core/__main__.py b/nf_core/__main__.py index 9d7291694a..7d2d083fa9 100644 --- a/nf_core/__main__.py +++ b/nf_core/__main__.py @@ -1410,7 +1410,6 @@ def create_subworkflow(ctx, subworkflow, dir, author, force, migrate_pytest): type=click.Choice(["none", "singularity"]), default=None, help="Run tests with a specific profile", - options=["docker", "singularity", "conda"], ) def test_subworkflow(ctx, subworkflow, dir, no_prompts, update, once, profile): """ From f4a4c2f2e9df84e85155dbc7ed41a24ccaedb8b4 Mon Sep 17 00:00:00 2001 From: mashehu Date: Mon, 19 Feb 2024 10:03:06 +0100 Subject: [PATCH 6/6] no need for a prompt if it profile is set as a parameter --- nf_core/components/components_test.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/nf_core/components/components_test.py b/nf_core/components/components_test.py index a94441ae8d..f1a9e7c401 100644 --- a/nf_core/components/components_test.py +++ b/nf_core/components/components_test.py @@ -133,7 +133,7 @@ def check_inputs(self) -> None: ) # Check container software to use - if os.environ.get("PROFILE") is None: + if os.environ.get("PROFILE") is None and self.profile is None: os.environ["PROFILE"] = "" if self.no_prompts: log.info( @@ -237,16 +237,18 @@ def check_snapshot_stability(self) -> bool: log.error("nf-test snapshot is not stable") self.errors.append("nf-test snapshot is not stable") return False + else: if self.obsolete_snapshots: # ask if the user wants to remove obsolete snapshots using nf-test --clean-snapshot if self.no_prompts or Confirm.ask( "nf-test found obsolete snapshots. Do you want to remove them?", default=True ): + profile = self.profile if self.profile else os.environ["PROFILE"] log.info("Removing obsolete snapshots") nf_core.utils.run_cmd( "nf-test", - f"test --tag {self.component_name} --profile {os.environ['PROFILE']} --clean-snapshot", + f"test --tag {self.component_name} --profile {profile} --clean-snapshot", ) else: log.debug("Obsolete snapshots not removed")