
    h'                         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  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JrJr  SSKJrJr  S	S
KJrJrJrJr  Sr\R:                  " SSSS.S9\" \R<                  " 5       SSSS9\" SSSSS9\" SSSSS94S\
R>                  S\S\ S\ 4S jj5       r!\" 5       SSS.S\S\\"\4   S\ S\ S S4
S! jjr#S)S"\S#\\"   S S4S$ jjr$ S)S%\S&\"S"\S#\\"   S S4
S' jjr%S&\"S \"4S( jr&g)*    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                 F    [        U R                  5      n[        UUUUS9  g)aO  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        K/home/james-whalen/.local/lib/python3.13/site-packages/weasel/cli/assets.pyproject_assets_clir(      s&    & 'sxx0I'	    r#   r$   returnc          	      n   [        U 5      n[        XAS9nUR                  S/ 5       Vs/ s H)  nU(       d  UR                  S[        5      (       a  M'  UPM+     nnU(       d  [        R
                  " S[         S3SS9  [        R                  " S[        U5       S	35        U GH  nXS
   -  R                  5       nUR                  S5      n	SU;   Ga%  Sn
[        U
S9  UR                  5       (       ap  U	(       a-  U	[        U5      :X  a  [        R                  " SUS
    35        M  UR                  5       (       a  [        R                   " U5        OUR#                  5         SUS   ;  d	  US   S   c  [        R$                  " SSS9  SUS   ;  d	  US   S   c  [        R$                  " SSS9  ['        US   S   US   S   UUS   R                  S5      US9  [        R                  " SU 35        GMV  UR                  S5      nU(       d  [)        X5        GM|  [+        XKX5        GM     gs  snf )aB  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gitzCloning 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 CF ZZ"--E		'=9 	-  
 %l^3op	
 HHyVY/0Fm+44699Z(E>Q  '*{{}}L,> >HHDU6]OT {{}}d+U5\)U5\&-A-INVW U5\)U5\&-A-I^ eV$eV$U|''1& HH(/0))E"C#D34:Y s   &H2H2r-   r.   c                 >   [        U 5      R                  5       (       d  SU  3n[        R                  " U5        gU(       d  [        R                  " SU  35        gU[        U 5      :X  a  [        R                  " SU  35        g[        R                  " SU  35        g)zCheck 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   {   s{     :OPTvVHH-dV45d++HH<TFCDHHDTFKLr)   rF   r7   c                 b   X-  R                  5       nUR                  5       (       a  U(       a*  U[        U5      :X  a  [        R                  " SU 35        gOR[
        R                  R                  U5      S:X  a/  [        R                  " SU 35        [
        R                  " U5        UR                  R                  5       (       d  UR                  R                  SS9  [        U 5         [        U5      n [        X5        [        R                  " SU 35        SSS5        U(       a1  U[        U5      :w  a!  [        R.                  " S
[0         SU 35        ggg! [        R                   R"                   a  n[%        U5      R                  5       (       a\  [%        U5      R'                  5       (       a>  [(        R*                  " U[-        U5      5        [        R                  " SU 35         SnAN[        R.                  " S	U 3U5         SnANSnAff = f! , (       d  f       GN= f)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
   requests
exceptionsRequestExceptionr   is_filer@   copystrrC   r   )rF   r7   r-   r.   	dest_pathes         r'   rE   rE      s    $--/I<	22EdVLM 3
 wwy)Q.LTFST		)$ ""$$t,	\	"$		8#)HH(/0	 
# HY 77;L>D6RS 8x ""33 	8Cy!!d3i&7&7&9&9CY0.tf566,TF3Q77	8 
#	"s=   .H;$E  H>A5H3H8HHHH
H.c                     [         R                  " SU 5      (       aO  SU ;  aI  SU ;  aC  U R                  SS5      n[         R                  " SSU5      n[        R
                  " SU5        U$ U $ )	zhCheck 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)//zDownloading 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      sm     	-s33s*3KK.IJ	FF+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(   rY   r&   rD   rE   rS    r)   r'   <module>rn      s   	 	   & &    M M E E 6 - -  *.$O DHHJ-mvz  GL  Mz4  ?t  ueY3lm	  	
 	6 !1 2!H;H; CH~H; 	H;
 H; 
H;VMd Mhsm Mt M( IM)T)T )T(,)T8@)T	)TX3 3 r)   