
    dC                        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dS )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dS )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                ,    |                      d          S )N.conda)endswith)fns    @lib/python3.11/site-packages/conda_package_handling/conda_fmt.py	supportedzCondaFormat_v2.supported"   s    {{8$$$    c                   t          j        |                    d                    pd}t          j                            |           sNt          j                            t          j                            t          j                    |                     } t          j        	                    |          st          j
        |           t          t          |           t          |          |           d S )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
w}}R   	A!!"',,ry{{B"?"?@@Bw}}X&& 	"K!!!R#h--J??????r   Nc                >    t                               | |dg          S )Nr   r   )r   r*   )r   r(   s     r   extract_infozCondaFormat_v2.extract_info0   s    %%b(x%HHHr   NNN
compressor-Callable[[], zstandard.ZstdCompressor] | Nonec           	        t           j                            |          r>t           j                            |          }t           j                            |          }t           j                            ||          }|                    dd          }t          j        ||           }t          |          t          fd|D                       }	|r|dk    rt          d          |%d }|\  }
}r                    d          rfd} G d	 d
          }t          |dt                    5 }t          j        |           5  dt           i}|                    dt%          j        |                     d| d|fd| d|	ff} |            }|D ]\  }}t)          j         |            d          5 }|D ]#}|                    |t          j                   $	 d d d            n# 1 swxY w Y   |j        j        }|                    |d          5 }|                    ||d          }t)          j        |d          }|D ]#}|                    |t          j                   $|                                 |                                 d d d            n# 1 swxY w Y   	 d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   |S )Nr    c              3  $   K   | ]
}|v|V  d S N ).0fpkg_files_sets     r   	<genexpr>z(CondaFormat_v2.create.<locals>.<genexpr>E   s-      II!=2H2H!2H2H2H2HIIr   r-   z<Supply one of compressor= or (deprecated) compression_tuple=c                 B    t          j        t          t                    S )Nlevelthreads)	zstandardZstdCompressorZSTD_COMPRESS_LEVELZSTD_COMPRESS_THREADSr4   r   r   <lambda>z'CondaFormat_v2.create.<locals>.<lambda>K   s    !9)-" " " r   zzstd:compression-level=c                     t          j        t                               dd          d                   t                    S )N=r   r:   )r=   r>   intsplitr@   )filter_optss   r   rA   z'CondaFormat_v2.create.<locals>.<lambda>S   s<    Y%=k//Q77;<<1& & & r   c                  $    e Zd ZdZd Zd Zd ZdS ))CondaFormat_v2.create.<locals>.NullWriterzL
            zstd uses less memory on extract if size is known.
            c                    d| _         d S )Nr   sizeselfs    r   __init__z2CondaFormat_v2.create.<locals>.NullWriter.__init__]   s    			r   c                Z    | xj         t          |          z  c_         t          |          S r3   )rL   len)rN   bytess     r   writez/CondaFormat_v2.create.<locals>.NullWriter.write`   s$    		SZZ'		5zz!r   c                    | j         S r3   rK   rM   s    r   tellz.CondaFormat_v2.create.<locals>.NullWriter.telld   s
    y r   N)__name__
__module____qualname____doc__rO   rS   rU   r4   r   r   
NullWriterrI   X   sK           " " "! ! ! ! !r   rZ   w)compressionconda_pkg_format_versionzmetadata.jsonzpkg-r   zinfo-)fileobjmode)filterF)rL   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^   rL   openstream_writerclose)prefix	file_listout_fn
out_folderr.   compression_tupleconda_pkg_fnfile_id	pkg_files
info_filesextcomp_filterrZ   
conda_filepkg_metadatacomponents_filescompress	componentfilessizerfilerL   component_filecomponent_streamcomponent_tarrG   r7   s                            @@r   createzCondaFormat_v2.create4   s`    7==   	.00JW%%f--Fw||J77..2..+Iv>>	IIIIIYIIIII
 	],0BBB[\\\ J ->)Ck {556OPP    

	! 	! 	! 	! 	! 	! 	! 	! \3J???  	-:uP
 P
  	-  	- 78TULL1I1IJJJ 8w 8 8 8)D))))G   "z||H$4 - - 	5 _ZZ\\DDD H % H H		$u/F	GGGGHH H H H H H H H H H H H H H H })__Y44 -'/'='=&T5 (> ( ($ %,O<LSV$W$W$WM % P P%))$u7N)OOOO!'')))$**,,,- - - - - - - - - - - - - - -- 	-  	-  	-  	-  	-  	-  	-  	-  	-  	-  	-  	-  	-  	-  	-  	-  	-  	-  	-  	-  	-  	-  	-  	-  	-  	-  	-  	-  	-  	-D s   7KA2K>'G2	&K2G66K9G6:%KA=J(	K(J,,K/J,0K6KK	K	K	
KK Kc                t    t          j        |           }|j        }t          j        | d          \  }}|||dS )N)md5sha256)rL   r   r   )r   statst_sizer   	checksums)in_filestat_resultrL   r   r   s        r   get_pkg_detailszCondaFormat_v2.get_pkg_details   s?    gg&&"og/@AAVSF;;;r   r3   )r.   r/   )rV   rW   rX   rY   staticmethodr   r*   r,   r   r$   r   r   r4   r   r   r   r      s        2 2 % % \% @ @ \@ I I I \I 
 29;;DH,T T T T \Tl < < \< < <r   r   )rY   
__future__r   rm   r   ro   typingr   zipfiler   r   r=   r1   r   	interfacer	   	streamingr
   rk   DEFAULT_COMPRESSION_TUPLEr?   r@   r   r4   r   r   <module>r      s    # " " " " "  				        ' ' ' ' ' ' ' '           ) ) ) ) ) )        M    r< r< r< r< r<' r< r< r< r< r<r   