
    h              
          S SK Jr  S SKJrJrJrJrJrJr  S SK	J
r
  S SKJr  S SKJr  SSKJr  \" S5      rS	S	S	S
SSS	S
S	S.	                     SS jjr0 4SS
S.         SS jjjrg	)    )annotations)AnyMappingSequenceTupleTypeVarUnion)	Annotated)Suppress)ConstructorRegistry   )TypeFormTNFT)	progdescriptionargsuse_underscoresconsole_outputsadd_helpconfigsort_subcommandsregistryc       	        d   SSK n
[        U R                  5       5      nU
R                  U
R                  R                  U Vs0 s H
  oX   S   _M     snU Vs0 s H
  oX   S   _M     snUS9UUUUUUU
R                  R                  4Uc
  [        5       O
[        U5      -   U	S9	$ s  snf s  snf )a	  Helper function for creating a CLI interface that allows us to choose
between default config objects (typically dataclasses) and override values
within it. Turns off subcommand creation for any union types within the
config object.

This is a lightweight wrapper over :func:`tyro.cli()`, with some default
arguments populated. Also see
:func:`tyro.extras.subcommand_type_from_defaults()`.


Example usage:

.. code-block:: python

    import dataclasses

    import tyro


    @dataclasses.dataclass
    class Config:
        a: int
        b: str


    default_configs = {
        "small": (
            "Small config",
            Config(1, "small"),
        ),
        "big": (
            "Big config",
            Config(100, "big"),
        ),
    }
    config = tyro.extras.overridable_config_cli(default_configs)
    print(config)

Args:
    configs: A dictionary of config names mapped to a tuple of
        (description, config object).
    prog: The name of the program printed in helptext. Mirrors argument from
        `argparse.ArgumentParser()`.
    description: Description text for the parser, displayed when the --help flag is
        passed in. If not specified, the class docstring is used. Mirrors argument from
        `argparse.ArgumentParser()`.
    args: If set, parse arguments from a sequence of strings instead of the
        commandline. Mirrors argument from `argparse.ArgumentParser.parse_args()`.
    use_underscores: If True, use underscores as a word delimiter instead of hyphens.
        This primarily impacts helptext; underscores and hyphens are treated equivalently
        when parsing happens. We default helptext to hyphens to follow the GNU style guide.
        https://www.gnu.org/software/libc/manual/html_node/Argument-Syntax.html
    console_outputs: If set to `False`, parsing errors and help messages will be
        suppressed.
    add_help: Add a -h/--help option to the parser. This mirrors the argument from
        `argparse.ArgumentParser()`.
    config: Sequence of config marker objects, from `tyro.conf`. We include
        :class:`tyro.conf.AvoidSubcommands` by default.
    sort_subcommands: If True, sort the subcommands alphabetically by name.
    registry: A :class:`tyro.constructors.ConstructorRegistry` instance containing custom
        constructor rules.
r   N   )defaultsdescriptionsr   )r   r   r   r   r   r   r   r   )	tyrolistkeyscliextrassubcommand_type_from_defaultsconfAvoidSubcommandstuple)configsr   r   r   r   r   r   r   r   r   r   r   ks                S/home/james-whalen/.local/lib/python3.13/site-packages/tyro/extras/_base_configs.pyoverridable_config_clir)      s    V D88110451A&5489DqWZ]*D9- 	2 	

 ''		**,n57%-9   59s   B(B-)prefix_namesr   c                  ^ ^^^ SSK m[        T R                  5       5      nU(       a  [        U5      n[        [        U UUU4S jU 5       5      [        S[        4   4-      $ )a  Construct a Union type for defining subcommands that choose between defaults.

For example, when ``defaults`` is set to:

.. code-block:: python

    {
        "small": Config(...),
        "big": Config(...),
    }

We return:

.. code-block:: python

    Union[
        Annotated[
            Config,
            tyro.conf.subcommand("small", default=Config(...))
        ],
        Annotated[
            Config,
            tyro.conf.subcommand("big", default=Config(...))
        ]
    ]

Direct use of :py:data:`typing.Union` and :func:`tyro.conf.subcommand()` should generally be
preferred, but this function can be helpful for succinctness.

.. warning::

    The type returned by this function can be safely used as an input to
    :func:`tyro.cli()`, but for static analysis when used for annotations we
    recommend applying a `TYPE_CHECKING` guard:

    .. code-block:: python

        from typing import TYPE_CHECKING

        if TYPE_CHECKING:
            # Static type seen by language servers, type checkers, etc.
            SelectableConfig = Config
        else:
            # Runtime type used by tyro.
            SelectableConfig = subcommand_type_from_defaults(...)

Args:
    defaults: A dictionary of default subcommand instances.
    descriptions: A dictionary conttaining descriptions for helptext.
    prefix_names: Whether to prefix subcommand names.
    sort_subcommands: If True, sort the subcommands alphabetically by name.

Returns:
    A subcommand type, which can be passed to :func:`tyro.cli`.
r   Nc              3     >#    U  HI  n[         [        TU   5      TR                  R                  UTU   TR	                  US 5      TS94   v   MK     g7f) )defaultr   prefix_nameN)r
   typer#   
subcommandget).0r'   r   r   r*   r   s     r(   	<genexpr>0subcommand_type_from_defaults.<locals>.<genexpr>   sf      
  !%II(( ($0$4$4Q$;$0	 ) 
 s   AA)r   r   r   sortedr	   r%   r
   r   )r   r   r*   r   r   r   s   ```  @r(   r"   r"   p   s_    |  Dd| 
 
 	
" T8^$
&#	'     )r&   zMapping[str, Tuple[str, T]]r   
str | Noner   r8   r   zSequence[str] | Noner   boolr   r9   r   r9   r   zSequence[Any] | Noner   r9   r   zConstructorRegistry | Nonereturnr   )
r   zMapping[str, T]r   zMapping[str, str]r*   r9   r   r9   r:   zTypeForm[T])
__future__r   typingr   r   r   r   r   r	   typing_extensionsr
   tyro.conf._markersr   tyro.constructorsr   _typingr   r   r)   r"    r7   r(   <module>rB      s
   " @ @ ' ' 1 CL "!%! #'"+/^(^ ^ 	^
 ^ ^ ^ ^ !^ ^ )^ ^F ')V "VV#V 	V
 V Vr7   