
    I0fC                        d Z ddlmZ ddlZddlZddlZddlmZ ddlm	Z	m
Z
 ddlZddlmZ ddlmZ dd	lmZ d
ZdZdZdZ G d de      Zy)z
The 'new' conda format, introduced in late 2018/early 2019.

https://docs.conda.io/projects/conda/en/latest/user-guide/concepts/packages.html
    )annotationsN)Callable)
ZIP_STOREDZipFile   )utils)AbstractBaseFormat)_extract   ).tar.zstzstdzzstd:compression-level=19   c                      e Zd ZdZed        Zed        Zed	d       Ze ej                         ddf	 d
d       Z
ed        Zy)CondaFormat_v2zIf there's another conda format or breaking changes, please create a new class and keep this
    one, so that handling of v2 stays working.c                $    | j                  d      S )N.conda)endswith)fns    @lib/python3.12/site-packages/conda_package_handling/conda_fmt.py	supportedzCondaFormat_v2.supported"   s    {{8$$    c                   t        j                  |j                  d            xs d}t        j                  j                  |       sOt        j                  j                  t        j                  j                  t        j                         |             } t        j                  j                  |      st        j                  |       t        t        |       t        |      |       y )N
components)infopkgr   )r   ensure_listgetospathisabsnormpathjoingetcwdisdirmakedirsr
   str)r   dest_dirkwr   s       r   extractzCondaFormat_v2.extract&   s    &&rvvl';<O
ww}}R !!"'',,ryy{B"?@Bww}}X&KK!R#h-J?r   Nc                4    t         j                  | |dg      S )Nr   r   )r   r*   )r   r(   s     r   extract_infozCondaFormat_v2.extract_info0   s    %%b(x%HHr   NNNc           	     h   t         j                  j                  |      r>t         j                  j                  |      }t         j                  j	                  |      }t         j                  j                  ||      }|j                  dd      }t        j                  ||       }t        |      t        fd|D              }	|r|dk7  rt        d      |!d }|\  }
}rj                  d      rfd} G d	 d
      }t        |dt              5 }t        j                  |       5  dt         i}|j#                  dt%        j&                  |             d| d|fd| d|	ff} |       }|D ]  \  }}t)        j*                   |       d      5 }|D ]#  }|j-                  |t        j.                         % 	 d d d        j0                  j2                  }|j5                  |d      5 }|j7                  ||d      }t)        j*                  |d      }|D ]#  }|j-                  |t        j.                         % |j9                          |j9                          d d d         	 d d d        d d d        |S # 1 sw Y   xY w# 1 sw Y   #xY w# 1 sw Y   ,xY w# 1 sw Y   |S xY w)Nr    c              3  ,   K   | ]  }|vs|  y wN ).0fpkg_files_sets     r   	<genexpr>z(CondaFormat_v2.create.<locals>.<genexpr>E   s     I!=2H!Is   	r-   z<Supply one of compressor= or (deprecated) compression_tuple=c                 @    t        j                  t        t              S )Nlevelthreads)	zstandardZstdCompressorZSTD_COMPRESS_LEVELZSTD_COMPRESS_THREADSr2   r   r   <lambda>z'CondaFormat_v2.create.<locals>.<lambda>K   s    !9!9)-" r   zzstd:compression-level=c                 r    t        j                  t         j                  dd      d         t              S )N=r   r8   )r;   r<   intsplitr>   )filter_optss   r   r?   z'CondaFormat_v2.create.<locals>.<lambda>S   s/    Y%=%=k//Q7;<1& r   c                  "    e Zd ZdZd Zd Zd Zy))CondaFormat_v2.create.<locals>.NullWriterzL
            zstd uses less memory on extract if size is known.
            c                    d| _         y )Nr   sizeselfs    r   __init__z2CondaFormat_v2.create.<locals>.NullWriter.__init__]   s	    	r   c                T    | xj                   t        |      z  c_         t        |      S r1   )rJ   len)rL   bytess     r   writez/CondaFormat_v2.create.<locals>.NullWriter.write`   s    		SZ'	5z!r   c                    | j                   S r1   rI   rK   s    r   tellz.CondaFormat_v2.create.<locals>.NullWriter.telld   s    yy r   N)__name__
__module____qualname____doc__rM   rQ   rS   r2   r   r   
NullWriterrG   X   s    "!r   rX   w)compressionconda_pkg_format_versionzmetadata.jsonzpkg-r   zinfo-)fileobjmode)filterF)rJ   closefd)r   r    r!   dirnamebasenamer#   replacer   filter_info_filessetlist
ValueError
startswithr   r   	tmp_chdirCONDA_PACKAGE_FORMAT_VERSIONwritestrjsondumpstarfileTarFileaddanonymize_tarinfor\   rJ   openstream_writerclose)prefix	file_listout_fn
out_folder
compressorcompression_tupleconda_pkg_fnfile_id	pkg_files
info_filesextcomp_filterrX   
conda_filepkg_metadatacomponents_filescompress	componentfilessizerfilerJ   component_filecomponent_streamcomponent_tarrE   r5   s                            @@r   createzCondaFormat_v2.create4   s    77== 0JWW%%f-Fww||J7..2.++Iv>	IIYII
,0BB[\\J ->)Ck{556OP

	! 	! \3J?  	-:uP
  	- 78TULL1IJ"&wix 8)Dy)G   "|H$4 - 	5 __Z\D H % H		$u/F/F	GHH }}))__Y4 -'/'='=&T5 (> ($ %,OO<LSV$WM % P%))$u7N7N)OP "'')$**,- -- 	-  	-D %H H
- -+ 	-  	-  	-D sV   J'.A)J)J	0J1A4J	%
J0J'JJJJJ$	 J''J1c                    t        j                  |       }|j                  }t        j                  | d      \  }}|||dS )N)md5sha256)rJ   r   r   )r   statst_sizer   	checksums)in_filestat_resultrJ   r   r   s        r   get_pkg_detailszCondaFormat_v2.get_pkg_details   s=    ggg&""oog/@AVSF;;r   r1   )rx   z-Callable[[], zstandard.ZstdCompressor] | None)rT   rU   rV   rW   staticmethodr   r*   r,   r   r$   r   r   r2   r   r   r   r      s    2 % % @ @ I I 
 299;DH,T
 BT Tl < <r   r   )rW   
__future__r   rk   r   rm   typingr   zipfiler   r   r;   r/   r   	interfacer	   	streamingr
   ri   DEFAULT_COMPRESSION_TUPLEr=   r>   r   r2   r   r   <module>r      sS    #  	   '   )   M    r<' r<r   