Skip to content

Commit 3b2aaa9

Browse files
pmorisadamrtalbotewelsawgymer
committed
Make cli-provided module/subworkflow names case insensitive
Uses a click callback function to normalize the name of a module/subworkflow that is provided by the user on the CLI, so that names written in uppercase still resolve to the expected lowercase name. In case no argument is provided, the callback function simply returns None, and thus the current behaviour of a user being asked to select a component via an interactive prompt is maintained. The .casefold() method is used in favour of .lower() for slightly more robust case normalization. See: https://stackoverflow.com/questions/45745661/lower-vs-casefold-in-string-matching-and-converting-to-lowercase The callback is applied to all occurrences of "tool/module/subworkflow" arguments, except those in the the "create" functions, because these already contain an internal check that prompts to user to adhere to the lowercase naming convention. Updates to CHANGELOG.md. Co-authored-by: Adam Talbot <adam.talbot@seqera.io> Co-authored-by: Phil Ewels <phil.ewels@seqera.io> Co-authored-by: Arthur Gymer <24782660+awgymer@users.noreply.github.com>
1 parent 70def9a commit 3b2aaa9

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
- Fix issue with config resolution that was causing nested configs to behave unexpectedly ([#2862](https://github.com/nf-core/tools/pull/2862))
4242
- Fix schema docs console output truncating ([#2880](https://github.com/nf-core/tools/pull/2880))
4343
- fix: ensure path object converted to string before stripping quotes ([#2878](https://github.com/nf-core/tools/pull/2878))
44+
- Make cli-provided module/subworkflow names case insensitive ([#2869](https://github.com/nf-core/tools/pull/2869))
4445

4546
## [v2.13.1 - Tin Puppy Patch](https://github.com/nf-core/tools/releases/tag/2.13) - [2024-02-29]
4647

nf_core/__main__.py

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,14 @@ def selective_traceback_hook(exctype, value, traceback):
103103
sys.excepthook = selective_traceback_hook
104104

105105

106+
# Define callback function to normalize the case of click arguments,
107+
# which is used to make the module/subworkflow names, provided by the
108+
# user on the cli, case insensitive.
109+
def normalize_case(ctx, param, component_name):
110+
if component_name is not None:
111+
return component_name.casefold()
112+
113+
106114
def run_nf_core():
107115
# print nf-core header if environment variable is not set
108116
if os.environ.get("_NF_CORE_COMPLETE") is None:
@@ -786,7 +794,7 @@ def modules_list_local(ctx, keywords, json, dir): # pylint: disable=redefined-b
786794
# nf-core modules install
787795
@modules.command("install")
788796
@click.pass_context
789-
@click.argument("tool", type=str, required=False, metavar="<tool> or <tool/subtool>")
797+
@click.argument("tool", type=str, callback=normalize_case, required=False, metavar="<tool> or <tool/subtool>")
790798
@click.option(
791799
"-d",
792800
"--dir",
@@ -838,7 +846,7 @@ def modules_install(ctx, tool, dir, prompt, force, sha):
838846
# nf-core modules update
839847
@modules.command("update")
840848
@click.pass_context
841-
@click.argument("tool", type=str, required=False, metavar="<tool> or <tool/subtool>")
849+
@click.argument("tool", type=str, callback=normalize_case, required=False, metavar="<tool> or <tool/subtool>")
842850
@click.option(
843851
"-d",
844852
"--dir",
@@ -930,7 +938,7 @@ def modules_update(
930938
# nf-core modules patch
931939
@modules.command()
932940
@click.pass_context
933-
@click.argument("tool", type=str, required=False, metavar="<tool> or <tool/subtool>")
941+
@click.argument("tool", type=str, callback=normalize_case, required=False, metavar="<tool> or <tool/subtool>")
934942
@click.option(
935943
"-d",
936944
"--dir",
@@ -967,7 +975,7 @@ def patch(ctx, tool, dir, remove):
967975
# nf-core modules remove
968976
@modules.command("remove")
969977
@click.pass_context
970-
@click.argument("tool", type=str, required=False, metavar="<tool> or <tool/subtool>")
978+
@click.argument("tool", type=str, callback=normalize_case, required=False, metavar="<tool> or <tool/subtool>")
971979
@click.option(
972980
"-d",
973981
"--dir",
@@ -1121,7 +1129,7 @@ def create_module(
11211129
# nf-core modules test
11221130
@modules.command("test")
11231131
@click.pass_context
1124-
@click.argument("tool", type=str, required=False, metavar="<tool> or <tool/subtool>")
1132+
@click.argument("tool", type=str, callback=normalize_case, required=False, metavar="<tool> or <tool/subtool>")
11251133
@click.option(
11261134
"-d",
11271135
"--dir",
@@ -1180,7 +1188,7 @@ def test_module(ctx, tool, dir, no_prompts, update, once, profile):
11801188
# nf-core modules lint
11811189
@modules.command("lint")
11821190
@click.pass_context
1183-
@click.argument("tool", type=str, required=False, metavar="<tool> or <tool/subtool>")
1191+
@click.argument("tool", type=str, callback=normalize_case, required=False, metavar="<tool> or <tool/subtool>")
11841192
@click.option(
11851193
"-d",
11861194
"--dir",
@@ -1267,7 +1275,7 @@ def modules_lint(ctx, tool, dir, registry, key, all, fail_warned, local, passed,
12671275
# nf-core modules info
12681276
@modules.command("info")
12691277
@click.pass_context
1270-
@click.argument("tool", type=str, required=False, metavar="<tool> or <tool/subtool>")
1278+
@click.argument("tool", type=str, callback=normalize_case, required=False, metavar="<tool> or <tool/subtool>")
12711279
@click.option(
12721280
"-d",
12731281
"--dir",
@@ -1306,7 +1314,7 @@ def modules_info(ctx, tool, dir):
13061314
# nf-core modules bump-versions
13071315
@modules.command()
13081316
@click.pass_context
1309-
@click.argument("tool", type=str, required=False, metavar="<tool> or <tool/subtool>")
1317+
@click.argument("tool", type=str, callback=normalize_case, required=False, metavar="<tool> or <tool/subtool>")
13101318
@click.option(
13111319
"-d",
13121320
"--dir",
@@ -1392,7 +1400,7 @@ def create_subworkflow(ctx, subworkflow, dir, author, force, migrate_pytest):
13921400
# nf-core subworkflows test
13931401
@subworkflows.command("test")
13941402
@click.pass_context
1395-
@click.argument("subworkflow", type=str, required=False, metavar="subworkflow name")
1403+
@click.argument("subworkflow", type=str, callback=normalize_case, required=False, metavar="subworkflow name")
13961404
@click.option(
13971405
"-d",
13981406
"--dir",
@@ -1519,7 +1527,7 @@ def subworkflows_list_local(ctx, keywords, json, dir): # pylint: disable=redefi
15191527
# nf-core subworkflows lint
15201528
@subworkflows.command("lint")
15211529
@click.pass_context
1522-
@click.argument("subworkflow", type=str, required=False, metavar="subworkflow name")
1530+
@click.argument("subworkflow", type=str, callback=normalize_case, required=False, metavar="subworkflow name")
15231531
@click.option(
15241532
"-d",
15251533
"--dir",
@@ -1600,7 +1608,7 @@ def subworkflows_lint(ctx, subworkflow, dir, registry, key, all, fail_warned, lo
16001608
# nf-core subworkflows info
16011609
@subworkflows.command("info")
16021610
@click.pass_context
1603-
@click.argument("tool", type=str, required=False, metavar="subworkflow name")
1611+
@click.argument("tool", type=str, callback=normalize_case, required=False, metavar="subworkflow name")
16041612
@click.option(
16051613
"-d",
16061614
"--dir",
@@ -1639,7 +1647,7 @@ def subworkflows_info(ctx, tool, dir):
16391647
# nf-core subworkflows install
16401648
@subworkflows.command("install")
16411649
@click.pass_context
1642-
@click.argument("subworkflow", type=str, required=False, metavar="subworkflow name")
1650+
@click.argument("subworkflow", type=str, callback=normalize_case, required=False, metavar="subworkflow name")
16431651
@click.option(
16441652
"-d",
16451653
"--dir",
@@ -1697,7 +1705,7 @@ def subworkflows_install(ctx, subworkflow, dir, prompt, force, sha):
16971705
# nf-core subworkflows remove
16981706
@subworkflows.command("remove")
16991707
@click.pass_context
1700-
@click.argument("subworkflow", type=str, required=False, metavar="subworkflow name")
1708+
@click.argument("subworkflow", type=str, callback=normalize_case, required=False, metavar="subworkflow name")
17011709
@click.option(
17021710
"-d",
17031711
"--dir",
@@ -1727,7 +1735,7 @@ def subworkflows_remove(ctx, dir, subworkflow):
17271735
# nf-core subworkflows update
17281736
@subworkflows.command("update")
17291737
@click.pass_context
1730-
@click.argument("subworkflow", type=str, required=False, metavar="subworkflow name")
1738+
@click.argument("subworkflow", type=str, callback=normalize_case, required=False, metavar="subworkflow name")
17311739
@click.option(
17321740
"-d",
17331741
"--dir",

0 commit comments

Comments
 (0)