github.com/tilt-dev/tilt@v0.33.15-0.20240515162809-0a22ed45d8a0/internal/tiltfile/api/config/__init__.py (about)

     1  from typing import Dict, Union, List, Callable, Any
     2  
     3  tilt_subcommand: str = ''
     4  """The sub-command with which `tilt` was invoked. Does not include extra args or options.
     5  
     6  Examples:
     7  
     8  - run `tilt down` -> `config.tilt_subcommand == "down"`
     9  - run `tilt up frontend backend` -> `config.tilt_subcommand == "up"`
    10  - run `tilt alpha tiltfile-result` -> `config.tilt_subcommand == "alpha tiltfile-result"`
    11  """
    12  
    13  main_path: str = ''
    14  """The absolute path of the main Tiltfile."""
    15  
    16  main_dir: str = ''
    17  """The absolute directory of the main Tiltfile.
    18  
    19  Often used to determine the location of vendored code and caches."""
    20  
    21  def define_string_list(name: str, args: bool=False, usage: str="") -> None:
    22      """
    23      Defines a config setting of type `List[str]`.
    24  
    25      Allows the user invoking Tilt to configure a key named ``name`` to be in the
    26      dict returned by :meth:`parse`.
    27  
    28      See the `Tiltfile config documentation <tiltfile_config.html>`_ for examples
    29      and more information.
    30  
    31      Args:
    32        name: The name of the config setting
    33        args: If False, the config setting is specified by its name. (e.g., if it's named "foo",
    34              ``tilt up -- --foo bar`` this setting would be ``["bar"]``.)
    35  
    36              If True, the config setting is specified by unnamed positional args. (e.g.,
    37              in ``tilt up -- 1 2 3``, this setting would be ``["1" "2" "3"]``.)
    38        usage: When arg parsing fails, what to print for this setting's description.
    39      """
    40  
    41  def define_string(name: str, args: bool=False, usage: str="") -> None:
    42      """
    43      Defines a config setting of type `str`.
    44  
    45      Allows the user invoking Tilt to configure a key named ``name`` to be in the
    46      dict returned by :meth:`parse`.
    47  
    48      For instance, at runtime, to set a flag of this type named `foo` to value "bar", run ``tilt up -- --foo bar``.
    49  
    50      See the `Tiltfile config documentation <tiltfile_config.html>`_ for examples
    51      and more information.
    52  
    53      Args:
    54        name: The name of the config setting
    55        args: If False, the config setting is specified by its name. (e.g., if it's named "foo",
    56              ``tilt up -- --foo bar`` this setting would be ``"bar"``.)
    57  
    58              If True, the config setting is specified by unnamed positional args. (e.g.,
    59              in ``tilt up -- 1``, this setting would be ``"1"``.)
    60        usage: When arg parsing fails, what to print for this setting's description.
    61      """
    62  
    63  def define_bool(name: str, args: bool=False, usage: str="") -> None:
    64      """
    65      Defines a config setting of type `bool`.
    66  
    67      Allows the user invoking Tilt to configure a key named ``name`` to be in the
    68      dict returned by :meth:`parse`.
    69  
    70      For instance, at runtime, to set a flag of this type named `foo` to value `True`, run ``tilt up -- --foo``.
    71      To set a value to ``False``, you can run ``tilt up -- --foo=False``, or use a default value, e.g.::
    72  
    73        config.define_bool('foo')
    74        cfg = config.parse()
    75        do_stuff = cfg.get('foo', False)
    76  
    77      See the `Tiltfile config documentation <tiltfile_config.html>`_ for examples
    78      and more information.
    79  
    80      Args:
    81        name: The name of the config setting
    82        args: If False, the config setting is specified by its name. (e.g., if it's named "foo",
    83              ``tilt up -- --foo`` this setting would be ``True``.)
    84  
    85              If True, the config setting is specified by unnamed positional args. (e.g.,
    86              in ``tilt up -- True``, this setting would be ``True``.) (This usage
    87              isn't likely to be what you want)
    88        usage: When arg parsing fails, what to print for this setting's description.
    89      """
    90  
    91  def parse() -> Dict[str, Any]:
    92      """
    93      Loads config settings from tilt_config.json, overlays config settings from
    94      Tiltfile command-line args, validates them using the setting definitions
    95      specified in the Tiltfile, and returns a Dict of the resulting settings.
    96  
    97      Settings that are defined in the Tiltfile but not specified in the config
    98      file or command-line args will be absent from the dict. Access values via,
    99      e.g., `cfg.get('foo', ["hello"])` to have a default value.
   100  
   101      Note: by default, Tilt interprets the Tilt command-line args as the names of
   102      Tilt resources to run. When a Tiltfile calls :meth:`parse`, that behavior is
   103      suppressed, since those args are now managed by :meth:parse. If a
   104      Tiltfile uses :meth:`parse` and also needs to allow specifying a set
   105      of resources to run, it needs to call :meth:`set_enabled_resources`.
   106  
   107      See the `Tiltfile config documentation <tiltfile_config.html>`_ for examples
   108      and more information.
   109  
   110      Returns:
   111        A Dict where the keys are settings names and the values are their values.
   112      """
   113  
   114  def set_enabled_resources(resources: List[str]) -> None:
   115      """
   116      Tells Tilt to only run the specified resources.
   117      (takes precedence over the default behavior of "run the resources specified
   118      on the command line")
   119  
   120      Calling this with an empty list results in all resources being run.
   121  
   122      See the `Tiltfile config documentation <tiltfile_config.html>`_ for examples
   123      and more information.
   124  
   125      Args:
   126        resources: The names of the resources to run, or an empty list to run them
   127                   all.
   128      """
   129  
   130  def clear_enabled_resources() -> None:
   131      """
   132      Tells Tilt that all resources should be disabled. This allows the user to manually enable only the resources they want once Tilt is running.
   133      """