a
    xŒ@h‰N  ã                	   @   s¾   d Z 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 )aæ  Module/script to byte-compile all .py files to .pyc files.

When called as a script with arguments, this compiles the directories
given as arguments recursively; the -l option prevents it from
recursing into directories.

Without arguments, if compiles all modules on sys.path, without
recursing into subdirectories.  (Even though it should do so for
packages -- for now, you'll have to deal with packages separately.)

See module py_compile for details of the actual byte-compilation.
é    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    úlib/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 )aÞ  Byte-compile all modules in the given directory tree.

    Arguments (only dir is required):

    dir:       the directory to byte-compile
    maxlevels: maximum recursion level (default `sys.getrecursionlimit()`)
    ddir:      the directory that will be prepended to the path to the
               file as it is compiled into each byte-code file.
    force:     if True, force compilation, even if timestamps are up-to-date
    quiet:     full output with False or 0, errors only with 1,
               no output with 2
    legacy:    if True, produce legacy pyc paths instead of PEP 3147 paths
    optimize:  int or list of optimization levels or -1 for level of
               the interpreter. Multiple levels leads to multiple compiled
               files each with one optimization level.
    workers:   maximum number of parallel workers
    invalidation_mode: how the up-to-dateness of the pyc will be checked
    stripdir:  part of path to left-strip from source file path
    prependdir: path to prepend to beginning of original file path, applied
               after stripdir
    limit_sl_dest: ignore symlinks if they are pointing outside of
                   the defined path
    hardlink_dupes: hardlink duplicated pyc files
    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)Zmax_workers)ÚddirÚforceÚrxr   ÚlegacyÚoptimizeÚinvalidation_moder$   r%   r&   r'   )Údefaultr#   F)Ú
ValueErrorZconcurrent.futuresr)   ÚImportErrorÚsysÚgetrecursionlimitr   Úmapr   r   Úmin)r   r
   r*   r+   r,   r   r-   r.   Úworkersr/   r$   r%   r&   r'   r)   ÚfilesÚsuccessZexecutorZ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 )a  Byte-compile one file.

    Arguments (only fullname is required):

    fullname:  the file to byte-compile
    ddir:      if given, the directory name compiled in to the
               byte-code file.
    force:     if True, force compilation, even if timestamps are up-to-date
    quiet:     full output with False or 0, errors only with 1,
               no output with 2
    legacy:    if True, produce legacy pyc paths instead of PEP 3147 paths
    optimize:  int or list of optimization levels or -1 for level of
               the interpreter. Multiple levels leads to multiple compiled
               files each with one optimization level.
    invalidation_mode: how the up-to-dateness of the pyc will be checked
    stripdir:  part of path to left-strip from source file path
    prependdir: path to prepend to beginning of original file path, applied
               after stripdir
    limit_sl_dest: ignore symlinks if they are pointing outside of
                   the defined path.
    hardlink_dupes: hardlink duplicated pyc files
    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.   r/   F)Zshallowz*** Error compiling {!r}...z*** )ÚendÚbackslashreplace)Úerrorsú:)8r1   r   r   r   r   r   Úbasenamer   ÚsplitÚsepÚlistÚzipÚremoveÚintÚsortedÚsetÚlenÚsearchr   r   ZresolveÚparentsÚisfileÚ	importlibÚutilÚcache_from_sourceÚstatÚst_mtimeÚstructZpackÚMAGIC_NUMBERÚvaluesÚopenÚreadr   r   r   Ú	enumerateÚ
py_compileÚcompileÚfilecmpZcmpÚunlinkÚlinkÚPyCompileErrorr3   ÚstdoutÚencodingÚgetdefaultencodingÚmsgÚencodeÚdecodeÚSyntaxErrorÚUnicodeErrorÚ	__class__Ú__name__)&r   r*   r+   r,   r   r-   r.   r/   r$   r%   r&   r'   r9   r   ÚdfileZfullname_partsZstripdir_partsZ
ddir_partsZspartZopartZmoZ
opt_cfilesÚ	opt_levelZoptÚcfileÚheadÚtailÚmtimeZexpectZchandleZactualÚindexÚokZprevious_cfileÚerrrd   rf   Ú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 )a¤  Byte-compile all module on sys.path.

    Arguments (all optional):

    skip_curdir: if true, skip current directory (default True)
    maxlevels:   max recursion level (default 0)
    force: as for compile_dir() (default False)
    quiet: as for compile_dir() (default 0)
    legacy: as for compile_dir() (default False)
    optimize: as for compile_dir() (default -1)
    invalidation_mode: as for compiler_dir()
    Tr   zSkipping current directoryN)r   r-   r.   r/   )r3   r   r   r   r   r   )	Zskip_curdirr
   r+   r   r-   r.   r/   r9   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/d0� |jd1d2d3d4d5� |jd6d7d8td9d:� d;d<„ tjD ƒ}|jd=t|ƒd>d?� |jd@dAtdBdCdD� |jdEdFdGdHd0� |jdIddJdKd� | ¡ }|j}|j	�r„ddl
}| |j	¡|_	|jdLk�r–d|_|jdu�rª|j}n|j}|jdu �rÄdMg|_t|jƒd8k�ræ|j�ræ| dN¡ |jdu�r|jdu�s
|jdu�r| dO¡ |j�r¬z\|jdPk�r0tjnt|jƒ�*}|D ]}| | ¡ ¡ �q@W d  ƒ n1 �sl0    Y  W n2 t�yª   |jdQk �r¤tdR |j¡ƒ Y dSS 0 |j �rÒ|j  !dPdT¡ "¡ }	tj|	 }
nd}
dU}z¾|�r~|D ]�}t#j$ %|¡�r4t&||j|j'|j	|j|j(|
|j|j|j|j|jdV��stdS}n@t)|||j|j'|j	|j|j(|j*|
|j|j|j|j|jdW��sædS}�qæ|W S t+|j(|j'|j|
dX�W S W n* t,�yÂ   |jdQk �r¼tdYƒ Y dSS 0 dUS )ZzScript main program.r   Nz1Utilities to support installing Python libraries.)Zdescriptionz-lZstore_constr
   z!don't recurse into subdirectories)ÚactionZconstr0   ÚdestÚhelpz-rÚ	recursionzhcontrol the maximum recursion level. if `-l` and `-r` options are specified, then `-r` takes precedence.)Útyperx   ry   z-fÚ
store_truer+   z/force rebuild even if timestamps are up to date)rw   rx   ry   z-qÚcountr   zIoutput only error messages; -qq will suppress the error messages as well.)rw   rx   r0   ry   z-br-   z0use legacy (pre-PEP3147) compiled file locationsz-dZ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)Úmetavarrx   r0   ry   z-sZ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-pZ
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-xZREGEXPr,   zskip files matching the regular expression; the regexp is searched for in the full path of each file considered for compilationz-iZFILEÚflistzzadd all the files and directories listed in FILE to the list considered for compilation; if "-", names are read from stdin)r~   rx   ry   Ú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~   Únargsry   z-jz	--workersr	   zRun compileall concurrently)r0   r{   ry   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.)Úchoicesry   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).)rw   r{   rx   ry   z-eZ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)r/   r$   r%   r.   r&   r'   )r7   r/   r$   r%   r.   r&   r'   )r-   r+   r   r/   z
[interrupted])-ÚargparseÚArgumentParserÚadd_argumentrK   r]   ÚPycInvalidationModerL   Ú
parse_argsr€   r,   Úrer^   r&   rz   r
   rŒ   rN   r'   Úerrorr*   r$   r%   r   r3   ÚstdinrZ   r‹   Ústripr   r   r   r   r/   r†   Úupperr   r   rQ   r   r+   r-   r   r7   r   ÚKeyboardInterrupt)r�   ÚparserZinvalidation_modesÚargsZcompile_destsr’   r
   ÚfÚlineZivl_moder/   r9   rx   r    r    r!   Úmain2  s   ÿ
þ
ÿ
ÿÿ
ÿÿ
þ
þÿ
ÿ
ÿ
ÿÿþÿ
ÿþ
ÿÿ
6ù
ø	
þrœ   Ú__main__)r   )	NNFNr   Fr"   r	   N)NFNr   Fr"   N)r	   r   Fr   Fr"   N)Ú__doc__r   r3   Úimportlib.utilrR   r]   rW   r_   Ú	functoolsr   Úpathlibr   Ú__all__r   r   r   r   rœ   rl   rK   Zexit_statusÚexitr    r    r    r!   Ú<module>   sD   
   þýK   þý    þ
" 