-
-
Notifications
You must be signed in to change notification settings - Fork 606
/
global_options.py
969 lines (913 loc) · 38.7 KB
/
global_options.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
# Copyright 2014 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).
import multiprocessing
import os
import sys
import tempfile
from dataclasses import dataclass
from enum import Enum
from typing import Any
from pants.base.build_environment import (
get_buildroot,
get_default_pants_config_file,
get_pants_cachedir,
get_pants_configdir,
pants_version,
)
from pants.option.custom_types import dir_option
from pants.option.errors import OptionsError
from pants.option.scope import GLOBAL_SCOPE
from pants.subsystem.subsystem import Subsystem
from pants.util.logging import LogLevel
class GlobMatchErrorBehavior(Enum):
"""Describe the action to perform when matching globs in BUILD files to source files.
NB: this object is interpreted from within Snapshot::lift_path_globs() -- that method will need to
be aware of any changes to this object's definition.
"""
ignore = "ignore"
warn = "warn"
error = "error"
class FileNotFoundBehavior(Enum):
"""What to do when globs do not match in BUILD files."""
warn = "warn"
error = "error"
def to_glob_match_error_behavior(self) -> GlobMatchErrorBehavior:
return GlobMatchErrorBehavior(self.value)
class OwnersNotFoundBehavior(Enum):
"""What to do when a file argument cannot be mapped to an owning target."""
ignore = "ignore"
warn = "warn"
error = "error"
def to_glob_match_error_behavior(self) -> GlobMatchErrorBehavior:
return GlobMatchErrorBehavior(self.value)
@dataclass(frozen=True)
class ExecutionOptions:
"""A collection of all options related to (remote) execution of processes.
TODO: These options should move to a Subsystem once we add support for "bootstrap" Subsystems (ie,
allowing Subsystems to be consumed before the Scheduler has been created).
"""
remote_execution: Any
remote_store_server: Any
remote_store_thread_count: Any
remote_execution_server: Any
remote_store_chunk_bytes: Any
remote_store_chunk_upload_timeout_seconds: Any
remote_store_rpc_retries: Any
remote_store_connection_limit: Any
process_execution_local_parallelism: Any
process_execution_remote_parallelism: Any
process_execution_cleanup_local_dirs: Any
process_execution_speculation_delay: Any
process_execution_speculation_strategy: Any
process_execution_use_local_cache: Any
remote_execution_process_cache_namespace: Any
remote_instance_name: Any
remote_ca_certs_path: Any
remote_oauth_bearer_token_path: Any
remote_execution_extra_platform_properties: Any
remote_execution_headers: Any
remote_execution_overall_deadline_secs: int
process_execution_local_enable_nailgun: bool
@classmethod
def from_bootstrap_options(cls, bootstrap_options):
return cls(
remote_execution=bootstrap_options.remote_execution,
remote_store_server=bootstrap_options.remote_store_server,
remote_execution_server=bootstrap_options.remote_execution_server,
remote_store_thread_count=bootstrap_options.remote_store_thread_count,
remote_store_chunk_bytes=bootstrap_options.remote_store_chunk_bytes,
remote_store_chunk_upload_timeout_seconds=bootstrap_options.remote_store_chunk_upload_timeout_seconds,
remote_store_rpc_retries=bootstrap_options.remote_store_rpc_retries,
remote_store_connection_limit=bootstrap_options.remote_store_connection_limit,
process_execution_local_parallelism=bootstrap_options.process_execution_local_parallelism,
process_execution_remote_parallelism=bootstrap_options.process_execution_remote_parallelism,
process_execution_cleanup_local_dirs=bootstrap_options.process_execution_cleanup_local_dirs,
process_execution_speculation_delay=bootstrap_options.process_execution_speculation_delay,
process_execution_speculation_strategy=bootstrap_options.process_execution_speculation_strategy,
process_execution_use_local_cache=bootstrap_options.process_execution_use_local_cache,
remote_execution_process_cache_namespace=bootstrap_options.remote_execution_process_cache_namespace,
remote_instance_name=bootstrap_options.remote_instance_name,
remote_ca_certs_path=bootstrap_options.remote_ca_certs_path,
remote_oauth_bearer_token_path=bootstrap_options.remote_oauth_bearer_token_path,
remote_execution_extra_platform_properties=bootstrap_options.remote_execution_extra_platform_properties,
remote_execution_headers=bootstrap_options.remote_execution_headers,
remote_execution_overall_deadline_secs=bootstrap_options.remote_execution_overall_deadline_secs,
process_execution_local_enable_nailgun=bootstrap_options.process_execution_local_enable_nailgun,
)
DEFAULT_EXECUTION_OPTIONS = ExecutionOptions(
remote_execution=False,
remote_store_server=[],
remote_store_thread_count=1,
remote_execution_server=None,
remote_store_chunk_bytes=1024 * 1024,
remote_store_chunk_upload_timeout_seconds=60,
remote_store_rpc_retries=2,
remote_store_connection_limit=5,
process_execution_local_parallelism=multiprocessing.cpu_count() * 2,
process_execution_remote_parallelism=128,
process_execution_cleanup_local_dirs=True,
process_execution_speculation_delay=1,
process_execution_speculation_strategy="local_first",
process_execution_use_local_cache=True,
remote_execution_process_cache_namespace=None,
remote_instance_name=None,
remote_ca_certs_path=None,
remote_oauth_bearer_token_path=None,
remote_execution_extra_platform_properties=[],
remote_execution_headers={},
remote_execution_overall_deadline_secs=60 * 60, # one hour
process_execution_local_enable_nailgun=False,
)
class GlobalOptions(Subsystem):
"""Global options."""
options_scope = GLOBAL_SCOPE
@classmethod
def register_bootstrap_options(cls, register):
"""Register bootstrap options.
"Bootstrap options" are the set of options necessary to create a Scheduler. If an option is
not consumed during creation of a Scheduler, it should be in `register_options` instead.
Bootstrap option values can be interpolated into the config file, and can be referenced
programmatically in registration code, e.g., as register.bootstrap.pants_workdir.
Note that regular code can also access these options as normal global-scope options. Their
status as "bootstrap options" is only pertinent during option registration.
"""
buildroot = get_buildroot()
default_distdir_name = "dist"
default_rel_distdir = f"/{default_distdir_name}/"
register(
"-l",
"--level",
type=LogLevel,
default=LogLevel.INFO,
recursive=True,
help="Set the logging level.",
)
register(
"--log-show-rust-3rdparty",
type=bool,
default=False,
advanced=True,
help="Whether to show/hide logging done by 3rdparty Rust crates used by the Pants "
"engine.",
)
register(
"--colors",
type=bool,
default=sys.stdout.isatty(),
help=(
"Whether Pants should use colors in output or not. This may also impact whether "
"some tools Pants run use color."
),
)
register(
"--v1",
advanced=True,
type=bool,
default=False,
help="Enables execution of v1 Tasks.",
removal_version="2.1.0.dev0",
removal_hint="The v1 engine no longer exists. This option does nothing.",
)
register(
"--v2",
advanced=True,
type=bool,
default=True,
help="Enables execution of v2 @goal_rules.",
removal_version="2.1.0.dev0",
removal_hint="The v2 engine is the only one available. This option does nothing.",
)
# TODO(#7203): make a regexp option type!
register(
"--ignore-pants-warnings",
type=list,
member_type=str,
default=[],
advanced=True,
help="Regexps matching warning strings to ignore, e.g. "
'["DEPRECATED: scope some_scope will be removed"]. The regexps will be matched '
"from the start of the warning string, and will always be case-insensitive. "
"See the `warnings` module documentation for more background on these are used.",
)
register(
"--option-name-check-distance",
advanced=True,
type=int,
default=2,
help="The maximum Levenshtein distance to use when offering suggestions for invalid "
"option names.",
)
register(
"--pants-version",
advanced=True,
default=pants_version(),
daemon=True,
help="Use this pants version. Note Pants code only uses this to verify that you are "
"using the requested version, as Pants cannot dynamically change the version it "
"is using once the program is already running. This option is useful to set in "
"your pants.toml, however, and then you can grep the value to select which "
"version to use for setup scripts (e.g. `./pants`), runner scripts, IDE plugins, "
"etc. For example, the setup script we distribute at "
"https://www.pantsbuild.org/docs/installation uses this value to determine which Python"
"version to run with. You may find the version of the Pants instance you are running "
"by using -v, -V, or --version.",
)
register(
"--pants-bin-name",
advanced=True,
default="./pants",
help="The name of the script or binary used to invoke Pants. "
"Useful when printing help messages.",
)
register(
"--plugins",
advanced=True,
type=list,
help="Allow backends to be loaded from these plugins. The default backends for "
"each plugin will be loaded automatically. Other backends in a plugin can be "
"loaded by listing them in --backend-packages.",
)
register(
"--plugins2",
advanced=True,
type=list,
removal_version="2.1.0.dev0",
removal_hint="Use --plugins instead.",
help="Allow backends to be loaded from these plugins. The default backends for "
"each plugin will be loaded automatically. Other backends in a plugin can be "
"loaded by listing them in --backend-packages.",
)
register(
"--plugins-force-resolve",
advanced=True,
type=bool,
default=False,
help="Re-resolve plugins even if previously resolved.",
)
register(
"--plugin-cache-dir",
advanced=True,
default=os.path.join(get_pants_cachedir(), "plugins"),
help="Cache resolved plugin requirements here.",
)
register(
"--backend-packages",
advanced=True,
type=list,
default=[],
help=(
"Register rules from these backends. The backend packages must be present on "
"the PYTHONPATH, typically because they are in the Pants core dist, in a "
"plugin dist, or available as sources in the repo."
),
)
register(
"--backend-packages2",
advanced=True,
type=list,
default=[],
removal_version="2.1.0.dev0",
removal_hint="Use --backend-packages instead.",
help=(
"Register rules from these backends. The backend packages must be present on "
"the PYTHONPATH, typically because they are in the Pants core dist, in a "
"plugin dist, or available as sources in the repo."
),
)
register(
"--pants-bootstrapdir",
advanced=True,
metavar="<dir>",
default=get_pants_cachedir(),
help="Use this dir for global cache.",
)
register(
"--pants-configdir",
advanced=True,
metavar="<dir>",
default=get_pants_configdir(),
help="Use this dir for global config files.",
)
register(
"--pants-workdir",
advanced=True,
metavar="<dir>",
default=os.path.join(buildroot, ".pants.d"),
daemon=True,
help="Write intermediate output files to this dir.",
)
register(
"--pants-physical-workdir-base",
advanced=True,
metavar="<dir>",
default=None,
daemon=True,
help="When set, a base directory in which to store `--pants-workdir` contents. "
"If this option is a set, the workdir will be created as symlink into a "
"per-workspace subdirectory.",
)
register(
"--pants-supportdir",
advanced=True,
metavar="<dir>",
default=os.path.join(buildroot, "build-support"),
help="Use support files from this dir.",
)
register(
"--pants-distdir",
advanced=True,
metavar="<dir>",
default=os.path.join(buildroot, "dist"),
help="Write end-product artifacts to this dir.",
)
register(
"--pants-subprocessdir",
advanced=True,
default=os.path.join(buildroot, ".pids"),
daemon=True,
help="The directory to use for tracking subprocess metadata, if any. This should "
"live outside of the dir used by `--pants-workdir` to allow for tracking "
"subprocesses that outlive the workdir data.",
)
register(
"--pants-config-files",
advanced=True,
type=list,
# NB: We don't fingerprint the list of config files, because the content of the config
# files independently affects fingerprints.
fingerprint=False,
default=[get_default_pants_config_file()],
help="Paths to Pants config files.",
)
# TODO: Deprecate the --pantsrc/--pantsrc-files options? This would require being able
# to set extra config file locations in an initial bootstrap config file.
register(
"--pantsrc",
advanced=True,
type=bool,
default=True,
# NB: See `--pants-config-files`.
fingerprint=False,
help="Use pantsrc files.",
)
register(
"--pantsrc-files",
advanced=True,
type=list,
metavar="<path>",
# NB: See `--pants-config-files`.
fingerprint=False,
default=["/etc/pantsrc", "~/.pants.rc"],
help=(
"Override config with values from these files, using syntax matching that of "
"`--pants-config-files`."
),
)
register(
"--pythonpath",
advanced=True,
type=list,
help="Add these directories to PYTHONPATH to search for plugins.",
)
register(
"--spec-file",
type=list,
dest="spec_files",
# NB: See `--pants-config-files`.
fingerprint=False,
help="Read additional specs from this file (e.g. target addresses or file names). "
"Each spec should be one per line.",
)
register(
"--verify-config",
type=bool,
default=True,
advanced=True,
help="Verify that all config file values correspond to known options.",
)
register(
"--build-ignore",
advanced=True,
type=list,
default=[".*/", "bower_components/", "node_modules/", "*.egg-info/"],
help="Paths to ignore when identifying BUILD files. "
"This does not affect any other filesystem operations. "
"Patterns use the gitignore pattern syntax (https://git-scm.com/docs/gitignore).",
)
register(
"--pants-ignore",
advanced=True,
type=list,
member_type=str,
default=[".*/", default_rel_distdir],
help="Paths to ignore for all filesystem operations performed by pants "
"(e.g. BUILD file scanning, glob matching, etc). "
"Patterns use the gitignore syntax (https://git-scm.com/docs/gitignore). "
"The `--pants-distdir` and `--pants-workdir` locations are inherently ignored. "
"--pants-ignore can be used in tandem with --pants-ignore-use-gitignore, and any rules "
"specified here apply after rules specified in a .gitignore file.",
)
register(
"--pants-ignore-use-gitignore",
advanced=True,
type=bool,
default=True,
help="Make use of a root .gitignore file when determining whether to ignore filesystem "
"operations performed by Pants. If used together with `--pants-ignore`, any exclude/include "
"patterns specified there apply after .gitignore rules.",
)
register(
"--owners-not-found-behavior",
advanced=True,
type=OwnersNotFoundBehavior,
default=OwnersNotFoundBehavior.error,
help="What to do when file arguments do not have any owning target. This happens when there "
"are no targets whose `sources` fields include the file argument.",
)
register(
"--files-not-found-behavior",
advanced=True,
type=FileNotFoundBehavior,
default=FileNotFoundBehavior.warn,
help="What to do when files and globs specified in BUILD files, such as in the "
"`sources` field, cannot be found. This happens when the files do not exist on "
"your machine or when they are ignored by the `--pants-ignore` option.",
)
# TODO(#7203): make a regexp option type!
register(
"--exclude-target-regexp",
advanced=True,
type=list,
default=[],
metavar="<regexp>",
help="Exclude target roots that match these regexes.",
)
register(
"--subproject-roots",
type=list,
advanced=True,
default=[],
help="Paths that correspond with build roots for any subproject that this "
"project depends on.",
)
# These logging options are registered in the bootstrap phase so that plugins can log during
# registration and not so that their values can be interpolated in configs.
register(
"-d",
"--logdir",
advanced=True,
metavar="<dir>",
daemon=True,
help="Write logs to files under this directory.",
)
register(
"--pantsd",
advanced=True,
type=bool,
default=True,
daemon=True,
help=(
"Enables use of the Pants daemon (pantsd). pantsd can significantly improve "
"runtime performance by lowering per-run startup cost, and by caching filesystem "
"operations and rule execution."
),
)
# Whether or not to make necessary arrangements to have concurrent runs in pants.
# In practice, this means that if this is set, a run will not even try to use pantsd.
# NB: Eventually, we would like to deprecate this flag in favor of making pantsd runs parallelizable.
register(
"--concurrent",
advanced=True,
type=bool,
default=False,
help="Enable concurrent runs of Pants. Without this enabled, Pants will "
"start up all concurrent invocations (e.g. in other terminals) without pantsd. "
"Enabling this option requires parallel Pants invocations to block on the first",
)
# Calling pants command (inner run) from other pants command is unusual behaviour,
# and most users should never set this flag.
# It is automatically set by pants when an inner run is detected.
# Currently, pants commands with this option set don't use pantsd,
# but this effect should not be relied upon.
# This option allows us to know who was the parent of pants inner runs for informational purposes.
register(
"--parent-build-id",
advanced=True,
default=None,
help="The build ID of the other Pants run which spawned this one, if any.",
)
# NB: We really don't want this option to invalidate the daemon, because different clients might have
# different needs. For instance, an IDE might have a very long timeout because it only wants to refresh
# a project in the background, while a user might want a shorter timeout for interactivity.
register(
"--pantsd-timeout-when-multiple-invocations",
advanced=True,
type=float,
default=60.0,
help="The maximum amount of time to wait for the invocation to start until "
"raising a timeout exception. "
"Because pantsd currently does not support parallel runs, "
"any prior running Pants command must be finished for the current one to start. "
"To never timeout, use the value -1.",
)
register(
"--pantsd-max-memory-usage",
advanced=True,
type=int,
default=2 ** 30,
help=(
"The maximum memory usage of a pantsd process (in bytes). There is at most one "
"pantsd process per workspace."
),
)
# These facilitate configuring the native engine.
register(
"--native-engine-visualize-to",
advanced=True,
default=None,
type=dir_option,
help="A directory to write execution and rule graphs to as `dot` files. The contents "
"of the directory will be overwritten if any filenames collide.",
)
register(
"--print-exception-stacktrace",
advanced=True,
type=bool,
fingerprint=False,
help="Print to console the full exception stack trace if encountered.",
)
# BinaryUtil options.
# TODO: Nuke these once we get rid of src/python/pants/binaries/binary_util.py
# (see there for what that will take).
register(
"--binaries-baseurls",
type=list,
advanced=True,
default=["https://binaries.pantsbuild.org"],
help="List of URLs from which binary tools are downloaded. URLs are "
"searched in order until the requested path is found.",
)
register(
"--binaries-fetch-timeout-secs",
type=int,
default=30,
advanced=True,
help="Timeout in seconds for URL reads when fetching binary tools from the "
"repos specified by --baseurls.",
)
register(
"--binaries-path-by-id",
type=dict,
advanced=True,
help=(
"Maps output of uname for a machine to a binary search path: "
"(sysname, id) -> (os, arch), e.g. {('darwin', '15'): ('mac', '10.11'), "
"('linux', 'arm32'): ('linux', 'arm32')}."
),
)
register(
"--allow-external-binary-tool-downloads",
type=bool,
default=True,
advanced=True,
help="If False, require BinaryTool subclasses to download their contents from urls "
"generated from --binaries-baseurls, even if the tool has an external url "
"generator. This can be necessary if using Pants in an environment which cannot "
"contact the wider Internet.",
)
# Pants Daemon options.
register(
"--pantsd-pailgun-port",
advanced=True,
type=int,
default=0,
daemon=True,
help="The port to bind the Pants nailgun server to. Defaults to a random port.",
)
# TODO(#7514): Make this default to 1.0 seconds if stdin is a tty!
register(
"--pantsd-pailgun-quit-timeout",
advanced=True,
type=float,
default=5.0,
help="The length of time (in seconds) to wait for further output after sending a "
"signal to the remote pantsd process before killing it.",
)
register(
"--pantsd-log-dir",
advanced=True,
default=None,
daemon=True,
help="The directory to log pantsd output to.",
)
register(
"--pantsd-invalidation-globs",
advanced=True,
type=list,
default=[],
daemon=True,
help="Filesystem events matching any of these globs will trigger a daemon restart. "
"Pants's own code, plugins, and `--pants-config-files` are inherently invalidated.",
)
register(
"--build-file-prelude-globs",
advanced=True,
type=list,
default=[],
help="Python files to evaluate and whose symbols should be exposed to all BUILD files ."
"This allows for writing functions which create multiple rules, or set default "
"arguments for rules. The order these files will be evaluated is undefined - they should not rely on each "
"other, or override symbols from each other.",
)
register(
"--local-store-dir",
advanced=True,
help=(
"Directory to use for engine's local file store. This may be absolute or relative."
),
# This default is also hard-coded into the engine's rust code in
# fs::Store::default_path so that tools using a Store outside of pants
# are likely to be able to use the same storage location.
default=os.path.join(get_pants_cachedir(), "lmdb_store"),
)
register(
"--local-execution-root-dir",
advanced=True,
help=(
"Directory to use for engine's local process execution sandboxing. This may be "
"absolute or relative."
),
default=tempfile.gettempdir(),
)
register(
"--named-caches-dir",
advanced=True,
help=(
"Directory to use as the base for named global caches for processes with trusted, "
"concurrency-safe caches. This may be absolute or relative."
),
default=os.path.join(get_pants_cachedir(), "named_caches"),
)
register(
"--remote-execution",
advanced=True,
type=bool,
default=DEFAULT_EXECUTION_OPTIONS.remote_execution,
help="Enables remote workers for increased parallelism. (Alpha)",
)
register(
"--remote-store-server",
advanced=True,
type=list,
default=[],
help="host:port of grpc server to use as remote execution file store.",
)
# TODO: Infer this from remote-store-connection-limit.
register(
"--remote-store-thread-count",
type=int,
advanced=True,
default=DEFAULT_EXECUTION_OPTIONS.remote_store_thread_count,
help="Thread count to use for the pool that interacts with the remote file store.",
)
register(
"--remote-execution-server",
advanced=True,
help="host:port of grpc server to use as remote execution scheduler.",
)
register(
"--remote-store-chunk-bytes",
type=int,
advanced=True,
default=DEFAULT_EXECUTION_OPTIONS.remote_store_chunk_bytes,
help="Size in bytes of chunks transferred to/from the remote file store.",
)
register(
"--remote-store-chunk-upload-timeout-seconds",
type=int,
advanced=True,
default=DEFAULT_EXECUTION_OPTIONS.remote_store_chunk_upload_timeout_seconds,
help="Timeout (in seconds) for uploads of individual chunks to the remote file store.",
)
register(
"--remote-store-rpc-retries",
type=int,
advanced=True,
default=DEFAULT_EXECUTION_OPTIONS.remote_store_rpc_retries,
help="Number of times to retry any RPC to the remote store before giving up.",
)
register(
"--remote-store-connection-limit",
type=int,
advanced=True,
default=DEFAULT_EXECUTION_OPTIONS.remote_store_connection_limit,
help="Number of remote stores to concurrently allow connections to.",
)
register(
"--remote-execution-process-cache-namespace",
advanced=True,
help="The cache namespace for remote process execution. "
"Bump this to invalidate every artifact's remote execution. "
"This is the remote execution equivalent of the legacy cache-key-gen-version "
"flag.",
)
register(
"--remote-instance-name",
advanced=True,
help="Name of the remote execution instance to use. Used for routing within "
"--remote-execution-server and --remote-store-server.",
)
register(
"--remote-ca-certs-path",
advanced=True,
help="Path to a PEM file containing CA certificates used for verifying secure "
"connections to --remote-execution-server and --remote-store-server. "
"If not specified, TLS will not be used.",
)
register(
"--remote-oauth-bearer-token-path",
advanced=True,
help="Path to a file containing an oauth token to use for grpc connections to "
"--remote-execution-server and --remote-store-server. If not specified, no "
"authorization will be performed.",
)
register(
"--remote-execution-extra-platform-properties",
advanced=True,
help="Platform properties to set on remote execution requests. "
"Format: property=value. Multiple values should be specified as multiple "
"occurrences of this flag. Pants itself may add additional platform properties.",
type=list,
default=[],
)
register(
"--remote-execution-headers",
advanced=True,
help="Headers to set on remote execution requests. "
"Format: header=value. Pants itself may add additional headers.",
type=dict,
default={},
)
register(
"--remote-execution-enable-streaming",
type=bool,
default=True,
advanced=True,
help="This option no longer does anything. (It used to enable the streaming remote execution client "
"which is now the only remote execution client.)",
removal_version="2.1.0.dev0",
removal_hint="This option is no longer applicable.",
)
register(
"--remote-execution-overall-deadline-secs",
type=int,
default=DEFAULT_EXECUTION_OPTIONS.remote_execution_overall_deadline_secs,
advanced=True,
help="Overall timeout in seconds for each remote execution request from time of submission",
)
register(
"--process-execution-local-parallelism",
type=int,
default=DEFAULT_EXECUTION_OPTIONS.process_execution_local_parallelism,
advanced=True,
help="Number of concurrent processes that may be executed locally.",
)
register(
"--process-execution-remote-parallelism",
type=int,
default=DEFAULT_EXECUTION_OPTIONS.process_execution_remote_parallelism,
advanced=True,
help="Number of concurrent processes that may be executed remotely.",
)
register(
"--process-execution-cleanup-local-dirs",
type=bool,
default=True,
advanced=True,
help="Whether or not to cleanup directories used for local process execution "
"(primarily useful for e.g. debugging).",
)
register(
"--process-execution-speculation-delay",
type=float,
default=DEFAULT_EXECUTION_OPTIONS.process_execution_speculation_delay,
advanced=True,
help="Number of seconds to wait before speculating a second request for a slow process. "
" see `--process-execution-speculation-strategy`",
)
register(
"--process-execution-speculation-strategy",
choices=["remote_first", "local_first", "none"],
default=DEFAULT_EXECUTION_OPTIONS.process_execution_speculation_strategy,
help="Speculate a second request for an underlying process if the first one does not complete within "
"`--process-execution-speculation-delay` seconds.\n"
"`local_first` (default): Try to run the process locally first, "
"and fall back to remote execution if available.\n"
"`remote_first`: Run the process on the remote execution backend if available, "
"and fall back to the local host if remote calls take longer than the speculation timeout.\n"
"`none`: Do not speculate about long running processes.",
advanced=True,
)
register(
"--process-execution-use-local-cache",
type=bool,
default=True,
advanced=True,
help="Whether to keep process executions in a local cache persisted to disk.",
)
register(
"--process-execution-local-enable-nailgun",
type=bool,
default=DEFAULT_EXECUTION_OPTIONS.process_execution_local_enable_nailgun,
help="Whether or not to use nailgun to run the requests that are marked as nailgunnable.",
advanced=True,
)
@classmethod
def register_options(cls, register):
"""Register options not tied to any particular task or subsystem."""
# The bootstrap options need to be registered on the post-bootstrap Options instance, so it
# won't choke on them on the command line, and also so we can access their values as regular
# global-scope options, for convenience.
cls.register_bootstrap_options(register)
register(
"--tag",
type=list,
metavar="[+-]tag1,tag2,...",
help="Include only targets with these tags (optional '+' prefix) or without these "
"tags ('-' prefix). See https://www.pantsbuild.org/docs/advanced-target-selection.",
)
register(
"--dynamic-ui",
type=bool,
default=(("CI" not in os.environ) and sys.stderr.isatty()),
help="Display a dynamically-updating console UI as Pants runs. This is true by default "
"if Pants detects a TTY and there is no 'CI' environment variable indicating that "
"Pants is running in a continuous integration environment; and false otherwise.",
)
register(
"--dependency-inference",
default=False,
type=bool,
advanced=True,
help=(
"Enable dependency inference, meaning that Pants will read your source code to "
"infer the `dependencies` field for you in BUILD files. You can check what Pants "
"inferred by running `./pants dependencies` on your target. You may still need to "
"explicitly provide some `dependencies` that cannot be inferred."
),
)
loop_flag = "--loop"
register(
loop_flag, type=bool, help="Run goals continuously as file changes are detected.",
)
register(
"--loop-max",
type=int,
default=2 ** 32,
advanced=True,
help=f"The maximum number of times to loop when `{loop_flag}` is specified.",
)
register(
"--lock",
advanced=True,
type=bool,
default=True,
help="Use a global lock to exclude other versions of Pants from running during "
"critical operations.",
)
register(
"--streaming-workunits-report-interval",
type=float,
default=10,
advanced=True,
help="Interval in seconds between when streaming workunit event receivers will be polled.",
)
register(
"--streaming-workunits-handlers",
type=list,
member_type=str,
default=[],
advanced=True,
help="Use this option to name Subsystems which will receive streaming workunit events. "
"For instance, `--streaming-workunits-handlers=\"['pants.reporting.workunit.Workunits']\"` will "
'register a Subsystem called Workunits defined in the module "pants.reporting.workunit".',
)
@classmethod
def validate_instance(cls, opts):
"""Validates an instance of global options for cases that are not prohibited via
registration.
For example: mutually exclusive options may be registered by passing a `mutually_exclusive_group`,
but when multiple flags must be specified together, it can be necessary to specify post-parse
checks.
Raises pants.option.errors.OptionsError on validation failure.
"""
if opts.remote_execution and not opts.remote_execution_server:
raise OptionsError(
"The `--remote-execution` option requires also setting "
"`--remote-execution-server` to work properly."
)
if opts.remote_execution_server and not opts.remote_store_server:
raise OptionsError(
"The `--remote-execution-server` option requires also setting "
"`--remote-store-server`. Often these have the same value."
)