
    Y j                     
   % S r SSKrSSKrSSKrSSKrSSKrSSKrSSKrSSK	r	SSK
r
SSKrSSK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JrJrJr  SSKrSSKrSSKJrJr  SSK J!r!J"r"J#r#  SS	K$J%r%  SS
K&J'r'J(r(J)r)J*r*J+r+  SSK,J-r-  SSK.J/r/J0r0  \*Rb                  " 5       r2Sr3Sr4\(       a  SSK5J6r6  SS\7S-  SS4S jjr8Sr9SS\:\7   S\7S-  S\74S jjr;\S   \7-  r<\\:\7   \=\7   /\>S-  4   r?\" S\7S9r@S\7S-  S\R                  S\R                  SS4S jrC\R                  " S 5      rE " S! S"\5      rF/ S#QrG\:\H\7\74      \IS$'   S\R                  SS4S% jrJS&\R                  S\L4S' jrMS&\R                  S(\:\7   SS4S) jrNS(\:\7   S*\LS+\LSS4S, jrOS-\7SS.4S/ jrPS0\R                  S1\7S2\:\H\7\74      SS4S3 jrR SS4\?S5\/ \:\H\7\74      4   S-  S\S\F   4S6 jjrTSS7\<S\:\7   S-  S\S\   4S8 jjrU " S9 S:\R                  5      rWSS;\7S\7S-  S<\S\   S-  SS:4S= jjrX " S> S?\7\5      rY\\7\R                  " S@SA94   r[\\Y\R                  " SBSCSDSA94   r]\\7S-  \R                  " SESA94   r^\\LS-  \R                  " SFSA94   r_\\7S-  \R                  " SGSA94   r`\\>\R                  " SHSA94   ra\\7S-  \R                  " SISA94   rb\\:\7   S-  \R                  " SJSA94   rc\\7S-  \R                  " SKSA94   rd\\:\7   S-  \R                  " SLSMSNSA94   re\\:\7   S-  \R                  " SOSPSQSA94   rf\\7S-  \R                  " SRSSSA94   rg\\7S-  \R                  " STSA94   rhS\i\7\74   4SU jrj  SSV\:\7   S-  SW\7S-  S\i\7\7S-  4   4SX jjrkSY\i\7\7S-  4   S\:\i\7\74      S-  4SZ jrl\\:\7   S-  \R                  " S[S\S]SA94   rmS^rn\#R                  \#R                  \#R                  S_S`.rrSa\:\7   S-  SSb4Sc jrs " Sd Se\7\5      rt\\t\R                  " SfSA94   ruS-\/S\/4Sg jrv\\/\R                  " Sh\vSi94   rw\\L\R                  " SjSkSlSA94   rxSm\7S\74Sn jryS-\S\74So jrz\34S-\Sp\>S\74Sq jjr{ SS2\\i\7\4      Sr\:\7   Ss\\i\7\4   /\:\7   4   St\i\7\74   S-  SS4
Su jjr|    SS2\\i\7\4      Sv\tSw\LSx\7Sr\:\7   S-  Ss\\i\7\4   /\:\7   4   S-  St\i\7\74   S-  SS4Sy jjr}Sz\~S\~4S{ jrS|\S\i\7\4   4S} jrS~\\@   4S jrS\S   SS4S jrS\S   SS4S jrS\7S\7S-  4S jrS\>4S jrS\:\7   S-  4S jrS\:\7   S-  4S jrg)z*Contains CLI utilities (styling, helpers).    N)CallableSequence)Enum)Path)TYPE_CHECKING	AnnotatedAnyLiteralTypeVarUnioncast)TyperCommand
TyperGroup)Volume__version__	constants)CLIError)get_sessionhf_raise_for_statusinstallation_methodloggingtabulate)load_dotenv   )OutputFormatWithAutoout#      HfApitokenreturnr    c                 &    SSK Jn  U" U S[        S9$ )Nr   r   zhuggingface-cli)r!   library_namelibrary_version)huggingface_hub.hf_apir    r   )r!   r    s     o/root/GenerationalWealth/GenerationalWealth/venv/lib/python3.13/site-packages/huggingface_hub/cli/_cli_utils.py
get_hf_apir(   =   s    ,u+<kZZ    z9https://huggingface.co/docs/huggingface_hub/en/guides/cliexamplesdocs_anchorc                 r    U(       a
  [          U 3O[         nSR                  S U  5       5      nSU SU S3$ )zGenerate an epilog with examples and a Learn More section.

Args:
    examples: List of example commands (without the `$ ` prefix).
    docs_anchor: Optional anchor for the docs URL (e.g., "#hf-download").

Returns:
    Formatted epilog string.

c              3   ,   #    U  H
  nS U 3v   M     g7f)z  $ N ).0exs     r'   	<genexpr>"generate_epilog.<locals>.<genexpr>T   s     <8RtB4[8s   z	Examples
zk

Learn more
  Use `hf <command> --help` for more information about a command.
  Read the documentation at )CLI_REFERENCE_URLjoin)r*   r+   docs_urlexamples_strs       r'   generate_epilogr8   I   sS     7B#$[M2GXH99<8<<L  &J ' r)   )mainhelpExpandPropertyT)boundepilogctx	formatterc                     U (       a:  UR                  5         U R                  S5       H  nUR                  U5        M     gg)z%Write the epilog without indentation.r-   N)write_paragraphsplit
write_text)r=   r>   r?   lines       r'   _format_epilog_no_indentrE   d   s7    !!#LL&D  & ' r)   z\s*\|\s*c                     ^  \ rS rSrSrS\R                  SS4U 4S jjrS\R                  S\\	   S\
4U 4S jjr\S	\R                  S\\	   SS4S
 j5       rS\R                  S\	S\R                  S-  4U 4S jjrS\\	\\	   4   4S jrS\R                  S\R$                  SS4S jrS\R                  S\R$                  SS4S jrS\R                  S\\	   4S jrSrU =r$ )HFCliTyperGroupo   a  
Typer Group that:
- lists commands alphabetically within sections.
- separates commands by topic (main, help, etc.).
- formats epilog without extra indentation.
- supports aliases via pipe-separated names (e.g. ``name="list | ls"``).
- consumes the global formatting flags (``--format``, ``--json``, ``-q`` / ``--quiet``)
  anywhere in the args of a leaf command and applies them to ``out``, so leaf
  commands don't need to declare these options themselves.
- rewrites ``spaces/user/repo`` to ``user/repo --type space`` for commands that accept ``--type``.
- enriches "No such option" / "No such command" errors with available options or commands.
r>   r"   Nc           	      D  >  [         T	U ]  U5      $ ! [        R                   Gax  nUR                  Gbd  UR                  R
                  GbL  UR                  R
                  n[        U[        R                  5      (       a  UR                  UR                  5       Vs/ s HG  nUR                  UR                  U5      =nc  M$  UR                  (       a  M7  XER                  SS94PMI     Os  snf nn[        USU5        e UR                  UR                  5       Vs/ s H]  n[        U[        R                  5      (       d  M$  UR                  (       a  M7  UR                  UR                  5      =n(       d  M[  UPM_     Os  snf nn[        USU5        e SnAff = f)aL  Enrich unknown-option errors with available options or subcommands.

Catches `NoSuchOption` raised during subcommand `make_context()`
(option parsing).  For leaf commands (e.g. `hf repos create --test`)
we list the command's options; for groups (e.g. `hf cache --test`)
we list subcommands since groups have no user-facing options.
NP   limitcommandsoptions)superinvokeclickNoSuchOptionr>   command
isinstanceGrouplist_commandsget_commandhiddenget_short_help_str_enrich_usage_error
get_paramsOptionget_help_record)
selfr>   ecmdnamesubitemsprecord	__class__s
            r'   rP   HFCliTyperGroup.invoke}   s`   	7>#&&!! 	uu QUU]]%>eemmc5;;// %($5$5aee$<$<D#&??155$#??C AUXU_U_ A55B5?@$<E 
 (:u= 	 "%!6!6A%a6 ?@xx WXWhWhijininWoMoVMo !6E 
 (9e<'	sK    FA8F#C.C.C.-3F #FF F>FFFargsc           	        > U(       a  US   R                  S5      (       d  US   OS nU(       a  U R                  X5      OS nUb  U R                  XB5         [        TU ]  X5      u  pVnUb*  [)        U[
        R*                  5      (       d  [-        Xg5        XVU4$ ! [
        R                   Ga<  nUGc2  UGb.  U R                  R                  5        V	V
Vs/ s H7  u  pU
R                  (       a  M  [        R                  U	5        H  nUPM     M9     Os  snn
n	f nn
n	n[        R                  " X<5      nU(       a>  SR                  S U 5       5      nUR                  R!                  S5       SU S3Ul        U R#                  U5       Vs/ s H<  nU R                  X5      =nc  M  UR                  (       a  M,  X_R%                  SS	94PM>     Os  snf nn['        US
U5        e S nAff = f)Nr   -, c              3   .   #    U  H  nS U S 3v   M     g7f)'Nr/   r0   ms     r'   r2   2HFCliTyperGroup.resolve_command.<locals>.<genexpr>   s     +Fgas!Hgs   .z. Did you mean ?rJ   rK   rM   )
startswithrW   _rewrite_repo_type_prefixrO   resolve_commandrQ   
UsageErrorrM   rc   rX   _ALIAS_SPLITrB   difflibget_close_matchesr5   messagerstriprV   rY   rZ   rT   rU   _consume_format_flags_for_leaf)r^   r>   rh   cmd_namer`   ra   resolved_cmdsub_argsr_   key
registeredaliasvisible_namesmatchessuggestionsrb   rc   rf   s                    r'   ru   HFCliTyperGroup.resolve_command   s   "47+=+=c+B+B4719ds-t?**35	+07+B3+M(D4 #J|U[[,Q,Q*<B8++9  	{x3 ,0==+>+>+@!+@%,,  ".!3!3C!8  "9 +@! ! "33HL"&))+Fg+F"FK#$99#3#3C#8"9UV WAI !% 2 23 7 7#//:: =PSPZPZ =T111;< 7 
 $Az59)	sC   B G,0&G'D
1#D
A:G'G*G=GG''G,r`   c                 J   [        S U R                   5       5      nU(       d  g[        5       nSnU R                   HJ  n[        U[        R
                  5      (       d  M$  UR                  S;   a  UR                  U5        US-  nML     U(       d  g[        5       nU R                   Hj  n[        U[        R                  5      (       d  M$  UR                  (       a  M7  / UR                  QUR                  Q7 H  nUR                  U5        M     Ml     Sn/ n	Sn
U
[        U5      :  ai  X   nUS:X  a  O^UR                  S5      (       a  SU;   d  X;  a  U
S-  n
O&U
S	-  n
O X;   a  U	R                  U
5        US-  nU
S-  n
U
[        U5      :  a  Mi  U	(       d  gSnSn/ nU	 H  nX   R                  S
S	5      n[        U5      S:w  d  US   [         R"                  ;  a  M?  US   n[         R"                  U   nUb#  UU:w  a  [        R$                  " SU SU S35      eUnUnUR                  UUS    S
US	    345        M     U(       d  g[        S U 5       5      (       a  [        R$                  " SU S35      eU H
  u  nnUX'   M     UR'                  SU/5        g)u$  Rewrite prefixed repo IDs (e.g. ``spaces/user/repo``) to ``user/repo --type space``.

Only applies to commands that have a ``--type`` / ``--repo-type`` option and
at least one repo-ID positional argument (any ``click.Argument`` whose name
ends with ``_id``, e.g. ``repo_id``, ``from_id``, ``to_id``).  When the
token that maps to such an argument matches ``{prefix}/org/repo`` (where
*prefix* is one of ``spaces``, ``datasets``, or ``models``), the prefix is
stripped and an implicit ``--type {type}`` is appended.  An error is raised
if ``--type`` is also provided explicitly or if multiple prefixed arguments
disagree on the repo type.

Only repo-ID positional slots are inspected so that other positional
arguments (filenames, local paths, patterns …) are never misinterpreted as
prefixed repo IDs.
c              3      #    U  H5  n[        U[        R                  5      =(       a    S UR                  ;   v   M7     g7f)--typeN)rT   rQ   r\   opts)r0   params     r'   r2   <HFCliTyperGroup._rewrite_repo_type_prefix.<locals>.<genexpr>   s/     qfp]bj=X(ejjBXXfps   =?Nr   )repo_idfrom_idto_idr   --rj   =   /   z!Conflicting repo type prefixes: 'z/' and 'z/'.c              3      #    U  HF  nUS :H  =(       d5    UR                  S5      =(       d    US:H  =(       d    UR                  S5      v   MH     g7f)r   z--type=--repo-typez--repo-type=Nrs   r0   args     r'   r2   r     sH      
 8Ors~~i8rC=<PrTWTbTbcqTrrs   AAz!Ambiguous repo type: got prefix 'z8/' in repo ID and explicit --type. Use one or the other.r   )anyparamssetrT   rQ   Argumentra   addr\   is_flagr   secondary_optslenrs   appendrB   r   REPO_TYPES_MAPPINGrv   extend)r`   rh   has_type_optionrepo_id_positionsarg_idxr   value_optionsoptpositional_countrepo_id_arg_indicesir   inferred_typefirst_prefixrewrites	arg_indexpartsprefixmapped_type	new_values                       r'   rt   )HFCliTyperGroup._rewrite_repo_type_prefix   s   " qfifpfpqq '*eZZE%00::!@@%))'21	   ! #&%ZZE%..u}}}?UZZ?%*>*>?C!%%c* @   )+#d)m'Cd{~~c""#:!9FAFA#8'..q1 A% Q #d)m # %)#'*,,IO))#q1E5zQ%()2N2N"N1XF#66v>K([M-I&&)J<.X`ag`hhk'lmm'M!LOOY58*AeAhZ(@AB -   

 
 
 ""3L>Ayz 
 %- Iy'DO %-X}-.r)   r}   c                    > [         TU ]  X5      nUb  U$ U R                  R                  5        H#  u  pE[        R                  U5      nX&;   d  M!  Us  $    g N)rO   rW   rM   rc   rw   rB   )r^   r>   r}   r`   registered_nameregistered_cmdaliasesrf   s          r'   rW   HFCliTyperGroup.get_command$  sZ    g!#0?J 04}}/B/B/D+O"((9G"%% 0E r)   c                 r    0 nU R                    H$  n[        R                  U5      nUS   nUSS X'   M&     U$ )zBBuild a mapping from primary command name to its aliases (if any).r   r   N)rM   rw   rB   )r^   resultr   r   primarys        r'   
_alias_mapHFCliTyperGroup._alias_map1  sB    ')#}}O &&7EAhG#ABiFO  - r)   r?   c                    0 nU R                  5       nU R                  U5       H  nU R                  X5      nUb  UR                  (       a  M*  UR	                  UR
                  S9nUR                  U/ 5      nU(       a  U SSR                  U5       S3n[        USS5      n	UR                  U	/ 5      R                  XW45        M     UR                  S5         UR                  US   5        S S S 5        [        UR                  5       5       HI  n	U	S:X  a  M  UR                  U	R                  5        S35         UR                  X9   5        S S S 5        MK     g ! , (       d  f       Nu= f! , (       d  f       Mn  = f)	NrK   z	 [alias: rk   ]topicr9   zMain commandsz	 commands)r   rV   rW   rX   rY   widthgetr5   getattr
setdefaultr   sectionwrite_dlsortedkeys
capitalize)
r^   r>   r?   topics	alias_mapra   r`   	help_textr   r   s
             r'   format_commandsHFCliTyperGroup.format_commands:  sI   "$OO%	&&s+D""3-C{cjj..Y__.EImmD"-G(k499W3E2FaH	C&1EeR(//0AB , /vf~. 0FKKM*E""e&6&6&8%9#CD""6=1 ED + 0/
 EDs   E>E0
E-0
E?	c                 h   / nU R                  U5       HT  nU R                  X5      nUb  UR                  (       a  M*  [        US/ 5      nU(       d  M@  UR	                  US   5        MV     U(       a  [        U5      n[        XqU5        g U R                  (       a  [        U R                  X5        g g )Nr*   r   )rV   rW   rX   r   r   r8   rE   r=   )r^   r>   r?   all_examplesra   r`   cmd_examplesr=   s           r'   format_epilogHFCliTyperGroup.format_epilogQ  s     #%&&s+D""3-C{cjj"3
B7L|##LO4 , $\2F$V)<[[$T[[#A r)   c                     / nU R                    H,  n[        R                  U5      S   nUR                  U5        M.     [	        U5      $ )Nr   )rM   rw   rB   r   r   )r^   r>   primary_namesra   r   s        r'   rV   HFCliTyperGroup.list_commandsc  sE    #%MMD"((.q1G  ) " m$$r)   r/   )__name__
__module____qualname____firstlineno____doc__rQ   ContextrP   liststrtupleru   staticmethodCommandrt   rW   dictr   HelpFormatterr   r   rV   __static_attributes____classcell__rf   s   @r'   rG   rG   o   s(   %-- D >%,5== %,S	 %,e %,N ^/u}} ^/DI ^/$ ^/ ^/@u}}  PT@T Dd3i0 25== 2U=P=P 2UY 2.B B5;N;N BSW B$% %49 % %r)   rG   ))z&--format [auto|human|agent|json|quiet]zWOutput format. Defaults to 'auto' which picks 'agent' or 'human' based on the terminal.)--jsonz+JSON output. Equivalent to '--format json'.)z-q, --quietz?Quiet output (one ID per line). Equivalent to '--format quiet'. _FORMATTING_OPTIONS_HELP_RECORDSc                     U R                  S5         U R                  [        5        S S S 5        g ! , (       d  f       g = f)NzFormatting options)r   r   r   )r?   s    r'   "_format_formatting_options_sectionr   v  s,    			/	0;< 
1	0	0s   1
?r`   c                     U R                    HY  n[        U[        R                  5      (       d  M$  / UR                  QUR
                  Q7nSU;   d  SU;   d  SU;   d  SU;   d  MY    g   g)a	  Return True if the command defines its own --format, --json or --quiet / -q.

Used to skip the global formatting flag pre-processor and the duplicated "Formatting options" help section for
legacy commands like 'hf jobs ps' that have their own format/quiet options.
--formatr   --quiet-qTF)r   rT   rQ   r\   r   r   )r`   r   r   s      r'   _has_local_formatting_optionr   {  sd     %..33e223T!1Y$5F$RV,  r)   rh   c                   ^ U R                   R                  S5      (       a  gSnSnSnU R                   H_  n[        U[        R
                  5      (       d  M$  / UR                  QUR                  Q7nSU;   a  SnSU;   d  SU;   a  SnSU;   d  M]  SnMa     U(       a  [        X(       + U(       + S	9  g[        R                  nSmS
[        SS4U4S jjnSn	U	[        U5      :  Ga  X   n
U
S:X  a  OU
S:X  aK  U" S5        U	S-   [        U5      :  a  [        R                  " S5      e[        XS-      5      nSmXU	S-   2	 Ml  U
R                  S5      (       a*  U" S5        [        U
[        S5      S 5      nSmXU	S-   2	 M  U
S:X  a#  U" S5        [        R                   nSmXU	S-   2	 M  U
S;   a#  U" U
5        [        R"                  nU
mXU	S-   2	 M  U	S-  n	U	[        U5      :  a  GM  [$        R&                  " U5        g)u  Apply global formatting flags from 'args' to a leaf command.

Two modes, depending on the command:

* **Pass-through commands** (ignore_unknown_options=True, e.g. 'hf extensions exec'):
  args are forwarded verbatim to an external binary; we don't touch them.

* **Legacy commands with a local --format option** (e.g. 'hf jobs ps' whose '--format' accepts Go templates):
  the global flags are rewritten in-place to the legacy form ('--json' → '--format json', '--quiet'/'-q' → '--format quiet'
  when the cmd has no own '--quiet') so click can parse them locally. This preserves backwards compatibility with the previous shorthand behavior.

* **Modern commands** (no local format/quiet/json options): the flags '--format <value>' / '--json' / '--quiet' / '-q' are stripped from 'args' and applied to the singleton 'out'.

Raises click.UsageError if multiple conflicting flags are supplied (e.g. '--json' together with '--format table').
ignore_unknown_optionsNFr   Tr   r   r   )rewrite_jsonrewrite_quietnew_flagr"   c                 F   > Tb  [         R                  " ST SU  S35      eg )Nrm   z' and 'z' are mutually exclusive.)rQ   rv   )r   chosen_flags    r'   _check_conflict7_consume_format_flags_for_leaf.<locals>._check_conflict  s1     """Q{m78*D]#^__ #r)   r   r   r   z#Option '--format' requires a value.r   	--format=)r   r   )context_settingsr   r   rT   rQ   r\   r   r   _rewrite_legacy_shorthandsr   autor   r   rv   _parse_format_valuers   jsonquietr   set_mode)r`   rh   has_local_formathas_local_quiethas_local_jsonr   r   chosen_moder   r   r   r   s              @r'   r|   r|     s      899ON%..33e223#"Ot!N  "46H\kXkl )=(A(AK"K`# `$ ` 	
A
c$i-g$;*J'1uD	!&&'LMM-dq5k:K$KQY>>+&&J'-c#k2B2D.EFK$KQY(?H%.33K"KQY##C .44KKQY	Q= c$i-@ LLr)   r   r   c                f   [        S U  5       5      nU(       a?  SU ;   a9  U(       a  [        R                  " S5      eU R                  S5      nSS/XUS-   & SnU(       aR  SU ;   a  SO	S	U ;   a  S	OS
nUb<  U(       a  [        R                  " SU S35      eU R                  U5      nSS/XUS-   & g
g
g
)zRewrite --json / -q / --quiet to --format ... for legacy commands.

Used for commands like 'hf jobs ps' that still own their '--format' option.
The rewrite lets users keep using the global shorthand while click parses
'--format <value>' locally.
c              3   Z   #    U  H!  oS :H  =(       d    UR                  S5      v   M#     g7f)r   r   Nr   r   s     r'   r2   -_rewrite_legacy_shorthands.<locals>.<genexpr>  s'     ^Y]RUJ.M#..2MMY]s   )+r   z/'--json' and '--format' are mutually exclusive.r   r  r   Tr   r   Nrm   z(' and '--format' are mutually exclusive.r  )r   rQ   rv   index)rh   r   r   has_format_in_argsidxflags         r'   r   r     s     ^Y]^^D(""#TUUjj")6237!t|tyD7H)d!&&4&0X'YZZ**T"C#-w"7DsQw	  r)   valuer   c                      [        U 5      $ ! [         a;    SR                  S [          5       5      n[        R                  " SU  SU S35      S ef = f)Nrk   c              3   8   #    U  H  oR                   v   M     g 7fr   r  rn   s     r'   r2   &_parse_format_value.<locals>.<genexpr>  s     @+?a''+?   zInvalid value for '--format': 'z'. Valid values: rq   )r   
ValueErrorr5   rQ   rv   )r  valids     r'   r   r     sa    m#E** m		@+?@@!@GXY^X__`abhllms
   
 AAerrorlabelrc   c                 *   U(       a!  U R                   b  SU S3U R                  ;   a  gU R                   R                  nSU SU S3/nU H  u  pVUR                  SUS S	U 35        M     UR                  S
U S35        [	        U [
        R                  5      (       aO  U R                  (       a>  UR                  SSR                  [        U R                  5      5       S35        / U l        U =R                  SR                  U5      -  sl        g)zHAppend a list of available options or commands to a usage error message.Nz
Available z forz

Available z for 'z':z  30s z
Run 'z --help' for full details.z
Did you mean: rk   rr   r-   )
r>   rz   command_pathr   rT   rQ   rR   possibilitiesr5   r   )r  r  rc   cmd_pathlinesra   r   s          r'   rZ   rZ     s    EII%:eWD)AU]])Ryy%%HeWF8*B78E r$s1YK01 !	LL78*$>?@%++,,1D1D'		&9L9L2M(N'OqQR 	MMTYYu%%Mr)   fallback_handlerextra_commands_providerc                 0   ^ ^  " UU 4S jS[         5      nU$ )zRReturn a Typer group class that runs a fallback handler before command resolution.c                      >^  \ rS rSrS\R
                  S\\   S\4U U4S jjr	S\R
                  S\R                  SS4U U4S jjrS	rU =r$ )
8fallback_typer_group_factory.<locals>.FallbackTyperGroupi  r>   rh   r"   c                    > T" U[        U R                  R                  5       5      5      nUb  [        U5      e[        TU ]  X5      $ r   )r   rM   r   
SystemExitrO   ru   )r^   r>   rh   fallback_exit_coderf   r   s       r'   ru   Hfallback_typer_group_factory.<locals>.FallbackTyperGroup.resolve_command  sD    !1$DMM<N<N<P8Q!R!- !3447*355r)   r?   Nc                    > [         TU ]  X5        Tb;  T" 5       nU(       a,  UR                  S5         UR                  U5        S S S 5        g g g ! , (       d  f       g = f)NzExtension commands)rO   r   r   r   )r^   r>   r?   entriesrf   r!  s       r'   r   Hfallback_typer_group_factory.<locals>.FallbackTyperGroup.format_commands  s[    G#C3&213"**+?@!**73 A@  3 A@s   A
Ar/   )r   r   r   r   rQ   r   r   r   r   ru   r   r   r   r   )rf   r!  r   s   @r'   FallbackTyperGroupr$    sT    	6u}} 	6DI 	6% 	6 	6	4u}} 	4ATAT 	4Y] 	4 	4r)   r,  )rG   )r   r!  r,  s   `` r'   fallback_typer_group_factoryr-    s    4 4_ 4 r)   r   c           
         S[         R                  S[         R                  S[         R                  SS 4S jnS[        S[         R                  S[         R                  SS 4S jnS[         R                  S[         R                  S[
        [           S[
        [           4S jn[        S	U R                  5        3[        4U U=(       d    / UUUS
.5      $ )Nr^   r>   r?   r"   c                 0    [        U R                  X5        g r   )rE   r=   r^   r>   r?   s      r'   r   #HFCliCommand.<locals>.format_epilog'  s     c=r)   c                     [         R                  " XU5        [        U 5      (       a  g U R                  R	                  S5      (       a  g [        U5        g )Nr   )r   format_optionsr   r   r   r   r0  s      r'   r3  $HFCliCommand.<locals>.format_options*  sE    ##Dy9 (--  $$%=>>*95r)   rh   c                    U(       do  UR                   (       d^  [        S U R                   5       5      (       a=  [        R                  " UR                  5       UR                  S9  UR                  5         [        R                  " XU5      $ )Nc              3   |   #    U  H2  n[        U[        R                  5      =(       a    UR                  v   M4     g 7fr   )rT   rQ   r   required)r0   rd   s     r'   r2   3HFCliCommand.<locals>.parse_args.<locals>.<genexpr>8  s'     UA:a0?QZZ?s   :<)color)
resilient_parsingr   r   rQ   echoget_helpr9  exitr   
parse_args)r^   r>   rh   s      r'   r>   HFCliCommand.<locals>.parse_args4  sX     C11UUUU

3<<>;
&&t$77r)   r   r   r*   r   r3  r>  )	rQ   r   r   r   r   r   r   typer   r@  s        r'   HFCliCommandrB  &  s    >EMM > >%J]J] >bf >6\ 6 6%J]J] 6bf 68 8U]] 8$s) 8PTUXPY 8 
u'')*+	 B*,$	

 
r)   c            "          ^  \ rS rSrSr SSSSSSSSSSSSSS.S	\S-  S
\S\\   S-  S\\\	4   S-  S\S-  S\S-  S\S-  S\S\
S\
S\
S\
S\S-  S\\S\	4   /\S\	4   4   4U 4S jjjjrSrU =r$ )HFCliAppiJ  z&Custom Typer app for Hugging Face CLI.Nr9   z	[OPTIONS]TF)r   r*   r   r:   r=   
short_helpoptions_metavaradd_help_optionno_args_is_helprX   
deprecatedrich_help_panelra   r   r*   r   r:   r=   rE  rF  rG  rH  rX   rI  rJ  r"   .c                   >^ ^^^^^^^^^	^
^^^ Tc  T(       a  [        T5      mS[        S[        4   S[        S[        4   4UU	UUUUUUUU
UUU UU4S jjnU$ )Nfunc.r"   c                 \   > [         [        T]  T	[        TT5      TTTTTTT
TTTS9" U 5      $ )N)clsr   r:   r=   rE  rF  rG  rH  rX   rI  rJ  )rO   rD  rS   rB  )rL  rf   rG  r   rI  r=   r*   r:   rX   ra   rH  rF  rJ  r^   rE  r   s    r'   _inner HFCliApp.command.<locals>._innerb  sQ    40 1!1% / / /% / 1   r)   )r8   r   r	   )r^   ra   r   r*   r   r:   r=   rE  rF  rG  rH  rX   rI  rJ  rO  rf   s   `````````````` r'   rS   HFCliApp.commandM  sM    $ >h$X.F	#s(+ 	c0B 	 	 	  r)   r/   r   )r   r   r   r   r   r   TOPIC_Tr   r   r	   boolr   rS   r   r   r   s   @r'   rD  rD  J  s   0  %  %)26!!%* $ % &*%Dj% 	%
 s)d"% sCx.4/% Dj% d
% $J% % % % % % t%  
8CH%&c(::	;!% %r)   rD  r:   rN  c                 B    Uc  [         n[        U USSUSSSSSSS/S.S9
$ )	a  Create a Typer app with consistent settings.

Args:
    help: Help text for the app.
    epilog: Optional epilog text (use `generate_epilog` to create one).
    cls: Optional Click group class to use (defaults to `HFCliTyperGroup`).

Returns:
    A configured Typer app.
NTFx   z-hz--help)max_content_widthhelp_option_names)
r:   r=   add_completionrH  rN  rich_markup_moderJ  pretty_exceptions_enablesuggest_commandsr   )rG   rD  )r:   r=   rN  s      r'   typer_factoryr\  u  sJ     {!&  "%"&!1
 r)   c                        \ rS rSrSrSrSrSrg)RepoTypei  modeldatasetspacer/   N)r   r   r   r   r_  r`  ra  r   r/   r)   r'   r^  r^    s    EGEr)   r^  zNThe ID of the repo (e.g. `username/repo-name` or `spaces/username/repo-name`).)r:   r   r   z2The type of repository (model, dataset, or space).zJA User Access Token generated from https://huggingface.co/settings/tokens.zfWhether to create a private repo if repo doesn't exist on the Hub. Ignored if the repo already exists.zDGit revision id which can be a branch name, a tag, or a commit hash.zLimit the number of results.z!Filter by author or organization.zHFilter by tags (e.g. 'text-classification'). Can be used multiple times.zSearch query.z-ez--envz/Set environment variables. E.g. --env ENV=valuez-sz	--secretszvSet secret environment variables. E.g. --secrets SECRET=value or `--secrets HF_TOKEN` to pass your Hugging Face token.z
--env-filez(Read in a file of environment variables.z/Read in a file of secret environment variables.c                  j    SSK Jn   [        R                  R	                  5       nU " 5       =nb  X!S'   U$ )zQReturn a copy of ``os.environ`` with the user's HF token injected (if available).r   )	get_tokenHF_TOKEN)huggingface_hubrc  osenvironcopy)rc  extended_environr!   s      r'   _get_extended_environrj    s1    )zz()',$r)   envenv_filec                     [        5       n0 nU(       a0  UR                  [        [        U5      R	                  5       US95        U =(       d    /  H  nUR                  [        XBS95        M     U$ )zParse ``-e``/``--env``/``-s``/``--secrets`` and ``--env-file``/``--secrets-file`` CLI args into a dict.

Uses an extended environment that includes the user's HF token so that
bare ``--secrets HF_TOKEN`` resolves correctly.
)rg  )rj  updater   r   	read_text)rk  rl  ri  env_map	env_values        r'   parse_env_maprr    s\     -.%'G{4>#;#;#=GWXYYBY	{9GH Nr)   rp  c                 ~    U (       d  gU R                  5        VVs/ s H  u  pX=(       d    SS.PM     snn$ s  snnf )z_Convert an env/secrets dict to the ``[{"key": ..., "value": ...}]`` format used by the Hub API.N )r   r  )rc   )rp  kvs      r'   env_map_to_key_value_listrw    s/    5<]]_E_TQAR(_EEEs   9z-vz--volumeaV  Mount one or more volumes. Format: hf://[TYPE/]SOURCE:/MOUNT_PATH[:ro]. TYPE is one of: models, datasets, spaces, buckets. TYPE defaults to models if omitted. models, datasets and spaces are always mounted read-only. buckets are read+write by default. E.g. -v hf://org/m:/data or -v hf://datasets/org/ds:/data or -v hf://buckets/org/b:/mnt:rozhf://bucket)modelsdatasetsspacesbucketsvolumeszlist[Volume] | Nonec                    U (       d  g/ nU  GHc  nUnSnUR                  S5      (       a  SnUSS nOUR                  S5      (       a  SnUSS nUR                  [        5      (       d  [        SU S35      eU[	        [        5      S nUR                  S	5      nUS
:X  a  [        SU S35      eUSU nX5S-   S nUR                  S5      nUS
:X  a  [        R                  n	Un
SnOkUSU nU[        ;   a  [        U   n	XhS-   S nO[        R                  n	UnUR                  SS5      n[	        U5      S:  a  US   S-   US   -   n
US   nOUn
SnUR                  [        U	U
UUUS95        GMf     U$ )a#  Parse volume specs from CLI arguments.

Format: hf://[TYPE/]SOURCE[/PATH]:/MOUNT_PATH[:ro|:rw]
Where TYPE is one of: models, datasets, spaces, buckets (defaults to models if omitted).
SOURCE is the repo/bucket identifier (e.g. 'username/my-model').
PATH is an optional subfolder inside the repo/bucket.
MOUNT_PATH starts with '/'.
Optional ':ro' or ':rw' suffix for read-only or read-write.

Examples:
    hf://my-org/my-model:/data                (model, implicit type)
    hf://models/my-org/my-model:/data         (model, explicit type)
    hf://datasets/my-org/my-dataset:/data:ro
    hf://buckets/my-org/my-bucket:/mnt
    hf://spaces/my-org/my-space:/app
    hf://datasets/org/ds/train:/data          (with path inside repo)
    hf://buckets/org/b/sub/dir:/mnt           (with path inside bucket)
Nz:roTz:rwFzInvalid volume format: 'zf'. Source must start with 'hf://'. Expected hf://[TYPE/]SOURCE:/MOUNT_PATH[:ro]. E.g. hf://org/m:/dataz:/zF'. Expected hf://[TYPE/]SOURCE:/MOUNT_PATH[:ro]. E.g. hf://org/m:/datar   r   r   r   r   )rA  source
mount_path	read_onlypath)endswithrs   
_HF_PREFIXr   r   findr   REPO_TYPE_MODEL_HF_VOLUME_TYPESrB   r   r   )r}  r   raw_specspecr  colon_slash_idxsource_partr  	slash_idxvol_type_strr  r  first_segment	remainingr   s                  r'   parse_volumesr  :  s   ( F	==I9D]]5!!I9D z***8* 5V W  C
O%& ))D/b *8*4z{  +O,A-/0
  $$S)	?$44L FD'
3M 00/>'A8	  )88'	
 OOC+E5zQqC%(2Qx"!%#	
s D Mr)   c                        \ rS rSrSrSrSrSrg)OutputFormati  z$Output format for CLI list commands.tabler  r/   N)r   r   r   r   r   r  r  r   r/   r)   r'   r  r    s    .EDr)   r  zOutput format (table or json).c                 2    [         R                  " U 5        U $ )a<  Callback for the legacy FormatWithAutoOpt option type.

Most commands now rely on the global --format / --json / -q flags consumed by _consume_format_flags_for_leaf instead
of declaring FormatWithAutoOpt themselves.  This callback is kept for the rare cases where a command still wires
FormatWithAutoOpt explicitly.
)r   r  r  s    r'   _set_output_moder    s     LLLr)   zOutput format.)r:   callbackr   r   zPrint only IDs (one per line).ra   c                 R    [         R                  " SSU 5      nUR                  5       $ )z\Convert a camelCase or PascalCase string to SCREAMING_SNAKE_CASE to be used as table header.z([a-z])([A-Z])z\1_\2)rerb   upper)ra   ss     r'   
_to_headerr    s!    
 (D1A779r)   c                    U (       d  g[        U [        5      (       a  U (       a  S$ S$ [        U [        R                  5      (       a  U R                  S5      $ [        U [        5      (       a!  [
        R                  " SU 5      (       a  U SS $ [        U [        5      (       a  SR                  S U  5       5      $ [        U [        5      (       a*  S	U ;   a  [	        U S	   5      $ [        R                  " U 5      $ [	        U 5      $ )
z/Convert a value to string for terminal display.rt  u   ✔z%Y-%m-%dz^\d{4}-\d{2}-\d{2}TN
   rk   c              3   8   #    U  H  n[        U5      v   M     g 7fr   )_format_value)r0   rv  s     r'   r2    _format_value.<locals>.<genexpr>  s     95aq))5r  ra   )rT   rS  datetimestrftimer   r  matchr   r5   r   r  dumpsr  s    r'   r  r    s    %u%2%%**++~~j))%"((+A5"I"ISbz%yy95999	E4	 	 U?uV}%%zz%  u:r)   max_lenc                 P    [        U 5      n[        U5      U:  a  USUS-
   S-   nU$ )z/Format a value + truncate it for table display.Nr   z...)r  r   )r  r  cells      r'   _format_cellr    s2    D
4y7Mgk"U*Kr)   headersrow_fn
alignmentsc           	         U (       d  [        S5        g[        [        [        [        [        [
        4         U  Vs/ s H
  oB" U5      PM     sn5      nU Vs/ s H  n[        U5      PM     nnU=(       d    0 R                  5        VV	s0 s H  u  p[        U5      U	_M     n
nn	[        [        XWU
S95        gs  snf s  snf s  sn	nf )aQ  Print items as a formatted table.

Args:
    items: Sequence of dictionaries representing the items to display.
    headers: List of column headers.
    row_fn: Function that takes an item dict and returns a list of string values for each column.
    alignments: Optional mapping of header name to "left" or "right". Defaults to "left".
zNo results found.N)r  r  )	printr   r   r   r   intr  rc   r   )rc   r  r  r  itemrowshscreaming_headersru  rv  screaming_alignmentss              r'   print_as_tabler    s     !"T%S/*+u-MutfTlu-MND0781A8:D:J9Q9Q9ST9SJqM1,9ST	(4?S
TU	 .N8Ts   B;
C Cformatr  id_keyc                   ^^	 U(       a  U  H  n[        Xs   5        M     gU[        R                  :X  a-  [        [        R                  " [	        U 5      S[
        S95        gTcV  U (       a  [	        U S   R                  5       5      OU/nU V	^	s/ s H!  m	[        U	4S jU  5       5      (       d  M  T	PM#     sn	mUc(  S[        [
        [        4   S[        [
           4U4S jjn[        U TXVS	9  gs  sn	f )
a,  Print list command output in the specified format.

Args:
    items: Sequence of dictionaries representing the items to display.
    format: Output format.
    quiet: If True, print only IDs (one per line).
    id_key: Key to use for extracting IDs in quiet mode.
    headers: Optional list of column names for headers. If not provided, auto-detected from keys.
    row_fn: Optional function to extract row values. If not provided, uses _format_cell on each column.
    alignments: Optional mapping of header name to "left" or "right". Defaults to "left".
Nr   )indentdefaultr   c              3   X   >#    U  H  n[        UR                  T5      5      v   M!     g 7fr   r  r   )r0   r  cols     r'   r2   $print_list_output.<locals>.<genexpr>  s$     4c]bUY\$((3-5P5P]bs   '*r  r"   c                 d   > T Vs/ s H  n[        U R                  U5      5      PM     sn$ s  snf r   r  )r  r  r  s     r'   r  !print_list_output.<locals>.row_fn  s(    ;BC7CL#/7CCCs   $-)r  r  r  )r  r  r  r  r   r   r   r   r   r	   r  )
rc   r  r  r  r  r  r  r  all_columnsr  s
       `    `r'   print_list_outputr    s    ( D$, """djjeQ<=/4d58==?+6("-d+34c]b4c1c3+d~	Dc3h 	DDI 	D 5'&P es   C22C2rv  c                 n   [        U [        R                  5      (       a  U R                  5       $ [        U [        5      (       a4  U R	                  5        VVs0 s H  u  pUc  M
  U[        U5      _M     snn$ [        U [        5      (       a  U  Vs/ s H  n[        U5      PM     sn$ U $ s  snnf s  snf )z4Recursively serialize a value to be JSON-compatible.)rT   r  	isoformatr   rc   _serialize_valuer   )rv  r   valr  s       r'   r  r    s    !X&&''{{}	At		;<779X9xs*%c**9XX	At		34514 &155H Y5s   	B,%B,B2infoc                     [         R                  " U 5      R                  5        VVs0 s H  u  pUc  M
  U[        U5      _M     snn$ s  snnf )z9Convert repo info dataclasses to json-serializable dicts.)dataclassesasdictrc   r  )r  ru  rv  s      r'   api_object_to_dictr  *  sC    /:/A/A$/G/M/M/Oa/OtqST"A""/Oaaas
   	A	A	valid_propertiesc                 J   ^  S[         S-  S[        [           S-  4U 4S jjnU$ )zJCreate a callback to parse and validate comma-separated expand properties.r  Nr"   c           	      2  > U c  g U R                  S5       Vs/ s H  oR                  5       PM     nnU H4  nUT;  d  M  [        R                  " SU SSR	                  T5       35      e   U Vs/ s H  n[        [        U5      PM     sn$ s  snf s  snf )N,zInvalid expand property: 'z'. Valid values are: rk   )rB   striptyperBadParameterr5   r   r;   )r  rd   
propertiespropr  s       r'   _parse_expand_properties?make_expand_properties_parser.<locals>._parse_expand_properties2  s    =).S)9:)9Aggi)9
:D++((06KDIIVfLgKhi  
 9CC
_d+
CC ; Ds   B2B)r   r   r;   )r  r  s   ` r'   make_expand_properties_parserr  /  s/    	Dd
 	DtO7Lt7S 	D $#r)   library)re  transformersc                 d     [        U 5        g! [         a    [        R                  SSS9   gf = f)ak  
Check whether a newer version of a library is available on PyPI.

If a newer version is found, print a hint pointing at `hf update`.

If current version is a pre-release (e.g. `1.0.0.rc1`), or a dev version (e.g. `1.0.0.dev1`), no check is performed.
If `HF_HUB_DISABLE_UPDATE_CHECK` is set, the check is skipped entirely.

This function is called at the entry point of the CLI. It only performs the check once every 24 hours, and any error
during the check is caught and logged, to avoid breaking the CLI.

Args:
    library: The library to check for updates. Currently supports "huggingface_hub" and "transformers".
z$Error while checking for CLI update.Texc_infoN)_check_cli_update	Exceptionloggerdebug)r  s    r'   check_cli_updater  C  s2    L'" L;dKLs    //c                 @  ^ [         R                  (       a  g [        R                  R	                  U 5      m[        U4S jS 5       5      (       a  g [        R                  R                  [         R                  5      (       aJ  [        R                  R                  [         R                  5      n[        R                  " 5       U-
  S:  a  g [        [         R                  5      R                  R                  SSS9  [        [         R                  5      R                  5         [!        U 5      nUb  TU:X  a  g U S:X  a  [#        5       nO
[%        5       nSU  SU S	T S
3nUb$  U S:X  a  US-  nO USSR'                  U5       3-  n[(        R*                  " U5        g )Nc              3   ,   >#    U  H	  oT;   v   M     g 7fr   r/   )r0   tagcurrent_versions     r'   r2   $_check_cli_update.<locals>.<genexpr>`  s     
;]c/!]s   )rcdeviQ T)parentsexist_okre  zA new version of z (z&) is available! You are using version rq   z
To update, run: hf updatez
To update, run: r  )r   HF_HUB_DISABLE_UPDATE_CHECK	importlibmetadataversionr   rf  r  existsCHECK_FOR_UPDATE_DONE_PATHgetmtimetimer   parentmkdirtouch_fetch_latest_pypi_version#_get_huggingface_hub_update_command _get_transformers_update_commandr5   r   hint)r  mtimelatest_versionupdate_commandrz   r  s        @r'   r  r  Y  sZ   ,,((009O 
;]
;;; 
ww~~i::;;  !E!EFIIK%9, 		-	-.55;;DSW;X	-	-.446 08NN!B##<>9;!'"^,<<bcrbsstuG!"88/0H/IJJHHWr)   c                      [        5       R                  SU  S3SS9n[        U5        UR                  5       S   S   $ ! [         a    [
        R                  SSS	9   g
f = f)zSFetch the latest version of a library from PyPI. Returns None if the request fails.zhttps://pypi.org/pypi/z/jsonr   )timeoutr  r  z.Error while fetching latest version from PyPI.Tr  N)r   r   r   r  r  r  r  )r  responses     r'   r  r    sk    =$$'=gYe%LVW$XH%}}v&y11 EPTUs   <? A A c                  ^    [        5       n U c  [        S5      e[        R                  " U 5      $ )zRun the install-method-appropriate update command for the `hf` CLI.

Raises CLIError if the installation method can't be determined.
Returns the subprocess exit code on success/failure of the update itself.
zeCannot determine how to update huggingface_hub (unknown installation method). Please update manually.)r  r   
subprocesscall)r`   s    r'   
run_updater    s2     .
/C
{s
 	
 ??3r)   c                      [        5       =S:X  a    / SQ$ =S:X  a  [        R                  S:X  a    / SQ$ =S:X  a    / SQ$ S:X  a  [        R                  SSS	S
S/$  g)zlReturn the command to update huggingface_hub as an argv list, or None if the installation method is unknown.brew)r  upgradehfhf_installernt)
powershell
-NoProfile-Commandz-iwr -useb https://hf.co/cli/install.ps1 | iex)bash-cz0curl -LsSf https://hf.co/cli/install.sh | bash -pip-minstall-Ure  Nr   rf  ra   sys
executabler/   r)   r'   r  r    sP    

,,rww$^llUUNND%DBSTTr)   c                      [        5       =S:X  a  [        R                  S:X  a    / SQ$ =S:X  a    / SQ$ S:X  a  [        R                  SSSSS	/$  g
)ziReturn the command to update transformers as an argv list, or None if the installation method is unknown.r	  r
  )r  r  r  z?iwr -useb https://hf.co/cli/install.ps1 | iex -WithTransformers)r  r  zHcurl -LsSf https://hf.co/cli/install.sh | bash -s -- --with-transformersr  r  r  r  r  Nr  r/   r)   r'   r  r    sL    

rww$^  mmNND%D.QQr)   r   )NN)idNNN)r   r  r  rx   importlib.metadatar  r  rf  r  r  r  r  collections.abcr   r   enumr   pathlibr   typingr   r   r	   r
   r   r   r   rQ   r  
typer.corer   r   re  r   r   r   huggingface_hub.errorsr   huggingface_hub.utilsr   r   r   r   r   huggingface_hub.utils._dotenvr   _outputr   r   
get_loggerr  _MAX_CELL_LENGTHREPO_LIST_DEFAULT_LIMITr&   r    r   r(   r4   r   r8   rR  r   r  FallbackHandlerTr;   r   r   rE   compilerw   rG   r   r   __annotations__r   r   rS  r   r|   r   r   rv   rZ   rA  r-  rB  TyperrD  r\  r^  r   	RepoIdArgr\   RepoTypeOptTokenOpt
PrivateOptRevisionOptLimitOpt	AuthorOpt	FilterOpt	SearchOptEnvOpt
SecretsOpt
EnvFileOptSecretsFileOptr   rj  rr  rw  
VolumesOptr  r  REPO_TYPE_DATASETREPO_TYPE_SPACEr  r  r  	FormatOptr  FormatWithAutoOptQuietOptr  r  r  r  r  objectr  r  r  r  r  r  r  r  r  r/   r)   r'   <module>r>     s   1      	 	  
  .   O O O   / : : +  6 . 
			    ,[cDj [G [ P d3i cDj C , .
!C
'T#YC13:=> +37'S4Z 'emm 'PUPcPc 'hl ' zz+&z%j z%z;  $uS#X"7 =%2E2E =$ =
emm  Q QT#Y Q4 Qh8T#Y 8 8VZ 8_c 82ms m'= m&u// & &DsTWxDY &^b &" KO&%b$uS#X*?&?@4G 
/0! !49t+; !tLGY !H(u{{ (V   S4Z  T*=MPT=T  `j  FsD  	NN]	 	LLA $J	LLY 4K	LLu
 $J	LLS 	LL457
 $J	LL9:<	
 I	LL`ac	
 $J	LLo&(	 
I	LL>
 I	LLH	

 $J	LL7
 $J	LL>tCH~  !	cT	Dj 
#sTz/$FtCtO'< Fd3PS8nAUX\A\ F I	LLe	
 
''++''	 Z49t+ Z0E Zz3  	LL-	0 5I  	LL&1ABD 
 	LLy'GHJS S   ( -=  c   )-	VDcN#V#YV d38n%tCy01V S#X%	V
 
V8  $;?(,&QDcN#&Q&Q &Q 	&Q
 #Y&Q d38n%tCy01D8&Q S#X%&Q 
&QR 6 bS bT#s(^ b
$H_4M $(Lg&GH LT L,%w'HI %d %P d
  C  T#Y-= $s)d*: r)   