Skip to content

Commit 742897d

Browse files
authored
Merge pull request #3548 from JulianFlesch/feature/test-datasets
Feature/test datasets
2 parents 8bc4305 + 10051de commit 742897d

File tree

5 files changed

+45
-17
lines changed

5 files changed

+45
-17
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
- Changing retrieval of file extension from EDAM ([#3512](https://github.com/nf-core/tools/pull/3512))
6363
- Refactor adding EDAM ontologies and allowing detect more patterns (e.g., versions.yml) ([#3519](https://github.com/nf-core/tools/pull/3519))
6464
- Add offline configs test action ([#3524](https://github.com/nf-core/tools/pull/3524))
65-
- Adds `test-datasets` subcommand for listing/searching files in the nf-core/test-datasets repo from the cli ([#3487](https://github.com/nf-core/tools/issues/3487))
65+
- Adds `test-datasets` subcommand for listing/searching files in the nf-core/test-datasets repo from the cli ([#3487](https://github.com/nf-core/tools/issues/3487), [#3548](https://github.com/nf-core/tools/pull/3548))
6666
- Update pre-commit hook astral-sh/ruff-pre-commit to v0.11.2 ([#3521](https://github.com/nf-core/tools/pull/3521))
6767
- Fix indentation in included_configs API docs ([#3523](https://github.com/nf-core/tools/pull/3523))
6868
- chore(deps): update python:3.12-slim docker digest to a866731 ([#3527](https://github.com/nf-core/tools/pull/3527))

nf_core/__main__.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
"nf-core": [
7878
{
7979
"name": "Commands",
80-
"commands": ["pipelines", "modules", "subworkflows", "interface", "test-datasets"],
80+
"commands": ["pipelines", "modules", "subworkflows", "test-datasets", "interface"],
8181
},
8282
],
8383
"nf-core pipelines": [
@@ -1762,7 +1762,7 @@ def test_datasets(ctx):
17621762

17631763

17641764
# nf-core test-dataset search
1765-
@test_datasets.command("search")
1765+
@test_datasets.command("search", short_help="Search files in the nf-core/test-datasets repository")
17661766
@click.pass_context
17671767
@click.option("-b", "--branch", type=str, help="Branch in the test-datasets repository to reduce search to")
17681768
@click.option(
@@ -1779,11 +1779,13 @@ def test_datasets(ctx):
17791779
default=False,
17801780
help="Auto-generate a github url for downloading the test data file based on the branch and query result",
17811781
)
1782-
def command_test_dataset_search(ctx, branch, generate_nf_path, generate_dl_url):
1782+
@click.argument("query", required=False)
1783+
def command_test_dataset_search(ctx, branch, generate_nf_path, generate_dl_url, query):
17831784
"""
1784-
Interactively search for files on a specified branch in the nf-core/test-datasets repository on github.
1785+
Search files filtered by QUERY on a specified branch in the nf-core/test-datasets repository.
1786+
If no QUERY is given or QUERY is ambiguous, an auto-completion form is shown.
17851787
"""
1786-
test_datasets_search(ctx, branch, generate_nf_path, generate_dl_url)
1788+
test_datasets_search(ctx, branch, generate_nf_path, generate_dl_url, query)
17871789

17881790

17891791
# nf-core test-dataset search
@@ -1806,7 +1808,7 @@ def command_test_dataset_search(ctx, branch, generate_nf_path, generate_dl_url):
18061808
)
18071809
def command_test_dataset_list_remote(ctx, branch, generate_nf_path, generate_dl_url):
18081810
"""
1809-
List all data files for a specified branch in the nf-core/test-datasets repository on github.
1811+
List files on a specified branch in the nf-core/test-datasets repository.
18101812
"""
18111813
test_datasets_list_remote(ctx, branch, generate_nf_path, generate_dl_url)
18121814

@@ -1816,7 +1818,7 @@ def command_test_dataset_list_remote(ctx, branch, generate_nf_path, generate_dl_
18161818
@click.pass_context
18171819
def command_test_datasets_list_branches(ctx):
18181820
"""
1819-
List all remote branches with pipeline or module data in the nf-core/test-dataset repository on github
1821+
List remote branches with test data in the nf-core/test-dataset repository.
18201822
"""
18211823
test_datasets_list_branches(ctx)
18221824

nf_core/commands_test_datasets.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@ def test_datasets_list_remote(ctx: click.Context, branch: str, generate_nf_path:
2828
list_datasets(branch, generate_nf_path, generate_dl_url)
2929

3030

31-
def test_datasets_search(ctx: click.Context, branch: str, generate_nf_path: bool, generate_dl_url: bool) -> None:
31+
def test_datasets_search(
32+
ctx: click.Context, branch: str, generate_nf_path: bool, generate_dl_url: bool, query: str
33+
) -> None:
3234
"""
3335
Search all files on a given branch in the remote nf-core/testdatasets repository on github
3436
with an interactive autocompleting prompt and print the file matching the query.
3537
Specifying a branch is required.
3638
The resulting file can optionally be parsed as a nextflow path or a url for downloading
3739
"""
38-
search_datasets(branch, generate_nf_path, generate_dl_url)
40+
search_datasets(branch, generate_nf_path=generate_nf_path, generate_dl_url=generate_dl_url, query=query)

nf_core/test_datasets/search.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def search_datasets(
2222
generate_dl_url: bool = False,
2323
ignored_file_prefixes: List[str] = IGNORED_FILE_PREFIXES,
2424
plain_text_output: bool = False,
25+
query: str = "",
2526
) -> None:
2627
"""
2728
Search all files on a given branch in the remote nf-core/testdatasets repository on github
@@ -39,11 +40,17 @@ def search_datasets(
3940
files = sum(tree.values(), []) # flat representation of tree
4041

4142
file_selected = False
43+
44+
if query:
45+
# Check if only one file matches the query and directly return it
46+
filtered_files = [f for f in files if query in f]
47+
if len(filtered_files) == 1:
48+
selection = filtered_files[0]
49+
file_selected = True
50+
4251
while not file_selected:
4352
selection = questionary.autocomplete(
44-
"File:",
45-
choices=files,
46-
style=nfcore_question_style,
53+
"File:", choices=files, style=nfcore_question_style, default=query
4754
).unsafe_ask()
4855

4956
file_selected = any([selection == file for file in files])

nf_core/test_datasets/test_datasets_utils.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import json
22
import logging
33
from dataclasses import dataclass
4+
from pathlib import Path
45
from typing import Dict, List, Tuple
56

67
import questionary
78
import requests
89

9-
from nf_core.utils import nfcore_question_style
10+
from nf_core.utils import determine_base_dir, fetch_wf_config, load_tools_config, nfcore_question_style
1011

1112
log = logging.getLogger(__name__)
1213

@@ -176,10 +177,26 @@ def get_or_prompt_branch(maybe_branch: str) -> Tuple[str, List[str]]:
176177
else:
177178
all_branches = get_remote_branch_names()
178179

180+
# Find pipeline / modules root directory
181+
base_dir: Path = determine_base_dir()
182+
183+
# Read .nf-core.yml to identify repository_type
184+
_, tools_config = load_tools_config(base_dir)
185+
186+
branch_prefill = ""
187+
# either modules or a pipeline branch
188+
if tools_config is not None:
189+
repo_type = tools_config.get("repository_type", None)
190+
if repo_type == MODULES_BRANCH_NAME:
191+
branch_prefill = MODULES_BRANCH_NAME
192+
elif repo_type == "pipeline":
193+
wf_config = fetch_wf_config(base_dir)
194+
pipeline_name = wf_config.get("manifest.name", "").split("/")[-1]
195+
if pipeline_name in all_branches:
196+
branch_prefill = pipeline_name
197+
179198
branch = questionary.autocomplete(
180-
"Branch name:",
181-
choices=sorted(all_branches),
182-
style=nfcore_question_style,
199+
"Branch name:", choices=sorted(all_branches), style=nfcore_question_style, default=branch_prefill
183200
).unsafe_ask()
184201

185202
return branch, all_branches

0 commit comments

Comments
 (0)