o
    …9jO  ã                   @   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rheeƒ  ƒZe e¡ dS 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 | ¡} |std | ¡ƒ zt | ¡}W n ty6   |dk r2td | ¡ƒ g }Y nw | ¡  |D ]>}|dkrDq=tj	 
| |¡}tj	 |¡sU|V  q=|dkr{|tjkr{|tjkr{tj	 |¡r{tj	 |¡s{t||d |d�E d H  q=d 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/lib/python3.10/compileall.pyr      s:   €
ý
ÿ
ÿ
ÿ€ør   Féÿÿÿÿr	   ©ÚstripdirÚ
prependdirÚlimit_sl_destÚhardlink_dupesc
                C   sZ  d}|dur|
dus|durt dƒ‚|dur| }
|}d}|dk r$t dƒ‚|dkrEddlm} z|ƒ  W n ty>   d}Y nw ddlm} |du rMt ¡ }t| ||d�}d	}|dkr”|dur”|pad}||d
��#}| 	t
t|||||||	|
|||d�|¡}t|d	d�}W d  ƒ |S 1 s�w   Y  |S |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	   )Ú_check_system_limits)ÚProcessPoolExecutor)r   r
   T)Úmax_workers)ÚddirÚforceÚrxr   ÚlegacyÚoptimizeÚinvalidation_moder$   r%   r&   r'   )Údefaultr#   F)Ú
ValueErrorÚconcurrent.futures.processr)   ÚNotImplementedErrorÚconcurrent.futuresr*   ÚsysÚgetrecursionlimitr   Úmapr   r   Úmin)r   r
   r,   r-   r.   r   r/   r0   Úworkersr1   r$   r%   r&   r'   r*   r)   ÚfilesÚsuccessÚexecutorÚresultsÚfiler    r    r!   r   0   sh   
ÿ÷
ö
ôëùü€r   c          &   
   C   sn  |dur|dus|	durt dƒ‚d}t | ¡} |dur t |¡nd}tj | ¡}d}|dur5tj ||¡}|durd|  tjj¡}| tjj¡}t|ƒ}t	||ƒD ]\}}||kr]| 
|¡ qPtjj|Ž }|	dur{|du rttj |	| ¡}ntj |	|¡}t|tƒrƒ|g}tt|ƒƒ}|r•t|ƒdk r•t dƒ‚|dur¢| | ¡}|r¢|S |
dur»tj | ¡r»t|
ƒ ¡ t| ƒ ¡ jvr»|S i }tj | ¡�r5|D ].}|rÑ| d ||< qÆ|dkrê|dkrÛ|nd	}tjj| |d
�}|||< qÆtj | ¡}|||< qÆ|dd… |dd… }}|dk�r5|�sXzCtt | ¡jƒ}t dtjjd|d@ ¡}| ¡ D ]%}t|dƒ�}|  d¡}W d  ƒ n	1 �s;w   Y  ||k�rG n�q#|W S W n
 t!�yW   Y nw |�sbt"d #| ¡ƒ z?t$|ƒD ]8\}}|| }t%j&| ||d||d�} |dk�rž|�rž|||d   }!t'j(||!dd��ržt )|¡ t *|!|¡ �qgW 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, /¡ }#|"j0j1|#dd� 2|#¡}$t"|$ƒ W Y d}"~"|S d}"~"w t3t4t!f�y- }% z0d}|dk�r|W  Y d}%~%S |�rt"d #| ¡ƒ nt"dd	d� t"|%j5j6d |%ƒ W Y d}%~%|S d}%~%ww | dk�r5d}|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}...)r0   r1   F)Úshallowz*** Error compiling {!r}...z*** )ÚendÚbackslashreplace)Úerrorsú:)7r3   r   r   r   Úbasenamer   ÚsplitÚsepÚlistÚzipÚremover   Ú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ÚPyCompileErrorr7   ÚstdoutÚencodingÚgetdefaultencodingÚmsgÚencodeÚdecodeÚSyntaxErrorÚUnicodeErrorÚ	__class__Ú__name__)&r   r,   r-   r.   r   r/   r0   r1   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Úerrrn   rp   Úer    r    r!   r   }   sÚ   

€

ÿ


ÿÿ
ÿþÿþ
€÷

€ô
€ô

r   c           	      C   sT   d}t jD ]"}|r|tjkr| r|dk rtdƒ q|o&t||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/   r0   r1   )r7   r   r   r   r   r   )	Úskip_curdirr
   r-   r   r/   r0   r1   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/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�rQz0|jdPk�rtjnt|jdQdR��}|D ]
}| | ¡ ¡ �qW d  ƒ n	1 �s1w   Y  W n t�yP   |jdSk �rMtdT |j¡ƒ Y dUS w |j �rd|j  !dPdV¡ "¡ }	tj|	 }
nd}
dW}z^|�r»|D ]I}t#j$ %|¡�r–t&||j|j'|j	|j|j(|
|j|j|j|j|jdX��s”dU}�qnt)|||j|j'|j	|j|j(|j*|
|j|j|j|j|jdY��s¶dU}�qn|W S t+|j(|j'|j|
dZ�W S  t,�yÛ   |jdSk �rØtd[ƒ Y dUS w )\zScript main program.r   Nz1Utilities to support installing Python libraries.)Údescriptionz-lÚstore_constr
   z!don't recurse into subdirectories)ÚactionÚconstr2   Ú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’   r2   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’   r2   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)r2   r•   r“   c                 S   s   g | ]}|j  ¡  d d¡‘qS )Ú_ú-)r   ÚlowerÚreplace)Ú.0Úmoder    r    r!   Ú
<listcomp>i  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 filesrB   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£   zutf-8)rn   r   zError reading file list {}Fr¢   T)r1   r$   r%   r0   r&   r'   )r;   r1   r$   r%   r0   r&   r'   )r/   r-   r   r1   z
[interrupted])-ÚargparseÚArgumentParserÚadd_argumentrR   rf   ÚPycInvalidationModerS   Ú
parse_argsrŸ   r.   Úrerg   r&   r”   r
   r«   rU   r'   Úerrorr,   r$   r%   rž   r7   Ústdinrc   rª   Ústripr   r   r   r   r1   r¥   Úupperr   r   rY   r   r-   r/   r   r;   r   ÚKeyboardInterrupt)r­   ÚparserÚinvalidation_modesÚargsÚcompile_destsr²   r
   ÚfÚlineÚivl_moder1   r=   r’   r    r    r!   Úmain4  s  ÿ
þ
ÿ
ÿÿ
ÿÿ
þ
þÿ
ÿ
ÿ
ÿÿþÿ
ÿþ




ÿÿþ€ýù€
ø	€
þýr¿   Ú__main__)r   )	NNFNr   Fr"   r	   N)NFNr   Fr"   N)r	   r   Fr   Fr"   N)Ú__doc__r   r7   Úimportlib.utilrZ   rf   r_   rh   Ú	functoolsr   Úpathlibr   Ú__all__r   r   r   r   r¿   rv   rR   Úexit_statusÚexitr    r    r    r!   Ú<module>   sH    
þýMþý 
þ" þ