ó
    ç“,j¶  ã            
       ó(  • 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  S SK	J
r
Jr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  SSKJrJrJr  \
(       a  S S	KJr   " S
 S5      rS\S\4S jrS\S\S\\   S\\   S\4
S jrS r S\\\4   S\4S jr!g)é    N)ÚPath)ÚTYPE_CHECKINGÚDictÚListÚOptional)Úmsgé   )ÚErrors)Úcheck_spacy_env_varsÚdownload_fileÚensure_pathyÚget_checksum)Úget_hashÚmake_tempdirÚupload_file)Ú	CloudPathc            
       óä   • \ rS rSrSrSS.S\S\4S jjrS\S	\S
\SS4S jrSSS.S\S	\	\   S
\	\   S\	S   4S jjr
SSS.S\S	\	\   S
\	\   S\	S   4S jjrS\S	\S
\SS4S jrS\S\4S jrSrg)ÚRemoteStorageé   z’Push and pull outputs to and from a remote file storage.

Remotes can be anything that `smart_open` can support: AWS, GCS, file system,
ssh, etc.
Úgz)ÚcompressionÚproject_rootÚurlc                ó<   • Xl         [        U5      U l        X0l        g ©N)Úrootr   r   r   )Úselfr   r   r   s       Ú§C:\Users\johnn\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\weasel/cli/remote_storage.pyÚ__init__ÚRemoteStorage.__init__   s   € Ø Œ	Ü Ó$ˆŒØ&Õó    ÚpathÚcommand_hashÚcontent_hashÚreturnr   c                 ó:  • U R                   U-  nUR                  5       (       d  [        SU S35      eU R                  XU5      nUR                  5       (       a  U$ [	        5        nX`R                  [        U5      5      -  nU R                  (       a  SU R                   3OSn[        R                  " XxS9 n	U	R                  [        U5      [        U5      S9  SSS5        [        Xu5        SSS5        U$ ! , (       d  f       N#= f! , (       d  f       U$ = f)až  Compress a file or directory within a project and upload it to a remote
storage. If an object exists at the full URL, nothing is done.

Within the remote storage, files are addressed by their project path
(url encoded) and two user-supplied hashes, representing their creation
context and their file contents. If the URL already exists, the data is
not uploaded. Paths are archived and compressed prior to upload.
zCannot push z: does not exist.zw:Úw©Úmode)ÚarcnameN)r   ÚexistsÚIOErrorÚmake_urlr   Úencode_nameÚstrr   ÚtarfileÚopenÚaddr   )
r   r"   r#   r$   Úlocr   ÚtmpÚtar_locÚmode_stringÚtar_files
             r   ÚpushÚRemoteStorage.push    sä   € ð �i‰i˜$ÑˆØ�z‰z�|‰|Ü˜L¨¨Ð->Ð?Ó@Ð@Ø�m‰m˜D°Ó=ˆØ�:‰:�<‰<ØˆJäŒ^˜sØ×,Ñ,¬S°«YÓ7Ñ7ˆGØ59×5E×5E˜B˜t×/Ñ/Ð0Ñ1È3ˆKÜ—’˜gÒ8¸HØ—‘œS ›X¬s°4«y�Ñ9÷ 9ä˜Ô%÷ ð ˆ
÷ 9Õ8ú÷ Œ^ð ˆ
ús%   Á'ADÂ:#C:ÃDÃ:
D	ÄDÄ
DN©r#   r$   c                óD  ^• U R                   U-  nUR                  5       (       a  gU R                  XUS9nUc  U$ UR                  R                  5       (       d  UR                  R	                  SS9  [        5        nXeR                  S   -  n[        XW5        U R                  (       a  SU R                   3OSn[        R                  " XxS9 n	S	 mU4S
 jn
U
" X�R                   5        SSS5        SSS5        U$ ! , (       d  f       N= f! , (       d  f       U$ = f)záRetrieve a file from the remote cache. If the file already exists,
nothing is done.

If the command_hash and/or content_hash are specified, only matching
results are returned. If no results are available, an error is raised.
Nr:   T)Úparentséÿÿÿÿzr:Úrr(   c                 óÆ   • [         R                  R                  U 5      n[         R                  R                  U5      n[         R                  R                  X#/5      nXB:H  $ r   )Úosr"   ÚabspathÚcommonprefix)Ú	directoryÚtargetÚabs_directoryÚ
abs_targetÚprefixs        r   Úis_within_directoryÚ/RemoteStorage.pull.<locals>.is_within_directoryZ   sF   € Ü(*¯©¯©¸	Ó(B˜Ü%'§W¡W§_¡_°VÓ%<˜
Ü!#§¡×!5Ñ!5°}Ð6QÓ!R˜Ø%Ñ6Ð6r!   c                 ó>  >• U R                  5        HR  n[        R                  R                  XR                  5      nT" X5      (       a  M;  [        [        R                  5      e   [        R                  S:¼  a  U R                  USS9  g U R                  U5        g )N)é   é   Údata)Úfilter)Ú
getmembersr@   r"   ÚjoinÚnameÚ
ValueErrorr
   ÚE201ÚsysÚversion_infoÚ
extractall)Útarr"   ÚmemberÚmember_pathrH   s       €r   Úsafe_extractÚ(RemoteStorage.pull.<locals>.safe_extract`   sp   ø€ Ø&)§n¡nÖ&6˜FÜ*,¯'©'¯,©,°t¿[¹[Ó*I˜KÙ#6°t×#IÓ#IÜ&0´·±Ó&=Ð =ñ '7ô ×+Ñ+¨wÓ6ØŸN™N¨4¸˜NÒ?àŸN™N¨4Õ0r!   )r   r+   ÚfindÚparentÚmkdirr   Úpartsr   r   r0   r1   )r   r"   r#   r$   Údestr   r4   r5   r6   r7   rZ   rH   s              @r   ÚpullÚRemoteStorage.pull8   sò   ø€ ð �y‰y˜4ÑˆØ�;‰;�=‰=ØØ�i‰i˜ÀlˆiÐSˆØ‰;ØˆJð —;‘;×%Ñ%×'Ñ'Ø—‘×!Ñ!¨$Ð!Ñ/ä” 3Ø§	¡	¨"¡Ñ-�Ü˜cÔ+Ø9=×9I×9I  4×#3Ñ#3Ð"4Ñ5Ès�Ü—\’\ 'Ò<Àò7õ1ñ ! ¯9©9Ô5÷- =÷	  ð6 ˆ
÷/ =Õ<ú÷	  ”ð6 ˆ
ús%   Á>ADÃC?Ã-DÃ?
D	Ä	DÄ
Dc                ó  • U R                  [        U5      5      n/ nUb3  Ub0  U R                  U-  U-  U-  nUR                  5       (       a  U/O/ nOàUbO  U R                  U-  U-  R                  5       (       a)  [	        U R                  U-  U-  R                  5       5      nOŽU R                  U-  R                  5       (       al  U R                  U-  R                  5        H"  nUR                  UR                  5       5        M$     Ub&  U Vs/ s H  ofR                  S   U:X  d  M  UPM     nn[        U5      S:¼  a   UR                  S S9  U(       a  US   $ S$ s  snf ! [         a    [        R                  " S5         N5f = f)zòFind the best matching version of a file within the storage,
or `None` if no match can be found. If both the creation and content hash
are specified, only exact matches will be returned. Otherwise, the most
recent matching file is preferred.
Nr=   r	   c                 ó6   • U R                  5       R                  $ r   )ÚstatÚst_mtime)Úxs    r   Ú<lambda>Ú$RemoteStorage.find.<locals>.<lambda>‰   s   € ¨¯©«×(9Ò(9r!   )ÚkeyzkUnable to sort remote files by last modified. The file(s) pulled from the cache may not be the most recent.)r.   r/   r   r+   ÚlistÚiterdirÚextendr_   ÚlenÚsortÚ	Exceptionr   Úwarn)r   r"   r#   r$   rQ   Úurlsr   Úsub_dirs           r   r\   ÚRemoteStorage.findm   s\  € ð ×Ñ¤ D£	Ó*ˆØˆØÑ#¨Ñ(@Ø—(‘(˜T‘/ LÑ0°<Ñ?ˆCØŸJ™JŸL™L�C‘5¨b‰DØÑ%Ø—‘˜4‘ ,Ñ.×6Ñ6×8Ñ8Ü˜TŸX™X¨™_¨|Ñ;×DÑDÓFÓG�øà—‘˜4‘×'Ñ'×)Ñ)Ø $§¡¨4¡×8Ñ8Ö:�GØ—K‘K §¡Ó 1Ö2ñ  ;àÑ+Ù+/ÓQª4 C·9±9¸R±=ÀLÑ3PŸC©4�DÐQÜˆt‹9˜‹>ðØ—	‘	Ñ9�	Ñ:ö  ˆt�B‰xÐ) TÐ)ùò Røô ó Ü—’ðHöðús   ÄE!Ä+E!ÅE& Å& F	ÆF	c                 ó\   • U R                   U R                  [        U5      5      -  U-  U-  $ )zCConstruct a URL from a subpath, a creation hash and a content hash.)r   r.   r/   )r   r"   r#   r$   s       r   r-   ÚRemoteStorage.make_url‘   s*   € à�x‰x˜$×*Ñ*¬3¨t«9Ó5Ñ5¸ÑDÀ|ÑSÐSr!   rQ   c                 ó@   • [         R                  R                  U5      $ )z&Encode a subpath into a URL-safe name.)ÚurllibÚparseÚ
quote_plus)r   rQ   s     r   r.   ÚRemoteStorage.encode_name•   s   € ä�|‰|×&Ñ& tÓ,Ð,r!   )r   r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r/   r   r8   r   ra   r\   r-   r.   Ú__static_attributes__© r!   r   r   r      sý   † ñð EIò ' Tð '°õ 'ð
˜ð ¨Sð Àð Èô ð8 '+Ø&*ò3àð3ð ˜s‘mð	3ð
 ˜s‘mð3ð 
�+Ñ	õ3ðr '+Ø&*ò"*àð"*ð ˜s‘mð	"*ð
 ˜s‘mð"*ð 
�+Ñ	õ"*ðHT˜Tð T°ð TÀCð TÈKô Tð- ð -¨÷ -r!   r   r3   r%   c                 ó   • [        U 5      $ r   )r   )r3   s    r   Úget_content_hashr„   š   s   € Ü˜ÓÐr!   Ú	site_hashÚenv_hashÚdepsÚcmdc                 ó  • [        5         [        U5       Vs/ s H  n[        U5      PM     nnX/U-   nUR                  U5        SR	                  U5      R                  S5      n[        R                  " U5      R                  5       $ s  snf )zµCreate a hash representing the execution of a command. This includes the
currently installed packages, whatever environment variables have been marked
as relevant, and the command.
Ú Úutf8)	r   Úsortedr   rm   rP   ÚencodeÚhashlibÚmd5Ú	hexdigest)r…   r†   r‡   rˆ   ÚdepÚdep_checksumsÚhashesÚcreation_bytess           r   Úget_command_hashr•   ž   sv   € ô ÔÜ28¸´,Ó?²,¨3”\ #Ö&±,€MÐ?ØÐ" ]Ñ2€FØ
‡M�M�#ÔØ—W‘W˜V“_×+Ñ+¨FÓ3€NÜ�;Š;�~Ó&×0Ñ0Ó2Ð2ùò	 @s   ˜B
c                  óH  • [         R                  " 5       n [         R                  (       a$  U R                  [         R                  " 5       5        [        5       nU  Hx  n[        U5      nUR                  5        HV  nUR                  S   R                  S5      (       d  M(  UR                  UR                  S   R                  SS5      5        MX     Mz     SR                  [        U5      5      R                  S5      n[        R                   " U5      R#                  5       $ )z©Hash the current Python environment's site-packages contents, including
the name and version of the libraries. The list we're hashing is what
`pip freeze` would output.
r=   z	dist-infoz
.dist-inforŠ   r‹   )ÚsiteÚgetsitepackagesÚENABLE_USER_SITErm   ÚgetusersitepackagesÚsetr   rl   r_   Úendswithr2   ÚreplacerP   rŒ   r�   rŽ   Úmd5sumr�   )Ú	site_dirsÚpackagesÚsite_dirÚsubpathÚpackage_bytess        r   Úget_site_hashr¤   ­   sÓ   € ô
 ×$Ò$Ó&€IÜ××Ø×Ñœ×1Ò1Ó3Ô4Ü‹u€HÛˆÜ˜“>ˆØ×'Ñ'Ö)ˆGØ�}‰}˜RÑ ×)Ñ)¨+×6Ó6Ø—‘˜WŸ]™]¨2Ñ.×6Ñ6°|ÀRÓHÖIó *ñ ð
 —G‘GœF 8Ó,Ó-×4Ñ4°VÓ<€MÜ�>Š>˜-Ó(×2Ñ2Ó4Ð4r!   Úenvc                 óÐ   • 0 nU R                  5        HF  u  p#UR                  S5      (       a'  [        R                  R	                  USS S5      X'   MB  X1U'   MH     [        U5      $ )zÐConstruct a hash of the environment variables that will be passed into
the commands.

Values in the env dict may be references to the current os.environ, using
the syntax $ENV_VAR to mean os.environ[ENV_VAR]
Ú$é   NrŠ   )ÚitemsÚ
startswithr@   ÚenvironÚgetr   )r¥   Úenv_varsrj   Úvalues       r   Úget_env_hashr¯   ¿   s\   € ð €HØ—i‘i–k‰
ˆØ×Ñ˜C× Ñ ÜŸJ™JŸN™N¨5°°¨9°bÓ9ˆH‹Mà!�S‹Mñ	 "ô
 �HÓÐr!   )"rŽ   r@   r—   rT   r0   Úurllib.parserx   Úpathlibr   Útypingr   r   r   r   Úwasabir   Úerrorsr
   Úutilr   r   r   r   r   r   r   Úcloudpathlibr   r   r/   r„   r•   r¤   r¯   r‚   r!   r   Ú<module>r·      s­   ðÛ Û 	Û Û 
Û Û Ý ß 6Ó 6å å ß RÓ Rß 6Ñ 6æÝ&÷C-ñ C-ðL˜$ð  3ô ð3Øð3Ø!ð3Ø)-¨d©ð3Ø:>¸s¹)ð3àô3ò5ð$�d˜3 ˜8‘nð ¨õ r!   