
    ^ha(                        S r SSKJr  SSKrSSKrSSKr SSKrSSKJr  SS jrSS jr " S	 S
\5      rg! \	 a     " S S5      r
\
" 5       r\r N1f = f)z;Helper utilities for integrating argcomplete with traitlets    )annotationsN)CompletionFinderc                      \ rS rSrSS jrSrg)
StubModule   c                b    UR                  S5      (       d  [        S5      e[        SU S35      e)N__zNo module named 'argcomplete'z*argcomplete stub module has no attribute '')
startswithModuleNotFoundErrorAttributeError)selfattrs     ]/home/james-whalen/.local/lib/python3.13/site-packages/traitlets/config/argcomplete_config.py__getattr__StubModule.__getattr__   s3    ??4(()*IJJ #MdVST!UVV     N)r   strreturnt.Any)__name__
__module____qualname____firstlineno__r   __static_attributes__r   r   r   r   r      s    	Wr   r   c                 .   S[         R                  ;  a  g[         R                  S   n [        [         R                  S   5      n [        R                  " X5      u  nnnnn[        [         R                  S   5      S-
  nXWS nU$ ! [
         a     gf = f)zGet current words prior to completion point

This is normally done in the `argcomplete.CompletionFinder` constructor,
but is exposed here to allow `traitlets` to follow dynamic code-paths such
as determining whether to evaluate a subcommand.
_ARGCOMPLETEN	COMP_LINE
COMP_POINT   )osenvironintargcomplete
split_liner   )	comp_line
comp_pointcword_prequotecword_prefixcword_suffix
comp_wordslast_wordbreak_posstarts           r   get_argcomplete_cwordsr/      s     RZZ'

;'IRZZ-.J	 ""99	
 

>*+a/EF#J   s   B 
BBc                     [        [        [        R                  S   5      S-   5      [        R                  S'   g! [         aC     [
        R                  " S[        R                  S   5         g! [        [        4 a      gf = ff = f)aA  Assumes ``$_ARGCOMPLETE`` is set and `argcomplete` is importable

Increment the index pointed to by ``$_ARGCOMPLETE``, which is used to
determine which word `argcomplete` should start evaluating the command-line.
This may be useful to "inform" `argcomplete` that we have already evaluated
the first word as a subcommand.
r   r!   z!Unable to increment $_ARGCOMPLETEN)	r   r$   r"   r#   	Exceptionr%   debugKeyErrorr   r   r   r   increment_argcomplete_indexr4   @   ss    %(RZZ-G)H1)L%M

>" 	A2::nC]^-. 		s'   9< 
B	(A11BB	BB	c                     ^  \ rS rSr% SrS\S'   / rS\S'   / rS\S'   SS	 jrSS
 jr	        SU 4S jjr
      SU 4S jjrSrU =r$ )ExtendedCompletionFinderQ   ao  An extension of CompletionFinder which dynamically completes class-trait based options

This finder adds a few functionalities:

1. When completing options, it will add ``--Class.`` to the list of completions, for each
class in `Application.classes` that could complete the current option.
2. If it detects that we are currently trying to complete an option related to ``--Class.``,
it will add the corresponding config traits of Class to the `ArgumentParser` instance,
so that the traits' completers can be used.
3. If there are any subcommands, they are added as completions for the first word

Note that we are avoiding adding all config traits of all classes to the `ArgumentParser`,
which would be easier but would add more runtime overhead and would also make completions
appear more spammy.

These changes do require using the internals of `argcomplete.CompletionFinder`.
argparse.ArgumentParser_parserzt.List[t.Any]config_classest.List[str]subcommandsc                x   U R                    Vs/ s H  o"SUR                   S34PM     nnUnSU;   a7  USUR                  S5      S-    nU VVs/ s H  u  p%XQ:X  d  M  X%4PM     nnnU$ [        U5      S:  a/  U VVs/ s H   u  p%UR	                  U5      (       d  M  X%4PM"     nnnU$ s  snf s  snnf s  snnf )zMatch the word to be completed against our Configurable classes

Check if cword_prefix could potentially match against --{class}. for any class
in Application.classes.
--.Nr!   r   )r:   r   indexlenr   )r   r*   clsclass_completionsmatched_completionscs         r   match_class_completions0ExtendedCompletionFinder.match_class_completionsh   s     EIDWDWXDWSR~Q#78DWX/,'(E,*<*<S*AA*EFL<M"c<MQRQb8C8<M"c
 #"	 "):#):Xcall<>X):   # #" Y #d#s   B+B0B0?B6B6c           	         UR                  SS9R                  5        H  u  p#UR                  R                  S5      =(       d    [	        USS5      nUR                  R                  S5      nUU R
                  R                  SUR                   SU 3[        UR                  US9l
        M     g! [         a     gf = f)	a  Add dummy arguments to our ArgumentParser for the traits of this class

The argparse-based loader currently does not actually add any class traits to
the constructed ArgumentParser, only the flags & aliaes. In order to work nicely
with argcomplete's completers functionality, this method adds dummy arguments
of the form --Class.trait to the ArgumentParser instance.

This method should be called selectively to reduce runtime overhead and to avoid
spamming options across all of Application.classes.
T)configargcompleterNmultiplicityr>   r?   )typehelpnargs)class_traitsitemsmetadatagetgetattrr9   add_argumentr   r   rM   	completerr   )r   rB   	traitnametraitrU   rK   s         r   inject_class_to_parser/ExtendedCompletionFinder.inject_class_to_parsery   s    	$'$4$4D$4$A$G$G$I 	!NN..~> '>4C	  %~~11.A ( ))a	{3&	 *   %J  		s   B/B2 2
B?>B?c                  >^ U R                   R                  n[        T5      S:  =(       a    TS   U;   nU(       a:  U R                  T5      n[        U5      S:X  a  US   S   nU R	                  U5        O{[        U5      S:  al  SUS   ;   ac  U(       d\  USSS2    HP  n[        U5      S:  d  M  US   U;   d  M  U R                  U5      nU(       a  US   S   nU R	                  U5          O   [
        T
U ]  " UT/UQ76 n	U R                  (       aK  [        U5      S:X  a<  [        R                  " ST5        U	R                  U4S jU R                   5       5        U	$ )a  Overridden to dynamically append --Class.trait arguments if appropriate

Warning:
    This does not (currently) support completions of the form
    --Class1.Class2.<...>.trait, although this is valid for traitlets.
    Part of the reason is that we don't currently have a way to identify
    which classes may be used with Class1 as a parent.

Warning:
    This is an internal method in CompletionFinder and so the API might
    be subject to drift.
r   r!   r?   NzAdding subcommands forc              3  V   >#    U  H  oR                  T5      (       d  M  Uv   M      g 7fN)r   ).0subcr*   s     r   	<genexpr><ExtendedCompletionFinder._get_completions.<locals>.<genexpr>   s     b0@OOT`Datt0@s   )	))r9   prefix_charsrA   rF   rX   super_get_completionsr<   r%   r2   extend)r   r,   r*   argsrb   	is_optionrD   matched_cls	prev_wordcompletions	__class__s     `       r   rd   )ExtendedCompletionFinder._get_completions   sK   " ||00%)Ml1o.M	 #'">">|"L&'1,1!4Q7++K8_q SJrN%:9 ("-	y>A%)A,,*F*.*F*Fy*Q'*&9!&<Q&?33K@ . g.z<O$O J1 46Eb0@0@bbr   c                   > [         TU ]  X5      nUR                  S5      (       a  U$ U R                  U5      n[	        U5      S:  a  UR                  S U 5       5        U$ )z7Overridden to add --Class. completions when appropriater?   r!   c              3  *   #    U  H	  u  pUv   M     g 7fr]   r   )r^   rB   opts      r   r`   CExtendedCompletionFinder._get_option_completions.<locals>.<genexpr>   s     G3Fxss3Fs   )rc   _get_option_completionsendswithrF   rA   re   )r   parserr*   rj   rD   rk   s        r   rq   0ExtendedCompletionFinder._get_option_completions   sg    
 g5fK  %%"::<H"#a'G3FGG
 r   r   )r*   r   r   zt.List[t.Tuple[t.Any, str]])rB   r   r   None)r,   r;   r*   r   rf   r   r   r;   )rs   r8   r*   r   r   r;   )r   r   r   r   __doc____annotations__r:   r<   rF   rX   rd   rq   r   __classcell__)rk   s   @r   r6   r6   Q   sv    $ %$$&NM&!K!#"85%5585AF5	5n-=@	 r   r6   )r   zt.Optional[t.List[str]])r   ru   )rv   
__future__r   argparser"   typingtr%   r   ImportErrorr   objectr/   r4   r6   r   r   r   <module>r      sh    A #  	 ,"J"K/ KG  
W W ,K
s   
6 AA