Ë
    ›¾j   ã                   óþ  — d dl Z d dlZd dlZd dlmZ d dlmZmZmZ d dl	Z	d dl
Z
d dlmZ ddlmZmZmZmZ ddlmZmZmZ ddlmZmZ d	d
lmZmZmZmZ dZ ej:                  ddddœ¬«       e ej<                  «       ddd¬«       edddd¬«       edddd¬«      fde
j>                  dede de fd„«       Z! e«       dddœdedee"ef   de de d df
d!„Z#d)d"ed#ee"   d dfd$„Z$	 d)d%ed&e"d"ed#ee"   d df
d'„Z%d&e"d e"fd(„Z&y)*é    N)ÚPath)ÚAnyÚDictÚOptional)Úmsgé   )ÚSimpleFrozenDictÚdownload_fileÚensure_pathÚget_checksum)Úget_git_versionÚgit_checkoutÚload_project_config)Úparse_config_overridesÚworking_diré   )ÚPROJECT_FILEÚArgÚOptÚappFÚassetsT)Úallow_extra_argsÚignore_unknown_options)Úcontext_settingsz>Path to cloned project. Defaults to current working directory.)ÚhelpÚexistsÚ	file_okayz--sparsez-SzsUse sparse checkout for assets provided via Git, to only check out and clone the files needed. Requires Git v22.2+.)r   z--extraz-ez7Download all assets, including those marked as 'extra'.ÚctxÚproject_dirÚsparse_checkoutÚextrac                 óL   — t        | j                  «      }t        ||||¬«       y)ac  Fetch project assets like datasets and pretrained weights. Assets are
    defined in the "assets" section of the project.yml. If a checksum is
    provided in the project.yml, the file is only downloaded if no local file
    with the same checksum exists.

    DOCS: https://github.com/explosion/weasel/tree/main/docs/tutorial/directory-and-assets.md
    ©Ú	overridesr    r!   N)r   ÚargsÚproject_assets)r   r   r    r!   r$   s        ú[/home/spazio/kingdom_calls/work5/transenv/lib/python3.12/site-packages/weasel/cli/assets.pyÚproject_assets_clir(      s&   € ô& ' s§x¡xÓ0€IÜØØØ'Øö	ó    r#   r$   Úreturnc          	      ó"  — t        | «      }t        ||¬«      }|j                  dg «      D �cg c]  }|s|j                  dt        «      s|‘Œ }}|st	        j
                  dt        › d�d¬«       t	        j                  dt        |«      › d	�«       |D �]r  }| |d
   z  j                  «       }|j                  d«      }	d|v �rd}
t        |
¬«       |j                  «       rb|	r*|	t        |«      k(  rt	        j                  d|d
   › �«       Œz|j                  «       rt        j                   |«       n|j#                  «        d|d   vs|d   d   €t	        j$                  dd¬«       d|d   vs|d   d   €t	        j$                  dd¬«       t'        |d   d   |d   d   ||d   j                  d«      |¬«       t	        j                  d|› �«       �ŒD|j                  d«      }|st)        ||	«       �Œet+        ||||	«       �Œu yc c}w )aV  Fetch assets for a project using DVC if possible.

    project_dir (Path): Path to project directory.
    sparse_checkout (bool): Use sparse checkout for assets provided via Git, to only check out and clone the files
                            needed.
    extra (bool): Whether to download all assets, including those marked as 'extra'.
    )r$   r   r!   zNo assets specified in z< (if assets are marked as extra, download them with --extra)r   )Úexitsz	Fetching z	 asset(s)ÚdestÚchecksumÚgitzƒCloning Weasel project templates requires Git and the 'git' command. Make sure it's installed and that the executable is available.)Úerrorú*Skipping download with matching checksum: ÚrepoNz8A git asset must include 'repo', the repository address.r   ÚpathzFA git asset must include 'path' - use "" to get the entire repository.Úbranch)r4   ÚsparseúDownloaded asset Úurl)r   r   ÚgetÚEXTRA_DEFAULTr   Úwarnr   ÚinfoÚlenÚresolver   r   r   ÚgoodÚis_dirÚshutilÚrmtreeÚunlinkÚfailr   Úcheck_private_assetÚfetch_asset)r   r$   r    r!   Úproject_pathÚconfigÚassetr   r-   r.   Úgit_errr7   s               r'   r&   r&   0   s  € ô ˜{Ó+€LÜ  ¸ÔC€Fð —Z‘Z ¨"Ó-öàÙ˜Ÿ	™	 '¬=Ô9ò 	ð€Fð ñ
 Ü�‰Ø%¤l ^Ð3oÐpØõ	
ô ‡H�Hˆyœ˜V›˜ YÐ/Ô0àó ,;ˆØ˜e F™mÑ+×4Ñ4Ó6ˆØ—9‘9˜ZÓ(ˆØ�EŠ>ðQð ô  'Õ*Ø�{‰{Œ}á ¬L¸Ó,>Ò >Ü—H‘HØDÀUÈ6Á]ÀOÐTôð à—{‘{”}ÜŸ™ dÕ+àŸ™œØ˜U 5™\Ñ)¨U°5©\¸&Ñ-AÐ-IÜ—‘ØNÐVWõð ˜U 5™\Ñ)¨U°5©\¸&Ñ-AÐ-IÜ—‘Ø^Øõô Ø�e‘˜VÑ$Ø�e‘˜VÑ$ØØ˜U‘|×'Ñ'¨Ó1Ø&õô �H‰HÐ(¨¨Ð/Ö0à—)‘)˜EÓ"ˆCÙä# D¨(Ô3ÙÜ˜ c¨4°Ö:ñY,;ùòs   ­!Hr-   r.   c                 ó   — t        | «      j                  «       sd| › �}t        j                  |«       y|st        j                  d| › �«       y|t        | «      k(  rt        j                  d| › �«       yt        j                  d| › �«       y)a  Check and validate assets without a URL (private assets that the user
    has to provide themselves) and give feedback about the checksum.

    dest (Path): Destination path of the asset.
    checksum (Optional[str]): Optional checksum of the expected file.
    z?No URL provided for asset. You need to add this file yourself: zAsset already exists: z%Asset exists with matching checksum: z-Asset available but with incorrect checksum: N)r   r   r   r:   r>   r   rC   )r-   r.   Úerrs      r'   rD   rD   {   sx   € ô �‹:×ÑÔØOÐPTÈvÐVˆÜ�‰��áÜ�H‰HÐ-¨d¨VÐ4Õ5Øœ dÓ+Ò+Ü�H‰HÐ<¸T¸FÐCÕDä�H‰HÐDÀTÀFÐKÕLr)   rF   r7   c                 óî  — | |z  j                  «       }|j                  «       rx|r'|t        |«      k(  rht        j                  d|› �«       yt
        j                  j                  |«      dk(  r-t        j                  d|› �«       t        j                  |«       |j                  j                  «       s|j                  j                  d¬«       t        | «      5  t        |«      }	 t        ||«       t        j                  d|› �«       ddd«       |r/|t        |«      k7  r t        j,                  d
t.        › d|› �«       yyy# t        j                   $ r�}t#        |«      j                  «       rQt#        |«      j%                  «       r8t'        j(                  |t+        |«      «       t        j                  d|› �«       nt        j,                  d	|› �|«       Y d}~ŒÕd}~ww xY w# 1 sw Y   ŒÞxY w)a§  Fetch an asset from a given URL or path. If a checksum is provided and a
    local file exists, it's only re-downloaded if the checksum doesn't match.

    project_path (Path): Path to project directory.
    url (str): URL or path to asset.
    checksum (Optional[str]): Optional expected checksum of local file.
    RETURNS (Optional[Path]): The path to the fetched asset or None if fetching
        the asset failed.
    r1   Nr   z1Asset exists but with size of 0 bytes, deleting: T)Úparentsr6   zCopied local asset zDownload failed: z(Checksum doesn't match value defined in z: )r=   r   r   r   r>   Úosr3   Úgetsizer:   ÚremoveÚparentÚmkdirr   Úconvert_asset_urlr
   ÚhttpxÚ	HTTPErrorr   Úis_filer@   ÚcopyÚstrrC   r   )rF   r7   r-   r.   Ú	dest_pathÚes         r'   rE   rE   Ž   sš  € ð  Ñ$×-Ñ-Ó/€IØ×ÑÔáØœ<¨	Ó2Ò2Ü—‘ÐEÀdÀVÐLÔMØô �w‰w�‰˜yÓ)¨QÒ.Ü—‘ÐLÈTÈFÐSÔTÜ—	‘	˜)Ô$ð ×Ñ×"Ñ"Ô$Ø×Ñ×Ñ tÐÔ,Ü	�\Ó	"ñ 8Ü Ó$ˆð		8Ü˜#˜yÔ)Ü�H‰HÐ(¨¨Ð/Ô0÷	8ñ �H¤¨YÓ 7Ò7Ü�‰Ð;¼L¸>ÈÈDÈ6ÐRÕSð 8€xøô �‰ò 	8Ü�C‹y×ÑÔ!¤d¨3£i×&7Ñ&7Ô&9ä—‘˜C¤ Y£Ô0Ü—‘Ð.¨t¨fÐ5Õ6ä—‘Ð,¨T¨FÐ3°QÔ7ÿøð	8ú÷8ð 8ús1   ÃG+Ã*$EÅG(ÅBG#ÇG+Ç#G(Ç(G+Ç+G4c                 óÄ   — t        j                  d| «      rId| vrEd| vrA| j                  dd«      }t        j                  dd|«      }t	        j
                  d|«       |S | S )	ztCheck and convert the asset URL if needed.

    url (str): The asset URL.
    RETURNS (str): The converted URL.
    z(http(s?)):\/\/github.comzreleases/downloadz/raw/z
github.comzraw.githubusercontent.comz/(tree|blob)/ú/zŒDownloading from a regular GitHub URL. This will only download the source of the page, not the actual file. Converting the URL to a raw URL.)ÚreÚmatchÚreplaceÚsubr   r:   )r7   Ú	converteds     r'   rS   rS   º   sj   € ô 	�‰Ð-¨sÔ3Ø sÑ*Ø˜3Ñà—K‘K Ð.IÓJˆ	Ü—F‘FÐ+¨S°)Ó<ˆ	Ü�‰ðð ô		
ð ÐØ€Jr)   )N)'rN   r]   r@   Úpathlibr   Útypingr   r   r   rT   ÚtyperÚwasabir   Úutilr	   r
   r   r   r   r   r   r   r   Úmainr   r   r   r   r9   ÚcommandÚcwdÚContextÚboolr(   rX   r&   rD   rE   rS   © r)   r'   ú<module>rm      sœ  ðÛ 	Û 	Û Ý ß &Ñ &ã Û Ý ç MÓ Mß EÑ Eß 6ß -Ó -ð €ð €‡�ØØ*.È$ÑOôñ ˜H˜DŸH™H›JÐ-mÐvzð  GLô  MÙ  z°4ð  ?tô  uÙ�e˜Y¨Ð3lÔmñà	�‰ðð ðð ð	ð
 òó	ðñ6 !1Ó 2Ø!ØòH;ØðH;ð �C˜�H‰~ðH;ð ð	H;ð
 ðH;ð 
óH;ñVM˜dð M¨h°s©mð MÀtó Mð( IMñ)TØð)TØ ð)TØ(,ð)TØ8@À¹ð)Tà	ó)TðX˜3ð  3ô r)   