
    k7i8              	          S r SSKrSSKrSSKrSSKJrJrJrJr  SSK	J
r
  SSKJr  SSKJrJrJrJr  SSKJrJr  \" S5      r\(       a  SS	KJr  SS
KJr  SSKJr  OSSKJr  \R6                  " \SS9rSSKJr   " S S\5      r " S S\S9r  " S S\ 5      r!S\"S\\\   /\\   4   4S jr#S\$4S jr%S\$4S jr&SS\-  \\   -  S\'\S4   4S jr(SS\-  \\   -  S\)\   4S jr*SS\-  \\   -  S\'\S4   S-  4S  jr+S\S\4S! jr,S"S\S#   -  \-  S\S-  4S$ jr-S%\"S\"4S& jr.S%\"S\"4S' jr/S(\\   S)\0S\\'\S4      4S* jr1S+S,.S-\"S\$4S. jjr2S/\S\$4S0 jr3S1 r4\ " S2 S35      5       r5S9S4S5S6\0S\"4S7 jjr6S:S8 jr7g);z^To prevent circular dependencies, this module should never import anything else from Cyclopts.    N)CallableIterableIteratorSequence)suppress)
itemgetter)TYPE_CHECKINGAnyLiteralTypeVar)fieldfrozenT)JSONDecodeError)r   Console)defineT)unsafe_hash)stdlib_module_namesc                   6    \ rS rSrS\4S jrS\S   4S jrSrg)SentinelMeta   returnc                 "    SU R                    S3$ )N<>)__name__clss    H/home/james-whalen/.local/lib/python3.13/site-packages/cyclopts/utils.py__repr__SentinelMeta.__repr__   s    3<<.""    Fc                     g)NF r   s    r    __bool__SentinelMeta.__bool__!   s    r#   r%   N)	r   
__module____qualname____firstlineno__strr!   r   r&   __static_attributes__r%   r#   r    r   r      s    # # r#   r   c                       \ rS rSrS rSrg)Sentinel%   c                     [        S5      e)NzGSentinel objects are not intended to be instantiated. Subclass instead.)
ValueErrorr   s    r    __new__Sentinel.__new__&   s    bccr#   r%   N)r   r(   r)   r*   r2   r,   r%   r#   r    r.   r.   %   s    dr#   r.   )	metaclassc                       \ rS rSrSrSrg)UNSET*   zTSpecial sentinel value indicating that no data was provided. **Do not instantiate**.r%   N)r   r(   r)   r*   __doc__r,   r%   r#   r    r6   r6   *   s    ^r#   r6   targetr   c                 L   ^  S[         [           S[         [           4U 4S jjnU$ )zJClass decorator that records init argument names as a tuple to ``target``.r   r   c                    >^^ U R                   m[        R                  " T5      n[        S UR                   5       5      m[
        R                  " T5      UUU4S j5       nX l         U $ )Nc              3   4   #    U  H  oS :w  d  M
  Uv   M     g7f)selfNr%   ).0names     r    	<genexpr>1record_init.<locals>.decorator.<locals>.<genexpr>4   s     ]-JTV\nDD-Js   		c                    > T" U /UQ70 UD6  [         R                  U T[        U4S j[        [	        U5      5       5       5      [        U5      -   5        g )Nc              3   .   >#    U  H
  nTU   v   M     g 7fNr%   )r>   iparam_namess     r    r@   Crecord_init.<locals>.decorator.<locals>.new_init.<locals>.<genexpr>:   s     2\K[a;q>K[s   )object__setattr__tuplerangelen)r=   argskwargsoriginal_initrF   r9   s      r    new_init0record_init.<locals>.decorator.<locals>.new_init6   sJ    $000tVU2\5QTUYQZK[2\-\_dek_l-lmr#   )__init__inspect	signaturerJ   
parameters	functoolswraps)r   function_signaturerP   rO   rF   r9   s      @@r    	decoratorrecord_init.<locals>.decorator1   s]    $..}=]-?-J-J]]		'	n 
(	n
  
r#   )typer   )r9   rY   s   ` r    record_initr\   .   s&    tAw 47  r#   c                     [        U [        [        -  [        -  [        -  5      (       a  g[        U [
        5      (       + =(       a    [        U [        5      $ )NT)
isinstancelistrJ   setdictr+   r   objs    r    is_iterablerd   B   s<    #te|c)D011#s##A
3(AAr#   c                 t     [         R                  " U 5      =(       a    [        X5      $ ! [         a     gf = f)a7  Safely check if a type is both a class and a subclass of target_class.

Parameters
----------
hint : Any
    The type to check.
target_class : type
    The target class to check subclass relationship against.

Returns
-------
bool
    True if hint is a class and is a subclass of target_class, False otherwise.
F)rS   isclass
issubclass	TypeError)hinttarget_classs     r    is_class_and_subclassrk   H   s2    t$GD)GG s   '* 
77value.c                 F    U c  g[        U 5      (       a  [        U 5      $ U 4$ )a  Convert a single element or an iterable of elements into a tuple.

Intended to be used in an ``attrs.Field``. If :obj:`None` is provided, returns an empty tuple.
If a single element is provided, returns a tuple containing just that element.
If an iterable is provided, converts it into a tuple.

Parameters
----------
value: Any | Iterable[Any] | None
    An element, an iterable of elements, or None.

Returns
-------
tuple[Any, ...]: A tuple containing the elements.
r%   )rd   rJ   rl   s    r    to_tuple_converterro   ^   s(      }	U		U|xr#   c                 *    [        [        U 5      5      $ rD   )r_   ro   rn   s    r    to_list_converterrq   v   s    "5)**r#   c                 0    U c  gU (       d  g[        U 5      $ )zkConvert a string or Iterable or None into an Iterable or None.

Intended to be used in an ``attrs.Field``.
Nr%   )ro   rn   s    r    optional_to_tuple_converterrs   z   s    
 }e$$r#   c                 d    U c  [         $ [        R                  " U 5      (       a  [        U 5      $ U $ )a  Convert sort_key value, consuming generators with :func:`next`.

Parameters
----------
value : Any
    The sort_key value to convert. Can be None, a generator, or any other value.

Returns
-------
Any
    UNSET if value is None, ``next(value)`` if generator, otherwise value unchanged.
)r6   rS   isgeneratornextrn   s    r    sort_key_converterrw      s.     }			U	#	#E{r#   input_value)defaultplainc                     U c  g[        U [        5      (       a6  U S:X  a  SSKJn  U" 5       $ U S:X  a  SSKJn  U" 5       $ [        SU < S35      eU $ )	ax  Convert string literals to help formatter instances.

Parameters
----------
input_value : None | Literal["default", "plain"] | Any
    The input value to convert. Can be None, "default", "plain", or a formatter instance.

Returns
-------
Any | None
    None, or a HelpFormatter instance.

Notes
-----
Lazily imports formatters to avoid importing Rich during normal execution.
Nry   r   )DefaultFormatterrz   )PlainFormatterzUnknown formatter: z. Must be 'default' or 'plain')r^   r+   cyclopts.help.formattersr|   r}   r1   )rx   r|   r}   s      r    help_formatter_converterr      s`    & 	K	%	%)#A#%%G#?!##2;/A_`aa r#   sc                     [         R                  " SS U 5      n[         R                  " SS U5      n[         R                  " SS U5      nUR                  5       $ )Nz([A-Z]+)([A-Z][a-z])c                 L    U R                  S5       SU R                  S5       3$ N   _   groupms    r    <lambda>"_pascal_to_snake.<locals>.<lambda>   s    Aaggaj\6Rr#   z([a-z])([A-Z])c                 L    U R                  S5       SU R                  S5       3$ r   r   r   s    r    r   r          1771:,a
|0Lr#   z([0-9])([A-Z])c                 L    U R                  S5       SU R                  S5       3$ r   r   r   s    r    r   r      r   r#   )resublower)r   snakes     r    _pascal_to_snaker      sM     FF*,RTUVEFF$&LeTEFF$&LeTE;;=r#   c                 r    [        U 5      R                  5       R                  SS5      R                  S5      $ )a  Converts a python identifier into a CLI token.

Performs the following operations (in order):

1. Convert PascalCase to snake_case.
2. Convert the string to all lowercase.
3. Replace ``_`` with ``-``.
4. Strip any leading/trailing ``-`` (also stripping ``_``, due to point 3).

Intended to be used with :attr:`App.name_transform` and :attr:`Parameter.name_transform`.

Parameters
----------
s: str
    Input python identifier string.

Returns
-------
str
    Transformed name.
r   -)r   r   replacestrip)r   s    r    default_name_transformr      s0    , A$$&..sC8>>sCCr#   iterablenc                     [        U 5      U-  (       a  [        U < SU S35      e[        U 5      /U-  n[        USS06$ )a  Collect data into non-overlapping fixed-length chunks or blocks.

https://docs.python.org/3/library/itertools.html#itertools-recipes

Parameters
----------
iterable: Sequence[Any]
    Some iterable sequence to group.
n: int
    Number of elements to put in each group.
z is not divisible by .strictF)rL   r1   iterzip)r   r   	iteratorss      r    grouperr      sJ     8}qH<'<QCqABBh 1$I	(%((r#   F)allow_numberstokenc                    U(       dC  [        [        5         [        U 5        U R                  5       S:X  a
   SSS5        g SSS5        gU R	                  S5      $ ! , (       d  f       N= f)a   Checks if a token looks like an option.

Namely, negative numbers are not options, but a token like ``--foo`` is.

Parameters
----------
token: str
    String to interpret.
allow_numbers: bool
    If :obj:`True`, then negative numbers (e.g. ``"-2"``) will return :obj:`True`.
    Otherwise, numbers will be interpreted as non-option-like (:obj:`False`).
    Note: ``-j`` **is option-like**, even though it can represent an imaginary number.

Returns
-------
bool
    Whether or not the ``token`` is option-like.
z-jNTFr   )r   r1   complexr   
startswith)r   r   s     r    is_option_liker      sZ    & j!EN{{}$  "!  "! C   "!s   !AA
A*rc   c                 N    [        U SS5      R                  S5      S   [        ;   $ )Nr(    r   r   )getattrsplitr   rb   s    r    
is_builtinr     s'    3b)//4Q7;NNNr#   c                    [        U [        [        5      5      (       a  U $ [        U 5      (       a  U " U0 UD6$ [	        U 5      (       a  / nU  H  n[        U[        [        5      5      (       a  UR                  U5        M4  [        U5      (       a  UR                  U" U0 UD65        M]  [	        U5      (       a   UR                  [        U/UQ70 UD65        M  UR                  U5        M     [        U5      $ U $ )zRecursively resolves callable elements in a tuple.

Returns an object that "looks like" the input, but with all callable's invoked
and replaced with their return values. Positional and keyword elements will be
passed along to each invocation.
)r^   r[   r.   callablerd   appendresolve_callablesrJ   )trM   rN   resolvedelements        r    r   r     s     !T(^$${{$!&!!	QG'4>22('"" 8 89W%% 1' KD KF KL(  Xr#   c                   r    \ rS rSr% Sr\\S'    \" \S9r	\\S'    \\S'    \
S\S    S\S    4S	 j5       rS
rg)
SortHelperi7  zLSort a list of objects by an external key and retrieve the objects in-order.key)	converterfallback_keyrl   entriesr   c                    SSK JnJnJn  / n/ n/ n/ n/ n/ n	U  GH1  n
U
R                  UL a  UR                  SU
45        M(  U
R                  UL a  UR                  SU
45        ML  U
R                  UL a  UR                  SU
45        Mp  U
R                  [        S4;   a  U	R                  U
R                  U
45        M  [        U
R                  5      (       aI  U
R                  S   [        S4;   a0  UR                  U
R                  SS U
R                  -   U
45        GM  UR                  U
R                  U
R                  4U
45        GM4     UR                  [        S5      S9  UR                  [        S5      S9  U	R                  [        S5      S9  UU-   U-   U-   U-   U	-   nU Vs/ s H  oS   PM	     sn$ s  snf )z(Sorts a sequence of :class:`SortHelper`.r   )#DEFAULT_ARGUMENTS_GROUP_SORT_MARKER"DEFAULT_COMMANDS_GROUP_SORT_MARKER$DEFAULT_PARAMETERS_GROUP_SORT_MARKERNr   )r   )cyclopts.groupr   r   r   r   r   r6   r   rd   sortr   )r   r   r   r   default_commands_groupdefault_arguments_groupdefault_parameters_groupuser_sort_keyordered_no_user_sort_keyno_user_sort_keyentrycombinedxs                r    r   SortHelper.sortH  s   	
 	
 "$"$#% #% Eyy>>&--tUm<AA'..e}=BB(//u>udm+ ''););U(CDUYY''EIIaLUDM,I )//12ASAS1SUZ0[\$$uyy%2D2D&Eu%MN   	z!}- %%*Q-%8*Q-0 #%&&'  '	'
  	 ''h!h'''s   ,F=r%   N)r   r(   r)   r*   r8   r
   __annotations__r   ro   r   staticmethodr   r_   r   r,   r%   r#   r    r   r   7  sZ    V	H
 (:;L#; JJ,(h|, ,(l1C ,( ,(r#   r   decode_errorr   contextc           
      T   U R                   R                  5       nX R                  S-
     nU R                  S-
  nXA-
  nUS::  a  SnSnUnOSnXE-
  nXA-   nU[	        U5      :  a  [	        U5      S-   nSn	OSn	X5U n
S[	        U5      U-   -  S-   nSU U
 U	 S	U S
[        U 5       3nU$ )zNot intended to be a super robust implementation, but robust enough to be helpful.

Parameters
----------
context: int
    Number of surrounding-character context
r   r   r   z... z ... ^zJSONDecodeError:
    z
    
)doc
splitlineslinenocolnorL   r+   )r   r   lineslineerror_indexstartprefix_ellipsissegment_error_indexendsuffix_ellipsissegmentcarat_pointerresponses                r    json_decode_error_verbosifierr   x  s     '')E$$q()D$$q(K!Ez) )1

C
c$i$i!m oG3/2EEFLM ! 1'?:K6R_Q``bcfgsctbuv  Or#   c           
      @   SSK Jn  U R                  =(       d    SnU" S0 SS_SU_S[        U SS	5      _S
U R                  =(       d    S	_SU R
                  =(       d    S	_SU R                  _SU R                  _S[        U SS	5      _SU R                  _S[        U SS5      _S[        U SS5      _S[        U SS	5      _S[        U SS5      _SU R                  _SU R                  _SU R                  _S[        U SS	5      _S[        U SS	5      _S[        U SS	5      _6$ ) a  Create an error console (stderr=True) that inherits settings from a source console.

Parameters
----------
console : Console
    Source Rich Console to copy settings from.

Returns
-------
Console
    New Rich Console with stderr=True and inherited settings.
r   r   autostderrTcolor_systemforce_terminal_force_terminalNforce_jupyterforce_interactive	soft_wrapwidthheight_heighttab_sizemarkup_markupemoji_emojiemoji_variant_emoji_variant	highlight
_highlightno_colorlegacy_windowssafe_box_environget_datetimeget_timer%   )rich.consoler   r   r   
is_jupyteris_interactiver   _widthr   r   r   r   )consoler   r   s      r    !create_error_console_from_consoler    sk    %''16L ! w(94@ ((0D	
 "008D ## nn w	40 !! w	40 gx. g'7> '<6 !! --  !!!" *d3#$ Wnd;%& *d3' r#   )   )r  r   r   r   )8r8   rV   rS   r   collections.abcr   r   r   r   
contextlibr   operatorr   typingr	   r
   r   r   attrsr   r   r   jsonr   r   r   r   partialsysr   r[   r   r.   r6   r+   r\   boolrd   rk   rJ   ro   r_   rq   rs   rw   r   r   r   intr   r   r   r   r   r   r  r%   r#   r    <module>r     s9   d   	 B B   7 7 CL $$v48F #4 d d
_H _ $q'DG); < (B B ,dSj8C=8 U38_ 0+TCZ(3-7 +DI +%tczHSM'A %eCQTHoX\F\ %c c *" 233c9"4Z"J  Dc Dc D2)hsm ) )sCx0I )$ 16 !# !$ !>OC OD O8 =( =( =(@"0A "C "Y\ "J%r#   