Skip to content

Commit

Permalink
Merge pull request #2767 from mashehu/nf-test-profiles
Browse files Browse the repository at this point in the history
Modules: Add `--profile` parameter to nf-test command
  • Loading branch information
mashehu committed Feb 19, 2024
2 parents 83fa6ba + f4a4c2f commit 706de8f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,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

Expand Down
18 changes: 16 additions & 2 deletions nf_core/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1134,7 +1134,13 @@ 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=click.Choice(["docker", "singularity", "conda"]),
default=None,
help="Run tests with a specific profile",
)
def test_module(ctx, tool, dir, no_prompts, update, once, profile):
"""
Run nf-test for a module.
Expand All @@ -1153,6 +1159,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:
Expand Down Expand Up @@ -1398,7 +1405,13 @@ 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=click.Choice(["none", "singularity"]),
default=None,
help="Run tests with a specific profile",
)
def test_subworkflow(ctx, subworkflow, dir, no_prompts, update, once, profile):
"""
Run nf-test for a subworkflow.
Expand All @@ -1417,6 +1430,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:
Expand Down
13 changes: 10 additions & 3 deletions nf_core/components/components_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------
Expand All @@ -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
Expand All @@ -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"""
Expand Down Expand Up @@ -129,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(
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -232,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")
Expand Down

0 comments on commit 706de8f

Please sign in to comment.