3 \]/�@s�dZddlZddlZddlZddlZddlZddlmZdddgZ ddd �Z dd d�Z dd d�Z ddd�Z dd�Zedkr�ee� �Zeje�dS)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� compile_dir� compile_file� compile_path� ccs |dkrt|tj�rtj|�}|s0tdj|��ytj|�}Wn.tk rl|dkrdtdj|��g}YnX|j�x�|D]�}|dkr�q|tj j ||�}|dk r�tj j ||�}nd}tj j |�s�|Vq||dkr||tj kr||tj kr|tj j |�r|tj j|� r|t|||d|d�EdHq|WdS)N�zListing {!r}...zCan't list {!r}� __pycache__r�)�ddir� maxlevels�quiet)� isinstance�os�PathLike�fspath�print�format�listdir�OSError�sort�path�join�isdir�curdir�pardir�islink� _walk_dir)�dirr r r �names�name�fullname�dfile�r"�"/usr/lib64/python3.6/compileall.pyrs0    rFr c Cs�d} |dk rP|dkrtd��n2|dkrPyddlm} Wntk rNd}YnXt||||d�} d} |dk r�|dkr�| dk r�|p�d}| |d��0} | jtt||||||d �| �} t| dd �} WdQRXn&x$| D]}t|||||||�s�d } q�W| 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 10) 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: optimization level or -1 for level of the interpreter workers: maximum number of parallel workers Nrz%workers must be greater or equal to 0r )�ProcessPoolExecutor)r r r T)Z max_workers)r �force�rxr �legacy�optimize)�defaultF) � ValueErrorZconcurrent.futuresr$� ImportErrorr�maprr�min)rr r r%r&r r'r(�workersr$�files�successZexecutorZresults�filer"r"r#r2s6     cCs�d}|dkr"t|tj�r"tj|�}tjj|�}|dk rFtjj||�} nd} |dk rd|j|�} | rd|Stjj|��r�|r�|d} nB|dkr�|dkr�|nd} t j j || d�} n t j j |�} tjj | �} |dd�|dd�}}|d k�r�|�sXyTt tj|�j�}tjd t j j|�}t| d ��}|jd �}WdQRX||k�r>|SWntk �rVYnX|�sltdj|��ytj|| | d|d�}Wn�tjk �r}zdd}|dk�r�|S|�r�tdj|��n tddd�|jjtjjdd�}|j tjj�}t|�WYdd}~Xn~t!t"tfk �rv}zLd}|dk�r2|S|�rHtdj|��n tddd�t|j#j$d|�WYdd}~XnX|dk�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: optimization level or -1 for level of the interpreter TrN�crr �)� optimization�z.pyz<4sl�rb�zCompiling {!r}...)r(Fz*** Error compiling {!r}...z*** )�end�backslashreplace)�errors�:�����r<)%r rrrr�basenamer�search�isfile� importlib�util�cache_from_source�dirname�int�stat�st_mtime�structZpack� MAGIC_NUMBER�open�readrrr� py_compile�compile�PyCompileError�msg�encode�sys�stdout�encoding�decode� SyntaxError� UnicodeError� __class__�__name__)r r r%r&r r'r(r0rr!Zmo�cfile�optZ cache_dir�head�tail�mtimeZexpectZchandleZactual�ok�errrN�er"r"r#rbsx                  $ c CsXd}xNtjD]D}| s |tjkr6|r6|dkrPtd�q |oNt||d||||d�}q W|S)awByte-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) TrzSkipping current directoryN)r r'r()rPrrrrr)Z skip_curdirr r%r r'r(r0rr"r"r#r�s    c Cszddl}|jdd�}|jdddddd d �|jd td d d�|jddddd�|jdddddd�|jddddd�|jdddddd �|jd!d"d#dd$d �|jd%d&d'd(d)�|jd*d+d,d-d.�|jd/d0d1td2d3�|j�}|j}|jr�ddl}|j|j�|_|j dk �r|j }n|j }|j �r�yJ|j d4k�r4t j nt|j ��$}x|D]}|j|j���qFWWdQRXWn2tk �r�|jd5k�r�td6j|j ��d7SX|jdk �r�|j�p�d|_d8}y�|�r4xj|D]b} tjj| ��rt| |j|j|j|j|j��s*d7}n*t| ||j|j|j|j|j|jd9��s�d7}�q�W|St|j|j|jd:�SWn*tk �rt|jd5k�rptd;�d7SXd8S) s$    / R [