wL i|BBdZddlZddlZddlZddlZddlmZddlmZddl m Z ddl m Z ddl mZmZmZmZmZmZmZmZddlmZdd lmZd d lmZmZmZmZmZm Z m!Z!m"Z"d d l#m$Z$d d l%m&Z&m'Z'd dl(m)Z)erd dl*m+Z+e jXe-Z.ej^dZ0dZ1dddZ2eGddZ3e" d;dee3dee4de4de4dee4dee4deee4e4fdeee4deee5ee5ee4ffdZ6Gd d!eZ7Gd"d#eZ8 dd.e4ddf d2Z?d0ed3e3d1e>dee4fd4Z@d5eed6e4de8fd7ZAd$d%d8ee4d1e>deefd9ZBd$d%d8ee4d1e>deefd:ZCy)=z.Git LFS related type definitions and utilitiesN) dataclass)ceil)getsize)Path) TYPE_CHECKINGBinaryIODictIterableListOptionalTuple TypedDict)unquote) constants)build_hf_headersfix_hf_endpoint_in_url get_sessionhf_raise_for_status http_backoffloggingtqdmvalidate_hf_hub_args) SliceFileObj)sha256 sha_fileobj)is_tqdm_disabled)CommitOperationAddz^[0-9a-f]{40}$zlfs-multipart-uploadzapplication/vnd.git-lfs+json)Acceptz Content-TypecreZdZUdZeed<eed<eed<edefdZ edefdZ ed e fd Z y ) UploadInfoad Dataclass holding required information to determine whether a blob should be uploaded to the hub using the LFS protocol or the regular protocol Args: sha256 (`bytes`): SHA256 hash of the blob size (`int`): Size in bytes of the blob sample (`bytes`): First 512 bytes of the blob rsizesamplepathct|}tj|d5}|jddd}t |}ddd||S#1swYxYw)Nrbr"rr#)rioopenpeekr)clsr$r"filer#shas Y/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/huggingface_hub/lfs.py from_pathzUploadInfo.from_pathOs_t} WWT4  $DYYs^DS)Fd#C $S88 $ $s AAdatacbt|j}|t||dd|S)Nr')r"r#r)rdigestlen)r,r1r.s r/ from_byteszUploadInfo.from_bytesWs-Tl!!#D $t*SAAfileobjc|jd}|jdtjt |}|j }|jdtj||||S)Nr'rr()readseekr)SEEK_SETrtell)r,r7r#r.r"s r/ from_fileobjzUploadInfo.from_fileobj\sXc" Q $'"||~ Q $S88r6N) __name__ __module__ __qualname____doc__bytes__annotations__int classmethodstrr0r5rr=r6r/r!r!<sj  M I M9S99BeBB9899r6r! upload_infostoken repo_typerepo_idrevisionendpointheaders transfersreturnc||ntj}d}|tjvrtj|}|d||d} d||nddg|D cgc])} | jj | j d+c} d d } |d t |i| d <itt| |xsi}tj| || } t| | j} | jdd}t|ts t!d| jd}t|t"r|nd}|Dcgc]}d|vst%|c}|Dcgc]}d|vst'|c}|fScc} wcc}wcc}w)a Requests the LFS batch endpoint to retrieve upload instructions Learn more: https://github.com/git-lfs/git-lfs/blob/main/docs/api/batch.md Args: upload_infos (`Iterable` of `UploadInfo`): `UploadInfo` for the files that are being uploaded, typically obtained from `CommitOperationAdd.upload_info` repo_type (`str`): Type of the repo to upload to: `"model"`, `"dataset"` or `"space"`. repo_id (`str`): A namespace (user or an organization) and a repo name separated by a `/`. revision (`str`, *optional*): The git revision to upload to. headers (`dict`, *optional*): Additional headers to include in the request transfers (`list`, *optional*): List of transfer methods to use. Defaults to ["basic", "multipart"]. Returns: `LfsBatchInfo`: 3-tuple: - First element is the list of upload instructions from the server - Second element is a list of errors, if any - Third element is the chosen transfer adapter if provided by the server (e.g. "basic", "multipart", "xet") Raises: [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError) If an argument is invalid or the server response is malformed. [`HTTPError`](https://requests.readthedocs.io/en/latest/api/#requests.HTTPError) If the server returned an error. N/z.git/info/lfs/objects/batchuploadbasic multipartoidr"r) operationrOobjects hash_algonameref)rIrNjsonrZzMalformed response from servertransfererror)rENDPOINTREPO_TYPES_URL_PREFIXESrhexr"r LFS_HEADERSrrpostrr_get isinstancelist ValueErrorrF_validate_batch_actions_validate_batch_error)rHrIrJrKrLrMrNrO url_prefix batch_urlrTpayloadresp batch_inforZchosen_transferobjs r/post_lfs_batch_infortfsX$/xY5G5GHJI55566yA *Aj\'2MNI"+"7Yg{=S '  }}((*    G '("34   ' =bG =  iw  GDJnnY-G gt $9:: nnZ0O)3OS)IotO29O#G3r?r@rDrCrFrGr6r/rvrvs O Ir6rvc,eZdZUdZeed<eeed<y)CompletionPayloadTz?Payload that will be sent to the Hub when uploading multi-part.rXpartsN)r>r?r@rArFrCr rvrGr6r/rzrzsI H  r6rzrYrlfs_batch_actioncBt||jd}|$tjd|jdy|dd}t ||djd}| t ||jdi}|jd} t |d | } |  t| } t||| | n t|| |t |t |d |} tj| t|||jj j#|jj$d} t'| tj|jdy#ttf$rtd | d wxYw)aw Handles uploading a given object to the Hub with the LFS protocol. Can be a No-op if the content of the file is already present on the hub large file storage. Args: operation (`CommitOperationAdd`): The add operation triggering this upload. lfs_batch_action (`dict`): Upload instructions from the LFS batch endpoint for this object. See [`~utils.lfs.post_lfs_batch_info`] for more details. headers (`dict`, *optional*): Headers to include in the request, including authentication and user agent headers. Raises: [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError) If `lfs_batch_action` is improperly formatted [`HTTPError`](https://requests.readthedocs.io/en/latest/api/#requests.HTTPError) If the upload resulted in an error actionsNzContent of file z. is already present upstream - skipping uploadrTverifyheader chunk_sizehref)rMzTMalformed response from LFS batch endpoint: `chunk_size` should be an integer. Got 'z'.)rYrr upload_url)rYr)rIrNrWr^z: Upload successful)rkrgloggerdebug path_in_repo_validate_lfs_actionrrDrj TypeError_upload_multi_part_upload_single_partrrfr upload_inforrdr"r) rYr|rIrNrMr~ upload_action verify_actionrrr verify_url verify_resps r/ lfs_uploadrs8,-""9-G ' (>(>'??mno%Y/9M'$Y/33H=M ]+  x ,FL)J' f(=QJ ZJ Yv*akliJG ]++M&,A8L !m(( $5'B"..5599;YEZEZE_E_`) K( LLI**++>?@%I& fgqfrrtu  s - E??F lfs_actionct|jdtr0|jd*t|jdts t d|S).validates response from the LFS batch endpointrrz"lfs_action is improperly formatted)rhrgrFdictrj)rs r/rrsK :>>&)3/ ^^H % -JNN8> r6lfs_batch_actionscPt|jdtrt|jdts t d|jdijd}|jdijd}| t || t ||S)rrXr"z)lfs_batch_actions is improperly formattedr~rTr)rhrgrFrDrjr)rrrs r/rkrks (,,U3S 9jIZI^I^_eIfhk>lDEE%)))R8<t|jdtrt|jdts t d|S)rrXr"z'lfs_batch_error is improperly formattedramessagecode)rhrgrFrDrjr)r error_infos r/rlrl's **513 7JGZGZ[aGbdgz(_get_sorted_parts_urls..ws !A$r6)keyz0Invalid server response to upload large LFS file)sorteditemsisdigitr4rDrr"rj)rrrpart_numr_sorted_part_upload_urls num_partss r/rrns$-3LLN (Hj##%#h-!*;Xr"J/      Az   +,ID))J677KLL ""  s 6B  B%rrXcg}t|D]H\}}|jd}||dk(rtd|d|dz|j|dz|dJ||dS)NrxrRzInvalid etag (`z`) returned for part r)rwrx)rXr{) enumeratergrjappend)rrXr{ part_numberrrxs r/rrs "E()9:   Vzz&! <42:tf4I+XY/IZ[\ \ )Ao    ''r6rc6g}|jd5}t|D]S\}}t|||z|5}td||}t ||j |j dddU ddd|S#1swYjxYw#1swY|SxYw)NTr) seek_from read_limitrr)rrrrrrrN) rYrrrNr7part_idxpart_upload_url fileobj_slicepart_upload_ress r/rrsG   T  * 8g)23D)E 8 %Ho$x/% 8".uoM"Z#O4667 8 8 8 8 N 8 8 8 Ns"#B5B- BB BBc ^ ddlm}dt j |j v}|stjd|jj}|j}t|dkDrd|dd}td d |d|ttj!d 5} |d|j"||d ddd|rd|j$ini}|s|j%||cdddS#t$r tdwxYw#t&$r} t)d| d} ~ wwxYw#1swYyxYw)Nr)multipart_uploadzFast uploading using 'hf_transfer' is enabled (HF_HUB_ENABLE_HF_TRANSFER=1) but 'hf_transfer' package is not available in your environment. Try `pip install hf_transfer`.callbackzYou are using an outdated version of `hf_transfer`. Consider upgrading to latest version to enable progress bars using `pip install -U hf_transfer`.(u(…)iBTzhuggingface_hub.lfs_upload)unit unit_scaletotalinitialdescdisabler\) file_path parts_urlsr max_filesparallel_failures max_retriesz~An error occurred while uploading using `hf_transfer`. Consider disabling HF_HUB_ENABLE_HF_TRANSFER for better error handling.rG) hf_transferr ImportErrorrjinspect signature parametersrrrr"rr4rrrgetEffectiveLevelrupdate Exception RuntimeError) rYrrrsupports_callbackrrprogressoutputes r/rrsh 0#g&7&78H&I&T&TT   c   ! ! & &E  ! !D 4y2~tCDzl#   !9!9!;< )   %#33,%"% 5FJ02F! OOE "5#   Q   H *  's;C.%D#')DD#.D D  DD  D##D,)NNNN)NNN)DrArr)rer dataclassesrmathros.pathrpathlibrtypingrrr r r r r r urllib.parserhuggingface_hubrutilsrrrrrrrr utils._lfsr utils.sharr utils.tqdmr _commit_apir get_loggerr>rcompile OID_REGEXLFS_MULTIPART_UPLOAD_COMMANDrer!rFrrtrvrzrrrkrlrrDrrrrrrGr6r/rs5 !\\\ %   %*(/   H % BJJ( ) 5-2  &9&9 &9R #"(,%)S:&S C=SS S sm S sm Sd38n %SS "S 4:tDz8C= 01SSl9  (," CA#CACA C=CAd38n % CA sm CA  CALT t  4 &S&T&, ("6 ( (RU (cf (ko (F#4#j#c#VZ[^V_#$ (d4j (s (GY (#8