
    {bj>\              %          S r SSKJrJr  SSKJr  SSK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JrJrJr  S	SKJr  S	SKJrJr  S	SKJrJr  S	SKJrJ r   \RB                  " \"5      r#\" SS9r$\$RK                  S/ SQS9    SS\\&\" SS94   S\\'\" SSS94   S\\S-  \" SSS94   S\\'\" SSS94   S\S S4S! jj5       r(S"\&S \'4S# jr)\$RK                  S$/ S%QS9      SS"\\&S-  \" S&S94   S'\\'\" S(S)S*S94   S+\\'\" S,S-S94   S.\\'\" S/S0S1S94   S2\S\S S4S3 jj5       r*S4\&S-  S2\&S-  S'\'S+\'S.\'S\&S-  S S4S5 jr+S6\\\-     S7\&S \\\-     4S8 jr,S"\&S'\'S+\'S.\'S\&S-  S S4S9 jr-\$RK                  S:S;S</S9 SS\\&\" S=S94   S\S S4S> jj5       r.\$RK                  S?/ S@QS9   SS\\&\" S=S94   SA\\'\" SBSCSDS94   SE\\'\" SFSGS94   S\S S4
SH jj5       r/\$RK                  SI/ SJQS9      SS"\\&\" SKS94   S.\\'\" S/S0SLS94   SA\\'\" SBSCSDS94   SM\\'\" SNSOS94   SP\\0\&   S-  \" SQS94   SR\\0\&   S-  \" SSS94   S\S S4ST jj5       r1\$RK                  SU/ SVQS9 SSW\\&\" SXS94   SY\\&\" SZS94   S\S S4S[ jj5       r2\$RK                  S\/ S]QS9   SS\\&\" S=S94   S\\'\" SS^S94   S_\\'\" S`SaS94   S\S S4
Sb jj5       r3\$RK                  Sc/ SdQS9               SSe\\&S-  \" SfS94   Sg\\&S-  \" ShS94   S?\\'\" SiS94   Sj\\'\" SkSlS94   Sm\\'\" SnSoS94   Sp\\&S-  \" SqS94   Sr\\&S-  \" SsS94   SM\\'\" SNStS94   SP\\0\&   S-  \" SuS94   SR\\0\&   S-  \" SvS94   Sw\\&S-  \" SxS94   Sy\\'\" SzS{S94   S|\\'\" S}S~S94   S\\'\" SSSS94   S\S S4 S jj5       r4\$RK                  S/ SQS9" \" S5      5        g)z7Contains commands to interact with buckets via the CLI.    )IterableIterator)	AnnotatedN)logging)BUCKET_PREFIX
BucketFileBucketFolderFilterMatcher_parse_bucket_uri   )REPO_REGIONS   )	SearchOptTokenOpt
get_hf_apityper_factory)make_cp)format_sizeprint_file_listing)ArgumentOption)OutputFormatoutz"Commands to interact with buckets.)helpcreate)zhf buckets create my-bucketz hf buckets create user/my-bucketz-hf buckets create hf://buckets/user/my-bucketz*hf buckets create user/my-bucket --privatez+hf buckets create user/my-bucket --exist-okz,hf buckets create user/my-bucket --region us)nameexamples	bucket_idzTBucket ID: bucket_name, namespace/bucket_name, or hf://buckets/namespace/bucket_nameprivatez	--privatezCreate a private bucket.regionz--regionzdCloud region in which to create the bucket. Can be one of 'us' or 'eu'. Requires Team plan or above.exist_okz
--exist-okz3Do not raise an error if the bucket already exists.tokenreturnc                    [        US9nU R                  [        5      (       aI  [        U 5      nUR                  (       a!  [
        R                  " SU  S[         S35      eUR                  n UR                  U U(       a  UOSUUS9n[        R                  " SUR                  R                  5       UR                  S9  g)	zCreate a new bucket.r"   z-Cannot specify a prefix for bucket creation: . Use namespace/bucket_name or namespace/bucket_name.N)r   r    r!   zBucket created)uriurl)r   
startswithr   r   path_in_repoclickBadParameteridcreate_bucketr   resultr(   to_urir)   )r   r   r    r!   r"   apiparsed
bucket_urls           ڗ/tmp/claude-0/-home-danvics-docker-quiz/c1e0577a-e42c-4a3d-b1ea-3edd61103a4e/scratchpad/stt/lib/python3.13/site-packages/huggingface_hub/cli/buckets.pyr   r   1   s    T 5
!CM**"9-$$?	{ K11>?UW  II	"""	 # J JJZ^^%:%:%<*..Q    argumentc                 r    U R                  [        5      (       a  U [        [        5      S nSU;   $ U nSU;   $ )zFCheck if argument is a bucket ID (namespace/name) vs just a namespace.N/)r*   r   len)r7   paths     r5   _is_bucket_idr<   o   sB    =))M*,- $; $;r6   z	list | ls)
zhf buckets listzhf buckets list huggingfacez$hf buckets list --search "my-prefix"zhf buckets list user/my-bucketz!hf buckets list user/my-bucket -Rz!hf buckets list user/my-bucket -hz%hf buckets list user/my-bucket --treez(hf buckets list user/my-bucket --tree -hz+hf buckets list hf://buckets/user/my-bucketz%hf buckets list user/my-bucket/sub -RzyNamespace (user or org) to list buckets, or bucket ID (namespace/bucket_name(/prefix) or hf://buckets/...) to list files.human_readablez--human-readablez-hz$Show sizes in human readable format.as_treez--treez3List files in tree format (only for listing files).	recursivez--recursivez-Rz0List files recursively (only for listing files).searchc           	          U SL=(       a    [        U 5      nU(       a'  Ub  [        R                  " S5      e[        U UUUUS9  g[	        U UUUUUS9  g)zList buckets or files in a bucket.

When called with no argument or a namespace, lists buckets.
When called with a bucket ID (namespace/bucket_name), lists files in the bucket.
Nz'Cannot use --search when listing files.)r7   r=   r>   r?   r"   )	namespacer@   r=   r>   r?   r"   )r<   r,   r-   _list_files_list_buckets)r7   r=   r>   r?   r@   r"   is_file_modes          r5   list_cmdrF   x   sg    r 4'CM(,CL$$%NOO)	
 	)	
r6   rB   c           	      *   U(       a  [         R                  " S5      eU(       a  [         R                  " S5      eU b=  U R                  [        5      (       a#  U [	        [        5      S n U R                  S5      n [        US9nUR                  XS9 Vs/ s HZ  nUR                  UR                  U(       a  [        UR                  U5      OUR                  UR                  UR                  S.PM\     nn[        R                  " USS	0S
9  gs  snf )zList buckets in a namespace.z'Cannot use --tree when listing buckets.z,Cannot use --recursive when listing buckets.Nr9   r%   )rB   r@   )r.   r   sizetotal_files
created_atrH   right)
alignments)r,   r-   r*   r   r:   rstripr   list_bucketsr.   r   r   rH   rI   rJ   r   table)	rB   r@   r=   r>   r?   r"   r2   bucketitemss	            r5   rD   rD      s       !JKK  !OPP !5!5m!D!Dc-023	$$S)	
5
!C &&&J	 KF ))~~@NK^<TZT_T_!-- ++	
 K 
 	 IIe 12	s   A!DrQ   prefixc              #      #    UR                  S5      nU  HC  nU(       a5  UR                  U:X  d%  UR                  R                  U S35      (       d  M?  Uv   ME     g7f)zDrop entries that are not `prefix` itself or below it.

The server matches `prefix` lexically, so listing "logs" also returns "logs.json" or "logs_backup/...".
Filesystem semantics require path components => keep only what's actually under the prefix.
r9   N)rM   r;   r*   )rQ   rR   items      r5   _iter_under_prefixrU      sL      ]]3Ff,		0D0Dxq\0R0RJ s   AA	Ac           
      T   U(       a8  [         R                  [        R                  :X  a  [        R
                  " S5      e[        US9n[        U 5      n[        [        UR                  UR                  UR                  =(       d    SUS9UR                  5      5      n[        XqX#S9  g)zList files in a bucket.z%Cannot use --tree with --format json.r%   NrR   r?   )r=   r>   r?   )r   moder   jsonr,   r-   r   r   listrU   list_bucket_treer.   r+   r   )r7   r=   r>   r?   r"   r2   r3   rQ   s           r5   rC   rC      s     388|000  !HII
5
!Cx(F  		**2d# ! 
 	
	E uWbr6   infozhf buckets info user/my-bucketz+hf buckets info hf://buckets/user/my-bucketzFBucket ID: namespace/bucket_name or hf://buckets/namespace/bucket_namec                     [        US9n[        U 5      nUR                  UR                  5      n[        R
                  " USS9  g)zGet info about a bucket.r%   r.   )id_keyN)r   r   bucket_infor.   r   dict)r   r"   r2   r3   rP   s        r5   r\   r\     s8    " 5
!Cy)F__VYY'FHHVD!r6   delete)z hf buckets delete user/my-bucketz-hf buckets delete hf://buckets/user/my-bucketz&hf buckets delete user/my-bucket --yesz-hf buckets delete user/my-bucket --missing-okyesz--yesz-yzSkip confirmation prompt.
missing_okz--missing-okz3Do not raise an error if the bucket does not exist.c                    U R                  [        5      (       aJ  [        U 5      nUR                  (       a!  [        R
                  " SU  S[         S35      eUR                  n O'SU ;  a!  [        R
                  " SU  S[         S35      e[        R                  " SU  S3US	9  [        US
9nUR                  XS9  [        R                  " SU S9  g)zwDelete a bucket.

This deletes the entire bucket and all its contents. Use `hf buckets rm` to remove individual files.
z-Cannot specify a prefix for bucket deletion: r&   r'   r9   Invalid bucket ID: -. Must be in format namespace/bucket_name or z(Are you sure you want to delete bucket ''?rb   r%   )rc   zBucket deleted)r   N)r*   r   r   r+   r,   r-   r.   r   confirmr   delete_bucketr0   )r   rb   rc   r"   r3   r2   s         r5   ra   ra   )  s    J M**"9-$$?	{ K11>?UW  II		I	  !) -;;H/I_a
 	

 KK:9+RHcR
5
!Ci7JJ95r6   zremove | rm)z)hf buckets remove user/my-bucket/file.txtz2hf buckets rm hf://buckets/user/my-bucket/file.txtz.hf buckets rm user/my-bucket/logs/ --recursivez:hf buckets rm user/my-bucket --recursive --include "*.tmp"z8hf buckets rm user/my-bucket/data/ --recursive --dry-runzBucket path: namespace/bucket_name/path or hf://buckets/namespace/bucket_name/path. With --recursive, namespace/bucket_name is also accepted to target all files.z0Remove files recursively under the given prefix.dry_runz	--dry-runz8Preview what would be deleted without actually deleting.includezQInclude only files matching pattern (can specify multiple). Requires --recursive.excludezLExclude files matching pattern (can specify multiple). Requires --recursive.c                   ^ [        U 5      nUR                  mUR                  nUS:X  a$  U(       d  [        R                  " ST ST S35      eU(       d  U(       a  U(       d  [        R                  " S5      e[        US9n	U(       Ga8  [        R                  " S5      n
/ n[        U	R                  TU=(       d    SS	S
9U5       HI  n[        U[        5      (       d  M  UR                  U5        U
R                  S[        U5       S35        MK     U
R                  S[        U5       S35        U(       d  U(       a=  [!        XES9nU Vs/ s H&  oR#                  UR$                  5      (       d  M$  UPM(     nnOUnU Vs/ s H  oR$                  PM     nn['        S U 5       5      n[)        US	S9nU(       d  [        R*                  " S5        g[        U5       SU 3nU(       dO  U(       dH  [        R*                  " SR-                  S U 5       5      5        [        R.                  " SU ST S3SS9  U(       aJ  [        R*                  " SR-                  U4S jU 5       5      5        [        R*                  " SU S35        gU	R1                  TUS9  [        R2                  " SU ST S3T[        U5      US9  gUnU(       d  [        R                  " S 5      eU(       a9  [        R*                  " S![4         T S"U 35        [        R*                  " S#5        g[        R.                  " S$U S%T S3US9  U	R1                  TU/S9  [        R2                  " S&UTS'9  gs  snf s  snf )(zZRemove files from a bucket.

To delete an entire bucket, use `hf buckets delete` instead.
 z?No file path specified. To remove files, provide a path (e.g. 'zd/FILE') or use --recursive to remove all files. To delete the entire bucket, use `hf buckets delete z`.z,--include and --exclude require --recursive.r%   zListing files from remoteNTrW   zListing files from remote (z files))include_patternsexclude_patternsc              3   8   #    U  H  oR                   v   M     g 7fN)rH   ).0fs     r5   	<genexpr>remove.<locals>.<genexpr>  s     7As   )r=   zNo files to remove.z file(s) totaling 
c              3   ,   #    U  H
  nS U 3v   M     g7f)z  N )rt   r;   s     r5   rv   rw     s     BztD6{zs   zRemove z from 'rg   Frh   c              3   @   >#    U  H  nS [          T SU 3v   M     g7f)delete: r9   N)r   )rt   r;   r   s     r5   rv   rw     s%     cXbPT-1TFKXbs   z
(dry run) z would be removed.)ra   zRemoved ')r   files_deletedrH   zFile path cannot be empty.r|   r9   z"(dry run) 1 file would be removed.zRemove 'z' from 'zFile removed)r;   r   )r   r.   r+   r,   r-   r   r   statusrU   r[   
isinstancer   appendupdater:   doner
   matchesr;   sumr   textjoinri   batch_bucket_filesr0   r   )r7   r?   rb   rk   rl   rm   r"   r3   rR   r2   r   	all_filesrT   matcherru   matched_files
file_paths
total_sizesize_strcount_label	file_pathr   s                        @r5   remover   c  s   z x(F		I  F|I   k "DDM;bR
 	
 	7I  !OPP
5
!C78&(	&  ~ ! 
 
D $
++  & ;C	N;K7ST
 	1#i.1AIJg#WWG(1M	1__QVV5LQ	MMM%M&34mffm
4777
z$?HH*+Z));H:F7HHTYYBzBBCKK'+gi[COHHTYYcXbccdHHz+.@ABy<

{m79+Q7j/		
 	$$%ABBHHxyk9+FGHH9:hyk)B?SIy)=

>	YGY N 5s   #M&4M&M+move)z/hf buckets move user/old-bucket user/new-bucketz/hf buckets move user/my-bucket my-org/my-bucketzIhf buckets move hf://buckets/user/old-bucket hf://buckets/user/new-bucketfrom_idzMSource bucket ID: namespace/bucket_name or hf://buckets/namespace/bucket_nameto_idzRDestination bucket ID: namespace/bucket_name or hf://buckets/namespace/bucket_namec                    [        U 5      nUR                  (       a!  [        R                  " SU  S[         S35      e[        U5      nUR                  (       a!  [        R                  " SU S[         S35      e[        US9nUR                  UR                  UR                  S9  [        R                  " SUR                  UR                  S9  g)z2Move (rename) a bucket to a new name or namespace.z)Cannot specify a prefix for bucket move: r&   r'   r%   )r   r   zBucket movedN)
r   r+   r,   r-   r   r   move_bucketr.   r   r0   )r   r   r"   parsed_from	parsed_tor2   s         r5   r   r     s    2 $G,K  7y A--:O;QS
 	
 "%(I  7w ?--:O;QS
 	

 5
!COOKNN),,O?JJ~{~~Y\\Jr6   settings)z,hf buckets settings user/my-bucket --privatez+hf buckets settings user/my-bucket --publicz9hf buckets settings hf://buckets/user/my-bucket --privatezMake the bucket private.publicz--publiczMake the bucket public.c                    X:X  a  [         R                  " S5      eU R                  [        5      (       aJ  [	        U 5      nUR
                  (       a!  [         R                  " SU  S[         S35      eUR                  n O'SU ;  a!  [         R                  " SU  S[         S35      e[        US9nUR                  XS	9  [        R                  " S
XS9  [        R                  " SU  S35        g)z$Update bucket settings (visibility).z-Specify exactly one of --private or --public.z-Cannot specify a prefix for bucket settings: r&   r'   r9   re   rf   r%   )r   zBucket settings updated)r   r   zRun `hf buckets info z` to view bucket details.N)r,   r-   r*   r   r   r+   r.   r   update_bucket_settingsr   r0   hint)r   r   r   r"   r3   r2   s         r5   r   r     s    @   !PQQM**"9-$$?	{ K11>?UW  II		I	  !) -;;H/I_a
 	

 5
!Cy:JJ(IOHH$YK/HIJr6   sync)z2hf buckets sync ./data hf://buckets/user/my-bucketz2hf buckets sync hf://buckets/user/my-bucket ./dataz;hf buckets sync ./data hf://buckets/user/my-bucket --deletez^hf buckets sync hf://buckets/user/my-bucket ./data --include "*.safetensors" --exclude "*.tmp"zIhf buckets sync ./data hf://buckets/user/my-bucket --plan sync-plan.jsonlz'hf buckets sync --apply sync-plan.jsonlz<hf buckets sync ./data hf://buckets/user/my-bucket --dry-runzChf buckets sync ./data hf://buckets/user/my-bucket --dry-run | jq .sourcezKSource path: local directory or hf://buckets/namespace/bucket_name(/prefix)destzPDestination path: local directory or hf://buckets/namespace/bucket_name(/prefix)z/Delete destination files not present in source.ignore_timesz--ignore-timesz;Skip files only based on size, ignoring modification times.ignore_sizesz--ignore-sizesz<Skip files only based on modification times, ignoring sizes.planz=Save sync plan to JSONL file for review instead of executing.applyz#Apply a previously saved plan file.z5Print sync plan to stdout as JSONL without executing.z6Include files matching pattern (can specify multiple).z6Exclude files matching pattern (can specify multiple).filter_fromz(Read include/exclude patterns from file.existingz
--existingzASkip creating new files on receiver (only update existing files).ignore_existingz--ignore-existingzCSkip updating files that exist on receiver (only create new files).verbosez	--verbosez-vz%Show detailed logging with reasoning.c                     [        US9nUR                  U UUUUUUUU	U
UUUU[        R                  " 5       S9  U(       a6  [        R                  " 5       (       d  [        R                  " SU S35        ggg)z0Sync files between local directory and a bucket.r%   )r   r   ra   r   r   r   r   rl   rm   r   r   r   rk   r   quietzRun `hf buckets sync --apply z` to execute this plan.N)r   sync_bucketr   is_quietr   )r   r   ra   r   r   r   r   rk   rl   rm   r   r   r   r   r"   r2   s                   r5   r   r   [  s    X 5
!COO!!'lln  " CLLNN06MNO #tr6   cp)zEhf buckets cp hf://buckets/username/my-bucket/config.json config.jsonz<hf buckets cp hf://buckets/username/my-bucket/data.csv data/z;hf buckets cp hf://buckets/username/my-bucket/config.json -zQhf buckets cp model.safetensors hf://buckets/username/my-bucket/model.safetensorsz?hf buckets cp config.json hf://buckets/username/my-bucket/logs/z;hf buckets cp - hf://buckets/username/my-bucket/config.jsonzYhf buckets cp hf://buckets/username/my-bucket/data.csv hf://buckets/username/dest-bucket/z_hf buckets cp hf://buckets/username/source-bucket/logs/ hf://buckets/username/dest-bucket/logs/buckets)FNFN)NFFFNNrs   )FFN)FFFNNN)NNFFFNNFNNNFFFN)5__doc__collections.abcr   r   typingr   r,   huggingface_hubr   huggingface_hub._bucketsr   r   r	   r
   r   hf_apir   
_cli_utilsr   r   r   r   _cpr   _file_listingr   r   
_frameworkr   r   _outputr   r   
get_logger__name__loggerbuckets_clicommandstrboolr   r<   rF   rD   rU   rC   r\   ra   rZ   r   r   r   r   rz   r6   r5   <module>r      s
   > .   #  "   : ( & 
		H	% !EF 	  
0 	 	 	90Rg	
	0R +	
	0R tw	
	0R* F	
	+0R8 90R: 
;0R
0RfC D  	  0 	 	 	 	E>
d
W	
	>
 7	
	>
$ F	
	%>
2 C	
	3>
B C>
D E>
F 
G>
>
B 3Tz 3$J 3  3 	 3
  3 : 3 
 3F	hzL'@A 	3 	S[\fiu\uSv 	ccc c 	c
 :c 
c6 	(5   "Y	
	" " 
""  	  . 	 	-.6Y	
	.6 
,	
	
.6 F	
	.6, -.6. 
/.6.6b 	  	6 	 	 	 	 	[BHa	
	BH C	
	BH$ 
,	
	
%BH4 K	
	5BHB S	Dd	
	CBHN S	D_	
	OBHZ [BH\ 
]BH	BHJ 	  * "K`	
	"K e	
	"K "K 
"K"KJ 	  * 	 	+,KY	
	,K +	
	,K *	
	,K* +,K, 
-,K,Kh 		  & 	 	 	 	 	 	 	 	 	 	 	 	 	 	yrPd
^	
	rP d
c	
	rP B	
	rP& N	
	'rP4 O	
	5rPB d
P	
	CrPN d
6	
	OrPZ H	
	[rPh S	DI	
	irPt S	DI	
	urP@ d
;	
	ArPL T	
	MrPZ V	
	[rPh 8	
	irPx yrPz 
{rPrPv   	   
)r6   