
    5pjFR              %          S 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
  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  \R:                  " \5      r\" SS9r \ RC                  S/ SQS9    S|S\\"\" 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%\ RC                  S#/ S$QS9      S}S!\\"S-  \" S%S94   S&\\#\" S'S(S)S94   S*\\#\" S+S,S94   S-\\#\" S.S/S0S94   S1\S\SS4S2 jj5       r&S3\"S-  S1\"S-  S&\#S*\#S-\#S\"S-  SS4S4 jr'S!\"S&\#S*\#S-\#S\"S-  SS4S5 jr(\ RC                  S6S7S8/S9 S~S\\"\" S9S94   S\SS4S: jj5       r)\ RC                  S;/ S<QS9   SS\\"\" S9S94   S=\\#\" S>S?S@S94   SA\\#\" SBSCS94   S\SS4
SD jj5       r*\ RC                  SE/ SFQS9      SS!\\"\" SGS94   S-\\#\" S.S/SHS94   S=\\#\" S>S?S@S94   SI\\#\" SJSKS94   SL\\+\"   S-  \" SMS94   SN\\+\"   S-  \" SOS94   S\SS4SP jj5       r,\ RC                  SQ/ SRQS9 S~SS\\"\" STS94   SU\\"\" SVS94   S\SS4SW jj5       r-\ RC                  SX/ SYQS9               SSZ\\"S-  \" S[S94   S\\\"S-  \" S]S94   S;\\#\" S^S94   S_\\#\" S`SaS94   Sb\\#\" ScSdS94   Se\\"S-  \" SfS94   Sg\\"S-  \" ShS94   SI\\#\" SJSiS94   SL\\+\"   S-  \" SjS94   SN\\+\"   S-  \" SkS94   Sl\\"S-  \" SmS94   Sn\\#\" SoSpS94   Sq\\#\" SrSsS94   St\\#\" SuSvSwS94   S\SS4 Sx jj5       r.\ RC                  Sy/ SzQS9" \" S{5      5        g)z7Contains commands to interact with buckets via the CLI.    )	AnnotatedN)logging)BUCKET_PREFIX
BucketFile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           W/var/www/html/pdf-tiff/venv/lib/python3.13/site-packages/huggingface_hub/cli/buckets.pyr   r   /   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)r4   paths     r2   _is_bucket_idr9   m   sB    =))M*,- $; $;r3   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.)r4   r:   r;   r<   r   )	namespacer=   r:   r;   r<   r   )r9   r)   r*   _list_files_list_buckets)r4   r:   r;   r<   r=   r   is_file_modes          r2   list_cmdrC   v   sg    r 4'CM(,CL$$%NOO)	
 	)	
r3   r?   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.Nr6   r"   )r?   r=   )r+   r   sizetotal_files
created_atrE   right)
alignments)r)   r*   r'   r   r7   rstripr   list_bucketsr+   r   r   rE   rF   rG   r   table)	r?   r=   r:   r;   r<   r   r/   bucketitemss	            r2   rA   rA      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c                 ,   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5      n[        XqX#S9  g)zList files in a bucket.z%Cannot use --tree with --format json.r"   Nprefixr<   )r:   r;   r<   )r   moder   jsonr)   r*   r   r   listlist_bucket_treer+   r(   r   )r4   r:   r;   r<   r   r/   r0   rN   s           r2   r@   r@      s     388|000  !HII
5
!Cx(FII&&.$ 	 	
E uWbr3   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   r/   r0   rM   s        r2   rV   rV     s8    " 5
!Cy)F__VYY'FHHVD!r3   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$   r6   zInvalid bucket ID: z-. Must be in format namespace/bucket_name or z(Are you sure you want to delete bucket ''?r\   r"   )r]   zBucket deleted)r   N)r'   r   r   r(   r)   r*   r+   r   confirmr   delete_bucketr-   )r   r\   r]   r   r0   r/   s         r2   r[   r[     s    J M**"9-$$?	{ K11>?UW  II		I	  !) -;;H/I_a
 	

 KK:9+RHcR
5
!Ci7JJ95r3   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a.  [        R                  " S5      n
/ nU	R                  TU=(       d    SS	S
9 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	R/                  TUS9  [        R0                  " 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![2         T S"U 35        [        R(                  " S#5        g[        R,                  " S$U S%T S3US9  U	R/                  TU/S9  [        R0                  " 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 remoteNTrP   zListing files from remote (z files))include_patternsexclude_patternsc              3   8   #    U  H  oR                   v   M     g 7fN)rE   ).0fs     r2   	<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 )rl   r8   s     r2   rn   ro     s     BztD6{zs   zRemove z from 'r_   Fr`   c              3   @   >#    U  H  nS [          T SU 3v   M     g7f)delete: r6   N)r   )rl   r8   r   s     r2   rn   ro     s%     cXbPT-1TFKXbs   z
(dry run) z would be removed.)r[   zRemoved ')r   files_deletedrE   zFile path cannot be empty.rt   r6   z"(dry run) 1 file would be removed.zRemove 'z' from 'zFile removed)r8   r   )r   r+   r(   r)   r*   r   r   statusrU   
isinstancer   appendupdater7   doner   matchesr8   sumr   textjoinra   batch_bucket_filesr-   r   )r4   r<   r\   rc   rd   re   r   r0   rQ   r/   rw   	all_filesitemmatcherrm   matched_files
file_paths
total_sizesize_strcount_label	file_pathr   s                        @r2   remover   R  s   z x(F		I  F|I   k "DDM;bR
 	
 	7I  !OPP
5
!C78&(	((>T ) 
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*M9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   r-   )r   r   r   parsed_from	parsed_tor/   s         r2   r   r     s    2 $G,K  7y A--:O;QS
 	
 "%(I  7w ?--:O;QS
 	

 5
!COOKNN),,O?JJ~{~~Y\\Jr3   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   r[   r   r   r   r   rd   re   r   r   r   rc   r   quietzRun `hf buckets sync --apply z` to execute this plan.N)r   sync_bucketr   is_quiethint)r   r   r[   r   r   r   r   rc   rd   re   r   r   r   r   r   r/   s                   r2   r   r     s    X 5
!COO!!'lln  " CLLNN06MNO #tr3   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)NFFFNNrk   )FFN)FFFNNN)NNFFFNNFNNNFFFN)/__doc__typingr   r)   huggingface_hubr   huggingface_hub._bucketsr   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   r9   rC   rA   r@   rV   r[   rT   r   r   r   rr   r3   r2   <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ccc c 	c
 :c 
c0 	(5   "Y	
	" " 
""  	  . 	 	-.6Y	
	.6 
,	
	
.6 F	
	.6, -.6. 
/.6.6b 	  	6 	 	 	 	 	[Ha	
	H C	
	H$ 
,	
	
%H4 K	
	5HB S	Dd	
	CHN S	D_	
	OHZ [H\ 
]H	HD 	  * "K`	
	"K e	
	"K "K 
"K"KT 		  & 	 	 	 	 	 	 	 	 	 	 	 	 	 	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   	   
)r3   