K ia(dZddlmZddlZddlZddlZ ddlZddlmZd dZ d dZ Gd d eZy#e $rGddZ e Ze ZY.wxYw) z;Helper utilities for integrating argcomplete with traitlets) annotationsN)CompletionFinderceZdZddZy) StubModulecX|jds tdtd|d)N__zNo module named 'argcomplete'z*argcomplete stub module has no attribute '') startswithModuleNotFoundErrorAttributeError)selfattrs i/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/traitlets/config/argcomplete_config.py __getattr__zStubModule.__getattr__s0??4()*IJJ #MdVST!UV VN)rstrreturnt.Any)__name__ __module__ __qualname__rrrrrs Wrrc*dtjvrytjd}ttjd} tj||\}}}}}ttjddz }||d}|S#t $rYywxYw)aGet 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)osenvironint argcomplete split_liner ) comp_line comp_pointcword_prequote cword_prefix cword_suffix comp_wordslast_wordbreak_posstarts rget_argcomplete_cwordsr+sRZZ' ;'IRZZ -.J   " "9j 9        >* +a /EEF#J  sB BBc tttjddztjd<y#t$rA t j dtjdYy#ttf$rYYywxYwwxYw)aUAssumes ``$_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. rrz!Unable to increment $_ARGCOMPLETEN) rr rr Exceptionr!debugKeyErrorr rrrincrement_argcomplete_indexr0@ss%(RZZ-G)H1)L%M >"     A2::nC] ^-.   s'9< B'A//B>BBBceZdZUdZded<gZded<gZded<d dZd d Z dfd Z dfd Z xZ S)ExtendedCompletionFinderaAn 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\|jDcgc]}|d|jdf}}|}d|vr5|d|jddz}|Dcgc]\}}||k(s ||f}}}|St|dkDr(|Dcgc]\}}|j |s||f}}}|Scc}wcc}}wcc}}w)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. --.Nrr)r5rindexlenr )r r&clsclass_completionsmatched_completionscs rmatch_class_completionsz0ExtendedCompletionFinder.match_class_completionshs EIDWDWXScR ~Q#78XX/ , '(E,*<*Xa# ##"Y#d#sB B"B"8B(B(c |jdjD]\}}|jjdxs t |dd}|jjd}||j j d|jd|t|j|_ y#t$rYywxYw) 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 multiplicityr9r:)typehelpnargs) class_traitsitemsmetadatagetgetattrr4 add_argumentrrrG completerr )r r= traitnametraitrOrEs rinject_class_to_parserz/ExtendedCompletionFinder.inject_class_to_parserys $'$4$4D$4$A$G$G$I ( 5!NN..~>'>4C  %~~11.A (  ))a {3& *  (   sB/B22 B>=B>ct|jj}tdkDxrd|v}|r9|j}t|dk(r|dd}|j |nht|dkDrZd|dvrS|sQ|dddD]F}t|dkDs|d|vs|j|}|r|dd}|j |nt ||g|} |jrHt|dk(r:tjd| jfd|jD| S)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. rrr:NzAdding subcommands forc3FK|]}|js|ywN)r ).0subcr&s r z.sbDOOT`Datbs!!) r4 prefix_charsr<rArRsuper_get_completionsr7r!r.extend) r r(r&argsrZ is_optionr? matched_cls prev_word completions __class__s ` rr\z)ExtendedCompletionFinder._get_completionssO"||00  %)Ml1o.M #'">">|"L &'1,1!4Q7 ++K8 _q SJrN%:9 ("-  y>A%)A,,*F*.*F*Fy*Q'*&9!&.sGxsCsGs)r[_get_option_completionsendswithrAr<r])r parserr&rbr?rcs rrgz0ExtendedCompletionFinder._get_option_completionssf g5flK   % "::<H " #a '   G3FG G r)r&rrzt.List[t.Tuple[t.Any, str]])r=rrNone)r(r6r&rr^rrr6)rir3r&rrr6) rrr__doc____annotations__r5r7rArRr\rg __classcell__)rcs@rr2r2Qsv$%$$&NM&!K!#"85%5585AF5 5n-=@ rr2)rzt.Optional[t.List[str]])rrj)rk __future__rargparsertypingtr!r ImportErrorrobjectr+r0r2rrrrtshA#  ,"J"K/KG WW ,K s 4AA