-
Notifications
You must be signed in to change notification settings - Fork 201
/
Copy path__main__.py
2203 lines (2008 loc) · 62.9 KB
/
__main__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python
"""nf-core: Helper tools for use with nf-core Nextflow pipelines."""
import logging
import os
import subprocess
import sys
from pathlib import Path
import rich
import rich.console
import rich.logging
import rich.traceback
import rich_click as click
from trogon import tui
from nf_core import __version__
from nf_core.download import DownloadError
from nf_core.modules.modules_repo import NF_CORE_MODULES_REMOTE
from nf_core.params_file import ParamsFileBuilder
from nf_core.utils import check_if_outdated, rich_force_colors, setup_nfcore_dir
# Set up logging as the root logger
# Submodules should all traverse back to this
log = logging.getLogger()
# Set up .nfcore directory for storing files between sessions
setup_nfcore_dir()
# Set up nicer formatting of click cli help messages
click.rich_click.MAX_WIDTH = 100
click.rich_click.USE_RICH_MARKUP = True
click.rich_click.COMMAND_GROUPS = {
"nf-core": [
{
"name": "Commands for users",
"commands": [
"list",
"launch",
"log",
"create-params-file",
"download",
"licences",
"tui",
],
},
{
"name": "Commands for developers",
"commands": [
"create",
"lint",
"modules",
"subworkflows",
"schema",
"create-logo",
"bump-version",
"sync",
],
},
],
"nf-core modules": [
{
"name": "For pipelines",
"commands": ["list", "info", "install", "update", "remove", "patch"],
},
{
"name": "Developing new modules",
"commands": ["create", "lint", "bump-versions", "test"],
},
],
"nf-core subworkflows": [
{
"name": "For pipelines",
"commands": ["info", "install", "list", "remove", "update"],
},
{
"name": "Developing new subworkflows",
"commands": ["create", "test", "lint"],
},
],
}
click.rich_click.OPTION_GROUPS = {
"nf-core modules list local": [{"options": ["--dir", "--json", "--help"]}],
}
# Set up rich stderr console
stderr = rich.console.Console(stderr=True, force_terminal=rich_force_colors())
stdout = rich.console.Console(force_terminal=rich_force_colors())
# Set up the rich traceback
rich.traceback.install(console=stderr, width=200, word_wrap=True, extra_lines=1)
# Define exceptions for which no traceback should be printed,
# because they are actually preliminary, but intended program terminations.
# (Custom exceptions are cleaner than `sys.exit(1)`, which we used before)
def selective_traceback_hook(exctype, value, traceback):
if exctype in {DownloadError}: # extend set as needed
log.error(value)
else:
# print the colored traceback for all other exceptions with rich as usual
stderr.print(rich.traceback.Traceback.from_exception(exctype, value, traceback))
sys.excepthook = selective_traceback_hook
# Define callback function to normalize the case of click arguments,
# which is used to make the module/subworkflow names, provided by the
# user on the cli, case insensitive.
def normalize_case(ctx, param, component_name):
if component_name is not None:
return component_name.casefold()
def run_nf_core():
# print nf-core header if environment variable is not set
if os.environ.get("_NF_CORE_COMPLETE") is None:
# Print nf-core header
stderr.print(f"\n[green]{' ' * 42},--.[grey39]/[green],-.", highlight=False)
stderr.print(
"[blue] ___ __ __ __ ___ [green]/,-._.--~\\",
highlight=False,
)
stderr.print(
r"[blue] |\ | |__ __ / ` / \ |__) |__ [yellow] } {",
highlight=False,
)
stderr.print(
r"[blue] | \| | \__, \__/ | \ |___ [green]\`-._,-`-,",
highlight=False,
)
stderr.print(
"[green] `._,._,'\n",
highlight=False,
)
stderr.print(
f"[grey39] nf-core/tools version {__version__} - [link=https://nf-co.re]https://nf-co.re[/]",
highlight=False,
)
try:
is_outdated, _, remote_vers = check_if_outdated()
if is_outdated:
stderr.print(
f"[bold bright_yellow] There is a new version of nf-core/tools available! ({remote_vers})",
highlight=False,
)
except Exception as e:
log.debug(f"Could not check latest version: {e}")
stderr.print("\n")
# Launch the click cli
nf_core_cli(auto_envvar_prefix="NFCORE")
@tui()
@click.group(context_settings=dict(help_option_names=["-h", "--help"]))
@click.version_option(__version__)
@click.option(
"-v",
"--verbose",
is_flag=True,
default=False,
help="Print verbose output to the console.",
)
@click.option("--hide-progress", is_flag=True, default=False, help="Don't show progress bars.")
@click.option("-l", "--log-file", help="Save a verbose log to a file.", metavar="<filename>")
@click.pass_context
def nf_core_cli(ctx, verbose, hide_progress, log_file):
"""
nf-core/tools provides a set of helper tools for use with nf-core Nextflow pipelines.
It is designed for both end-users running pipelines and also developers creating new pipelines.
"""
# Set the base logger to output DEBUG
log.setLevel(logging.DEBUG)
# Set up logs to the console
log.addHandler(
rich.logging.RichHandler(
level=logging.DEBUG if verbose else logging.INFO,
console=rich.console.Console(stderr=True, force_terminal=rich_force_colors()),
show_time=False,
show_path=verbose, # True if verbose, false otherwise
markup=True,
)
)
# don't show rich debug logging in verbose mode
rich_logger = logging.getLogger("rich")
rich_logger.setLevel(logging.INFO)
# Set up logs to a file if we asked for one
if log_file:
log_fh = logging.FileHandler(log_file, encoding="utf-8")
log_fh.setLevel(logging.DEBUG)
log_fh.setFormatter(logging.Formatter("[%(asctime)s] %(name)-20s [%(levelname)-7s] %(message)s"))
log.addHandler(log_fh)
ctx.obj = {
"verbose": verbose,
"hide_progress": hide_progress or verbose, # Always hide progress bar with verbose logging
}
# nf-core list
@nf_core_cli.command("list")
@click.argument("keywords", required=False, nargs=-1, metavar="<filter keywords>")
@click.option(
"-s",
"--sort",
type=click.Choice(["release", "pulled", "name", "stars"]),
default="release",
help="How to sort listed pipelines",
)
@click.option("--json", is_flag=True, default=False, help="Print full output as JSON")
@click.option("--show-archived", is_flag=True, default=False, help="Print archived workflows")
def list_pipelines(keywords, sort, json, show_archived):
"""
List available nf-core pipelines with local info.
Checks the web for a list of nf-core pipelines with their latest releases.
Shows which nf-core pipelines you have pulled locally and whether they are up to date.
"""
from nf_core.list import list_workflows
stdout.print(list_workflows(keywords, sort, json, show_archived))
# nf-core launch
@nf_core_cli.command()
@click.argument("pipeline", required=False, metavar="<pipeline name>")
@click.option("-r", "--revision", help="Release/branch/SHA of the project to run (if remote)")
@click.option("-i", "--id", help="ID for web-gui launch parameter set")
@click.option(
"-c",
"--command-only",
is_flag=True,
default=False,
help="Create Nextflow command with params (no params file)",
)
@click.option(
"-o",
"--params-out",
type=click.Path(),
default=os.path.join(os.getcwd(), "nf-params.json"),
help="Path to save run parameters file",
)
@click.option(
"-p",
"--params-in",
type=click.Path(exists=True),
help="Set of input run params to use from a previous run",
)
@click.option(
"-a",
"--save-all",
is_flag=True,
default=False,
help="Save all parameters, even if unchanged from default",
)
@click.option(
"-x",
"--show-hidden",
is_flag=True,
default=False,
help="Show hidden params which don't normally need changing",
)
@click.option(
"-u",
"--url",
type=str,
default="https://nf-co.re/launch",
help="Customise the builder URL (for development work)",
)
def launch(
pipeline,
id,
revision,
command_only,
params_in,
params_out,
save_all,
show_hidden,
url,
):
"""
Launch a pipeline using a web GUI or command line prompts.
Uses the pipeline schema file to collect inputs for all available pipeline
parameters. Parameter names, descriptions and help text are shown.
The pipeline schema is used to validate all inputs as they are entered.
When finished, saves a file with the selected parameters which can be
passed to Nextflow using the -params-file option.
Run using a remote pipeline name (such as GitHub `user/repo` or a URL),
a local pipeline directory or an ID from the nf-core web launch tool.
"""
from nf_core.launch import Launch
launcher = Launch(
pipeline,
revision,
command_only,
params_in,
params_out,
save_all,
show_hidden,
url,
id,
)
if not launcher.launch_pipeline():
sys.exit(1)
# nf-core log
@nf_core_cli.command("log")
@click.argument("filenames", required=False, nargs=-1, metavar="<filenames>")
def view_logs(filenames):
"""
Render .nextflow.log files nicely.
Uses [link=https://github.com/textualize/toolong/]Toolong[/] with the included nf-core extension.
Shows files globbed with `.nextflow.log*` by default, or supplied filenames.
"""
filenames = list(filenames)
if len(filenames) == 0:
p = Path(".")
p.glob(".nextflow.log*")
filenames = [str(f) for f in p.glob(".nextflow.log*")]
if len(filenames) == 0:
log.error("No .nextflow.log files found.")
sys.exit(1)
filenames.sort()
log.info(f"Launching log viewer for: [green]{", ".join(filenames)}")
log.info(
"This uses the [link=https://github.com/textualize/toolong/]Toolong[/] log viewer - you can view any file with it using the `[magenta]tl[/]` command!"
)
subprocess.run(["tl", *filenames])
# nf-core create-params-file
@nf_core_cli.command()
@click.argument("pipeline", required=False, metavar="<pipeline name>")
@click.option("-r", "--revision", help="Release/branch/SHA of the pipeline (if remote)")
@click.option(
"-o",
"--output",
type=str,
default="nf-params.yml",
metavar="<filename>",
help="Output filename. Defaults to `nf-params.yml`.",
)
@click.option("-f", "--force", is_flag=True, default=False, help="Overwrite existing files")
@click.option(
"-x",
"--show-hidden",
is_flag=True,
default=False,
help="Show hidden params which don't normally need changing",
)
def create_params_file(pipeline, revision, output, force, show_hidden):
"""
Build a parameter file for a pipeline.
Uses the pipeline schema file to generate a YAML parameters file.
Parameters are set to the pipeline defaults and descriptions are shown in comments.
After the output file is generated, it can then be edited as needed before
passing to nextflow using the `-params-file` option.
Run using a remote pipeline name (such as GitHub `user/repo` or a URL),
a local pipeline directory.
"""
builder = ParamsFileBuilder(pipeline, revision)
if not builder.write_params_file(output, show_hidden=show_hidden, force=force):
sys.exit(1)
# nf-core download
@nf_core_cli.command()
@click.argument("pipeline", required=False, metavar="<pipeline name>")
@click.option(
"-r",
"--revision",
multiple=True,
help="Pipeline release to download. Multiple invocations are possible, e.g. `-r 1.1 -r 1.2`",
)
@click.option("-o", "--outdir", type=str, help="Output directory")
@click.option(
"-x",
"--compress",
type=click.Choice(["tar.gz", "tar.bz2", "zip", "none"]),
help="Archive compression type",
)
@click.option("-f", "--force", is_flag=True, default=False, help="Overwrite existing files")
# TODO: Remove this in a future release. Deprecated in March 2024.
@click.option(
"--tower",
is_flag=True,
default=False,
hidden=True,
help="Download for Seqera Platform. DEPRECATED: Please use --platform instead.",
)
@click.option(
"-t",
"--platform",
is_flag=True,
default=False,
help="Download for Seqera Platform (formerly Nextflow Tower)",
)
@click.option(
"-d",
"--download-configuration",
is_flag=True,
default=False,
help="Include configuration profiles in download. Not available with `--platform`",
)
# -c changed to -s for consistency with other --container arguments, where it is always the first letter of the last word.
# Also -c might be used instead of -d for config in a later release, but reusing params for different options in two subsequent releases might be too error-prone.
@click.option(
"-s",
"--container-system",
type=click.Choice(["none", "singularity"]),
help="Download container images of required software.",
)
@click.option(
"-l",
"--container-library",
multiple=True,
help="Container registry/library or mirror to pull images from.",
)
@click.option(
"-u",
"--container-cache-utilisation",
type=click.Choice(["amend", "copy", "remote"]),
help="Utilise a `singularity.cacheDir` in the download process, if applicable.",
)
@click.option(
"-i",
"--container-cache-index",
type=str,
help="List of images already available in a remote `singularity.cacheDir`.",
)
@click.option(
"-p",
"--parallel-downloads",
type=int,
default=4,
help="Number of parallel image downloads",
)
def download(
pipeline,
revision,
outdir,
compress,
force,
tower,
platform,
download_configuration,
container_system,
container_library,
container_cache_utilisation,
container_cache_index,
parallel_downloads,
):
"""
Download a pipeline, nf-core/configs and pipeline singularity images.
Collects all files in a single archive and configures the downloaded
workflow to use relative paths to the configs and singularity images.
"""
from nf_core.download import DownloadWorkflow
dl = DownloadWorkflow(
pipeline,
revision,
outdir,
compress,
force,
tower or platform, # True if either specified
download_configuration,
container_system,
container_library,
container_cache_utilisation,
container_cache_index,
parallel_downloads,
)
dl.download_workflow()
# nf-core licences
@nf_core_cli.command()
@click.argument("pipeline", required=True, metavar="<pipeline name>")
@click.option("--json", is_flag=True, default=False, help="Print output in JSON")
def licences(pipeline, json):
"""
List software licences for a given workflow (DSL1 only).
Checks the pipeline environment.yml file which lists all conda software packages, which is not available for DSL2 workflows. Therefore, this command only supports DSL1 workflows (for now).
Each of these is queried against the anaconda.org API to find the licence.
Package name, version and licence is printed to the command line.
"""
from nf_core.licences import WorkflowLicences
lic = WorkflowLicences(pipeline)
lic.as_json = json
try:
stdout.print(lic.run_licences())
except LookupError as e:
log.error(e)
sys.exit(1)
# nf-core create
@nf_core_cli.command()
@click.option(
"-n",
"--name",
type=str,
help="The name of your new pipeline",
)
@click.option("-d", "--description", type=str, help="A short description of your pipeline")
@click.option("-a", "--author", type=str, help="Name of the main author(s)")
@click.option("--version", type=str, default="1.0dev", help="The initial version number to use")
@click.option(
"-f",
"--force",
is_flag=True,
default=False,
help="Overwrite output directory if it already exists",
)
@click.option("-o", "--outdir", help="Output directory for new pipeline (default: pipeline name)")
@click.option("-t", "--template-yaml", help="Pass a YAML file to customize the template")
@click.option("--plain", is_flag=True, help="Use the standard nf-core template")
def create(name, description, author, version, force, outdir, template_yaml, plain):
"""
Create a new pipeline using the nf-core template.
Uses the nf-core template to make a skeleton Nextflow pipeline with all required
files, boilerplate code and best-practices.
"""
from nf_core.create import PipelineCreate
try:
create_obj = PipelineCreate(
name,
description,
author,
version=version,
force=force,
outdir=outdir,
template_yaml_path=template_yaml,
plain=plain,
)
create_obj.init_pipeline()
except UserWarning as e:
log.error(e)
sys.exit(1)
# nf-core lint
@nf_core_cli.command()
@click.option(
"-d",
"--dir",
type=click.Path(exists=True),
default=".",
help=r"Pipeline directory [dim]\[default: current working directory][/]",
)
@click.option(
"--release",
is_flag=True,
default=os.path.basename(os.path.dirname(os.environ.get("GITHUB_REF", "").strip(" '\""))) == "master"
and os.environ.get("GITHUB_REPOSITORY", "").startswith("nf-core/")
and not os.environ.get("GITHUB_REPOSITORY", "") == "nf-core/tools",
help="Execute additional checks for release-ready workflows.",
)
@click.option(
"-f",
"--fix",
type=str,
metavar="<test>",
multiple=True,
help="Attempt to automatically fix specified lint test",
)
@click.option(
"-k",
"--key",
type=str,
metavar="<test>",
multiple=True,
help="Run only these lint tests",
)
@click.option("-p", "--show-passed", is_flag=True, help="Show passing tests on the command line")
@click.option("-i", "--fail-ignored", is_flag=True, help="Convert ignored tests to failures")
@click.option("-w", "--fail-warned", is_flag=True, help="Convert warn tests to failures")
@click.option(
"--markdown",
type=str,
metavar="<filename>",
help="File to write linting results to (Markdown)",
)
@click.option(
"--json",
type=str,
metavar="<filename>",
help="File to write linting results to (JSON)",
)
@click.option(
"--sort-by",
type=click.Choice(["module", "test"]),
default="test",
help="Sort lint output by module or test name.",
show_default=True,
)
@click.pass_context
def lint(
ctx,
dir,
release,
fix,
key,
show_passed,
fail_ignored,
fail_warned,
markdown,
json,
sort_by,
):
"""
Check pipeline code against nf-core guidelines.
Runs a large number of automated tests to ensure that the supplied pipeline
meets the nf-core guidelines. Documentation of all lint tests can be found
on the nf-core website: [link=https://nf-co.re/tools/docs/]https://nf-co.re/tools/docs/[/]
You can ignore tests using a file called [blue].nf-core.yml[/] [i](if you have a good reason!)[/].
See the documentation for details.
"""
from nf_core.lint import run_linting
from nf_core.utils import is_pipeline_directory
# Check if pipeline directory is a pipeline
try:
is_pipeline_directory(dir)
except UserWarning as e:
log.error(e)
sys.exit(1)
# Run the lint tests!
try:
lint_obj, module_lint_obj, subworkflow_lint_obj = run_linting(
dir,
release,
fix,
key,
show_passed,
fail_ignored,
fail_warned,
sort_by,
markdown,
json,
ctx.obj["hide_progress"],
)
swf_failed = 0
if subworkflow_lint_obj is not None:
swf_failed = len(subworkflow_lint_obj.failed)
if len(lint_obj.failed) + len(module_lint_obj.failed) + swf_failed > 0:
sys.exit(1)
except AssertionError as e:
log.critical(e)
sys.exit(1)
except UserWarning as e:
log.error(e)
sys.exit(1)
# nf-core modules subcommands
@nf_core_cli.group()
@click.option(
"-g",
"--git-remote",
type=str,
default=NF_CORE_MODULES_REMOTE,
help="Remote git repo to fetch files from",
)
@click.option(
"-b",
"--branch",
type=str,
default=None,
help="Branch of git repository hosting modules.",
)
@click.option(
"-N",
"--no-pull",
is_flag=True,
default=False,
help="Do not pull in latest changes to local clone of modules repository.",
)
@click.pass_context
def modules(ctx, git_remote, branch, no_pull):
"""
Commands to manage Nextflow DSL2 modules (tool wrappers).
"""
# ensure that ctx.obj exists and is a dict (in case `cli()` is called
# by means other than the `if` block below)
ctx.ensure_object(dict)
# Place the arguments in a context object
ctx.obj["modules_repo_url"] = git_remote
ctx.obj["modules_repo_branch"] = branch
ctx.obj["modules_repo_no_pull"] = no_pull
# nf-core subworkflows click command
@nf_core_cli.group()
@click.option(
"-g",
"--git-remote",
type=str,
default=NF_CORE_MODULES_REMOTE,
help="Remote git repo to fetch files from",
)
@click.option(
"-b",
"--branch",
type=str,
default=None,
help="Branch of git repository hosting modules.",
)
@click.option(
"-N",
"--no-pull",
is_flag=True,
default=False,
help="Do not pull in latest changes to local clone of modules repository.",
)
@click.pass_context
def subworkflows(ctx, git_remote, branch, no_pull):
"""
Commands to manage Nextflow DSL2 subworkflows (tool wrappers).
"""
# ensure that ctx.obj exists and is a dict (in case `cli()` is called
# by means other than the `if` block below)
ctx.ensure_object(dict)
# Place the arguments in a context object
ctx.obj["modules_repo_url"] = git_remote
ctx.obj["modules_repo_branch"] = branch
ctx.obj["modules_repo_no_pull"] = no_pull
# nf-core modules list subcommands
@modules.group("list")
@click.pass_context
def modules_list(ctx):
"""
List modules in a local pipeline or remote repository.
"""
pass
# nf-core modules list remote
@modules_list.command("remote")
@click.pass_context
@click.argument("keywords", required=False, nargs=-1, metavar="<filter keywords>")
@click.option("-j", "--json", is_flag=True, help="Print as JSON to stdout")
def modules_list_remote(ctx, keywords, json):
"""
List modules in a remote GitHub repo [dim i](e.g [link=https://github.com/nf-core/modules]nf-core/modules[/])[/].
"""
from nf_core.modules import ModuleList
try:
module_list = ModuleList(
None,
True,
ctx.obj["modules_repo_url"],
ctx.obj["modules_repo_branch"],
ctx.obj["modules_repo_no_pull"],
)
stdout.print(module_list.list_components(keywords, json))
except (UserWarning, LookupError) as e:
log.critical(e)
sys.exit(1)
# nf-core modules list local
@modules_list.command("local")
@click.pass_context
@click.argument("keywords", required=False, nargs=-1, metavar="<filter keywords>")
@click.option("-j", "--json", is_flag=True, help="Print as JSON to stdout")
@click.option(
"-d",
"--dir",
type=click.Path(exists=True),
default=".",
help=r"Pipeline directory. [dim]\[default: Current working directory][/]",
)
def modules_list_local(ctx, keywords, json, dir): # pylint: disable=redefined-builtin
"""
List modules installed locally in a pipeline
"""
from nf_core.modules import ModuleList
try:
module_list = ModuleList(
dir,
False,
ctx.obj["modules_repo_url"],
ctx.obj["modules_repo_branch"],
ctx.obj["modules_repo_no_pull"],
)
stdout.print(module_list.list_components(keywords, json))
except (UserWarning, LookupError) as e:
log.error(e)
sys.exit(1)
# nf-core modules install
@modules.command("install")
@click.pass_context
@click.argument("tool", type=str, callback=normalize_case, required=False, metavar="<tool> or <tool/subtool>")
@click.option(
"-d",
"--dir",
type=click.Path(exists=True),
default=".",
help=r"Pipeline directory. [dim]\[default: current working directory][/]",
)
@click.option(
"-p",
"--prompt",
is_flag=True,
default=False,
help="Prompt for the version of the module",
)
@click.option(
"-f",
"--force",
is_flag=True,
default=False,
help="Force reinstallation of module if it already exists",
)
@click.option("-s", "--sha", type=str, metavar="<commit sha>", help="Install module at commit SHA")
def modules_install(ctx, tool, dir, prompt, force, sha):
"""
Install DSL2 modules within a pipeline.
Fetches and installs module files from a remote repo e.g. nf-core/modules.
"""
from nf_core.modules import ModuleInstall
try:
module_install = ModuleInstall(
dir,
force,
prompt,
sha,
ctx.obj["modules_repo_url"],
ctx.obj["modules_repo_branch"],
ctx.obj["modules_repo_no_pull"],
)
exit_status = module_install.install(tool)
if not exit_status:
sys.exit(1)
except (UserWarning, LookupError) as e:
log.error(e)
sys.exit(1)
# nf-core modules update
@modules.command("update")
@click.pass_context
@click.argument("tool", type=str, callback=normalize_case, required=False, metavar="<tool> or <tool/subtool>")
@click.option(
"-d",
"--dir",
"directory",
type=click.Path(exists=True),
default=".",
help=r"Pipeline directory. [dim]\[default: current working directory][/]",
)
@click.option("-f", "--force", is_flag=True, default=False, help="Force update of module")
@click.option(
"-p",
"--prompt",
is_flag=True,
default=False,
help="Prompt for the version of the module",
)
@click.option("-s", "--sha", type=str, metavar="<commit sha>", help="Install module at commit SHA")
@click.option(
"-a",
"--all",
"install_all",
is_flag=True,
default=False,
help="Update all modules installed in pipeline",
)
@click.option(
"-x/-y",
"--preview/--no-preview",
is_flag=True,
default=None,
help="Preview / no preview of changes before applying",
)
@click.option(
"-D",
"--save-diff",
type=str,
metavar="<filename>",
default=None,
help="Save diffs to a file instead of updating in place",
)
@click.option(
"-u",
"--update-deps",
is_flag=True,
default=False,
help="Automatically update all linked modules and subworkflows without asking for confirmation",
)
def modules_update(
ctx,
tool,
directory,
force,
prompt,
sha,
install_all,
preview,
save_diff,
update_deps,
):
"""
Update DSL2 modules within a pipeline.
Fetches and updates module files from a remote repo e.g. nf-core/modules.
"""
from nf_core.modules import ModuleUpdate
try:
module_install = ModuleUpdate(
directory,
force,
prompt,
sha,
install_all,
preview,
save_diff,
update_deps,
ctx.obj["modules_repo_url"],
ctx.obj["modules_repo_branch"],
ctx.obj["modules_repo_no_pull"],
)
exit_status = module_install.update(tool)
if not exit_status and install_all:
sys.exit(1)
except (UserWarning, LookupError) as e:
log.error(e)
sys.exit(1)
# nf-core modules patch
@modules.command()
@click.pass_context
@click.argument("tool", type=str, callback=normalize_case, required=False, metavar="<tool> or <tool/subtool>")
@click.option(
"-d",
"--dir",
type=click.Path(exists=True),
default=".",
help=r"Pipeline directory. [dim]\[default: current working directory][/]",
)
@click.option("-r", "--remove", is_flag=True, default=False)
def patch(ctx, tool, dir, remove):
"""
Create a patch file for minor changes in a module
Checks if a module has been modified locally and creates a patch file
describing how the module has changed from the remote version
"""
from nf_core.modules import ModulePatch
try:
module_patch = ModulePatch(
dir,
ctx.obj["modules_repo_url"],
ctx.obj["modules_repo_branch"],
ctx.obj["modules_repo_no_pull"],
)
if remove:
module_patch.remove(tool)
else:
module_patch.patch(tool)
except (UserWarning, LookupError) as e: