a
    ´i‰N  ã                	   @   sº   d dl Z d dlZd dlZd dlZd dlZd dlZd dlmZ d dl	m
Z
 g d¢Zddd„Zdddddd
œdd„Zdddddd
œdd„Zddd„Zdd„ Zedkr¶eeƒ  ƒZe e¡ dS )é    N)Úpartial)ÚPath)Úcompile_dirÚcompile_fileÚcompile_pathc                 c   sú   |dk rt | tjƒrt | ¡} |s0td | ¡ƒ zt | ¡}W n, tyj   |dk rbtd | ¡ƒ g }Y n0 | ¡  |D ]|}|dkr†qxtj	 
| |¡}tj	 |¡s¨|V  qx|dkrx|tjkrx|tjkrxtj	 |¡rxtj	 |¡sxt||d |d�E d H  qxd S )Né   zListing {!r}...zCan't list {!r}Ú__pycache__r   é   )Ú	maxlevelsÚquiet)Ú
isinstanceÚosÚPathLikeÚfspathÚprintÚformatÚlistdirÚOSErrorÚsortÚpathÚjoinÚisdirÚcurdirÚpardirÚislinkÚ	_walk_dir)Údirr
   r   ÚnamesÚnameÚfullname© r    ú"/usr/lib64/python3.9/compileall.pyr      s2    


ÿ
ÿ
ÿr   Féÿÿÿÿr	   ©ÚstripdirÚ
prependdirÚlimit_sl_destÚhardlink_dupesc
                C   sN  d }|d ur$|
d us|d ur$t dƒ‚|d ur8| }
|}d }|dk rHt dƒ‚|dkrxzddlm} W n tyv   d}Y n0 |d u rˆt ¡ }t| ||d�}d}|dk�r|d u�r|p´d }||d��D}| tt	|||||||	|
|||d	�|¡}t
|dd
�}W d   ƒ n1 �s0    Y  n2|D ],}t	||||||||	|
|||d��sd}�q|S )NúPDestination dir (ddir) cannot be used in combination with stripdir or prependdirr   z%workers must be greater or equal to 0r	   )ÚProcessPoolExecutor)r   r
   T)Úmax_workers)ÚddirÚforceÚrxr   ÚlegacyÚoptimizeÚinvalidation_moder$   r%   r&   r'   )Údefaultr#   F)Ú
ValueErrorÚconcurrent.futuresr)   ÚImportErrorÚsysÚgetrecursionlimitr   Úmapr   r   Úmin)r   r
   r+   r,   r-   r   r.   r/   Úworkersr0   r$   r%   r&   r'   r)   ÚfilesÚsuccessÚexecutorÚresultsÚfiler    r    r!   r   0   sX    
÷
ö.ür   c          &   
   C   s„  |d ur |d us|	d ur t dƒ‚d}|dk rBt| tjƒrBt | ¡} tj | ¡}d }|d urhtj ||¡}|d urÆ|  tjj	¡}| tjj	¡}t
|ƒ}t||ƒD ]\}}||krž| |¡ qžtjj|Ž }|	d urô|d u rætj |	| ¡}ntj |	|¡}t|tƒ�r|g}tt|ƒƒ}|�r.t|ƒdk �r.t dƒ‚|d u�rL| | ¡}|�rL|S |
d u�r„tj | ¡�r„t|
ƒ ¡ t| ƒ ¡ jv�r„|S i }tj | ¡�r€|D ]d}|�r²| d ||< nJ|dk�rè|dk�rÊ|nd}tjj| |d	�}|||< ntj | ¡}|||< �qš|d d
… |d
d …  }}|dk�r€|�sÈzˆtt | ¡jƒ}t dtjjd|d@ ¡}| ¡ D ]L}t |dƒ�}| !d¡}W d   ƒ n1 �sŒ0    Y  ||k�r\ �q°�q\|W S W n t"�yÆ   Y n0 |�sÜt#d $| ¡ƒ z€t%|ƒD ]p\}}|| }t&j'| ||d||d�} |dk�ræ|�ræ|||d   }!t(j)||!dd��ræt *|¡ t +|!|¡ �qæW �n t&j,�yô }" z|d}|dk�rŽ|W  Y d }"~"S |�r¤t#d $| ¡ƒ nt#ddd� t-j.j/�pÀt- 0¡ }#|"j1j2|#dd� 3|#¡}$t#|$ƒ W Y d }"~"n”d }"~"0  t4t5t"f�yp }% z^d}|dk�r(|W  Y d }%~%S |�r>t#d $| ¡ƒ nt#ddd� t#|%j6j7d |%ƒ W Y d }%~%nd }%~%0 0 | dk�r€d}|S )Nr(   Tr   zXHardlinking of duplicated bytecode makes sense only for more than one optimization levelÚcr   r	   Ú )Úoptimizationéýÿÿÿz.pyz<4sLLl   ÿÿ Úrbé   zCompiling {!r}...)r/   r0   F)Úshallowz*** Error compiling {!r}...z*** )ÚendÚbackslashreplace)Úerrorsú:)8r2   r   r   r   r   r   Úbasenamer   ÚsplitÚsepÚlistÚzipÚremoveÚintÚsortedÚsetÚlenÚsearchr   r   ÚresolveÚparentsÚisfileÚ	importlibÚutilÚcache_from_sourceÚstatÚst_mtimeÚstructÚpackÚMAGIC_NUMBERÚvaluesÚopenÚreadr   r   r   Ú	enumerateÚ
py_compileÚcompileÚfilecmpÚcmpÚunlinkÚlinkÚPyCompileErrorr5   ÚstdoutÚencodingÚgetdefaultencodingÚmsgÚencodeÚdecodeÚSyntaxErrorÚUnicodeErrorÚ	__class__Ú__name__)&r   r+   r,   r-   r   r.   r/   r0   r$   r%   r&   r'   r;   r   ÚdfileÚfullname_partsÚstripdir_partsÚ
ddir_partsÚspartÚopartÚmoÚ
opt_cfilesÚ	opt_levelÚoptÚcfileÚheadÚtailÚmtimeÚexpectÚchandleÚactualÚindexÚokÚprevious_cfileÚerrrl   rn   Úer    r    r!   r   {   sÂ    



ÿ

ÿ*


þ


(
r   c           	      C   sT   d}t jD ]D}|r|tjkr2| r2|dk rNtdƒ q
|oLt||d |||||d�}q
|S )NTr   zSkipping current directory)r   r.   r/   r0   )r5   r   r   r   r   r   )	Úskip_curdirr
   r,   r   r.   r/   r0   r;   r   r    r    r!   r     s     

ø
r   c                  C   sÈ  dd l } | jdd�}|jdddd ddd� |jd	td
dd� |jddddd� |jdddddd� |jddddd� |jdddd dd� |jdd d!d d"d� |jd#d$d%d d&d� |jd'd(d)d d*d� |jd+d,d-d.d/� |jd0d1d2d3d4� |jd5d6d7td8d9� d:d;„ tjD ƒ}|jd<t|ƒd=d>� |jd?d@tdAdBdC� |jdDdEdFdGd/� |jdHddIdJd� | ¡ }|j}|j	�r„dd l
}| |j	¡|_	|jdKk�r–d |_|jd u�rª|j}n|j}|jd u �rÄdLg|_t|jƒd7k�ræ|j�ræ| dM¡ |jd u�r|jd u�s
|jd u�r| dN¡ |j�r¬z\|jdOk�r0tjnt|jƒ�*}|D ]}| | ¡ ¡ �q@W d   ƒ n1 �sl0    Y  W n2 t�yª   |jdPk �r¤tdQ |j¡ƒ Y dRS 0 |j �rÒ|j  !dOdS¡ "¡ }	tj|	 }
nd }
dT}z¾|�r~|D ]�}t#j$ %|¡�r4t&||j|j'|j	|j|j(|
|j|j|j|j|jdU��stdR}n@t)|||j|j'|j	|j|j(|j*|
|j|j|j|j|jdV��sædR}�qæ|W S t+|j(|j'|j|
dW�W S W n* t,�yÂ   |jdPk �r¼tdXƒ Y dRS 0 dTS )YNr   z1Utilities to support installing Python libraries.)Údescriptionz-lÚstore_constr
   z!don't recurse into subdirectories)ÚactionÚconstr1   ÚdestÚhelpz-rÚ	recursionzhcontrol the maximum recursion level. if `-l` and `-r` options are specified, then `-r` takes precedence.)Útyper�   r‘   z-fÚ
store_truer,   z/force rebuild even if timestamps are up to date)rŽ   r�   r‘   z-qÚcountr   zIoutput only error messages; -qq will suppress the error messages as well.)rŽ   r�   r1   r‘   z-br.   z0use legacy (pre-PEP3147) compiled file locationsz-dÚDESTDIRr+   z�directory to prepend to file paths for use in compile-time tracebacks and in runtime tracebacks in cases where the source file is unavailable)Úmetavarr�   r1   r‘   z-sÚSTRIPDIRr$   z€part of path to left-strip from path to source file - for example buildroot. `-d` and `-s` options cannot be specified together.z-pÚ
PREPENDDIRr%   z®path to add as prefix to path to source file - for example / to make it absolute when some part is removed by `-s` option. `-d` and `-p` options cannot be specified together.z-xÚREGEXPr-   zskip files matching the regular expression; the regexp is searched for in the full path of each file considered for compilationz-iÚFILEÚflistzzadd all the files and directories listed in FILE to the list considered for compilation; if "-", names are read from stdin)r—   r�   r‘   Úcompile_destzFILE|DIRÚ*zrzero or more file and directory names to compile; if no arguments given, defaults to the equivalent of -l sys.path)r—   Únargsr‘   z-jz	--workersr	   zRun compileall concurrently)r1   r“   r‘   c                 S   s   g | ]}|j  ¡  d d¡‘qS )Ú_ú-)r   ÚlowerÚreplace)Ú.0Úmoder    r    r!   Ú
<listcomp>g  s   ÿzmain.<locals>.<listcomp>z--invalidation-modez‡set .pyc invalidation mode; defaults to "checked-hash" if the SOURCE_DATE_EPOCH environment variable is set, and "timestamp" otherwise.)Úchoicesr‘   z-oÚappendÚ
opt_levelsz‡Optimization levels to run compilation with. Default is -1 which uses the optimization level of the Python interpreter itself (see -O).)rŽ   r“   r�   r‘   z-eÚDIRr&   z+Ignore symlinks pointing outsite of the DIRz--hardlink-dupesr'   zHardlink duplicated pyc filesr@   r"   zYHardlinking of duplicated bytecode makes sense only for more than one optimization level.z.-d cannot be used in combination with -s or -pr¡   r   zError reading file list {}Fr    T)r0   r$   r%   r/   r&   r'   )r9   r0   r$   r%   r/   r&   r'   )r.   r,   r   r0   z
[interrupted])-ÚargparseÚArgumentParserÚadd_argumentrP   rd   ÚPycInvalidationModerQ   Ú
parse_argsr�   r-   Úrere   r&   r’   r
   r©   rS   r'   Úerrorr+   r$   r%   rœ   r5   Ústdinra   r¨   Ústripr   r   r   r   r0   r£   Úupperr   r   rW   r   r,   r.   r   r9   r   ÚKeyboardInterrupt)r«   ÚparserÚinvalidation_modesÚargsÚcompile_destsr°   r
   ÚfÚlineÚivl_moder0   r;   r�   r    r    r!   Úmain2  s   ÿ
þ
ÿ
ÿÿ
ÿÿ
þ
þÿ
ÿ
ÿ
ÿÿþÿ
ÿþ
ÿÿ
6ù
ø	
þr½   Ú__main__)r   )	NNFNr   Fr"   r	   N)NFNr   Fr"   N)r	   r   Fr   Fr"   N)r   r5   Úimportlib.utilrX   rd   r]   rf   Ú	functoolsr   Úpathlibr   Ú__all__r   r   r   r   r½   rt   rP   Úexit_statusÚexitr    r    r    r!   Ú<module>   sB   
   þýK   þý    þ
" 