Yf-@s>dZddlZddlZddlZddlZddlZyddlmZWne k rpdZYnXddl m Z dddgZ dddd d Z ddd ddd dd d dZdd ddd dddZd dd dd dddZddZedkr:ee ZejedS)aModule/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)ProcessPoolExecutor)partial compile_dir compile_file compile_path ccsa|stdj|ytj|}Wn7tk re|dkr[tdj|g}YnX|jx|D]}|dkrqwtjj||}|dk rtjj||}nd}tjj|s|Vqw|dkrw|tj krw|tj krwtjj|rwtjj | rwt |d|d|dd |EdHqwWdS) NzListing {!r}...zCan't list {!r} __pycache__rddir maxlevelsquiet) printformatoslistdirOSErrorsortpathjoinisdircurdirpardirislink _walk_dir)dirr r r namesnamefullnamedfiler //opt/alt/python35/lib64/python3.5/compileall.pyrs,       *%rFr c Cs|dk r$|dkr$tdt|d|d|d|} d} |dk r|dkrtdk r|pud}td|U} | jttd|d |d |d|d |d || } t| d d} WdQRXn5x2| D]*} t| ||||||sd} qW| S)aByte-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 r r r Z max_workersforcerxlegacyoptimizedefault) ValueErrorrrmaprrmin)rr r r"r#r r$r%workersfilessuccessZexecutorZresultsfiler r r!r4s(  $       cCs'd}tjj|}|dk r<tjj||} nd} |dk rg|j|} | rg|Stjj|r#|r|d} nc|dkr|dkr|nd} tjj|d| } ntjj|} tjj | } |dd|dd}}|dkr#|syot tj |j }t jd tjj|}t| d }|jd }WdQRX||kr|SWntk rYnX|std j|y"tj|| | d d|}Wn-tjk r}zd}|dkr|S|r+tdj|ntddd|jjtjjdd}|jtjj}t|WYdd}~Xntttfk r}z^d}|dkr|S|rtdj|ntdddt|j j!d|WYdd}~XnX|dkr#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 r Ncr optimizationz.pyz<4slrbzCompiling {!r}...Tr%rz*** Error compiling {!r}...z*** enderrorsbackslashreplace:r8)"rrbasenamersearchisfile importlibutilcache_from_sourcedirnameintstatst_mtimestructZpack MAGIC_NUMBERopenreadrrr py_compilecompilePyCompileErrormsgencodesysstdoutencodingdecode SyntaxError UnicodeError __class____name__)rr r"r#r r$r%r,rrZmocfileZoptZ cache_dirheadtailmtimeZexpectZchandleZactualokerrrJer r r!r\st     !        * c Csd}xstjD]h}| s,|tjkrK|rK|dkrxtdq|out||d|d|d|d|}qW|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) r rzSkipping current directoryNr r$r%)rLrrrrr)Z skip_curdirr r"r r$r%r,rr r r!rs    c Csddl}|jdd}|jdddddd d d d d d|jddtd dd d|jdddd dd d|jdddd dd dd d|jdddd dd d|jddd d d!d dd d"|jd#dd$d d%d dd d&|jd'dd(d d)d d*|jd+dd,d-d.d d/|jd0d1d d2dtd d3|j}|j}|jrddl}|j|j|_|j dk r|j }n |j }|j rxyY|j d4krt j n t|j +}x!|D]}|j|jqWWdQRXWn;tk rw|jd5krotd6j|j d7SYnX|jdk r|jpd|_d8}y|r>x|D]} tjj| rt| |j|j|j|j|js6d7}qt| ||j|j|j|j|jd9|jsd7}qW|Std|jd|jd|jSWn/tk r|jd5krtd:d7SYnXd8S);zScript main program.rNZ descriptionz1Utilities to support installing Python libraries.z-lactionZ store_constZconstr&rdestr helpz!don't recurse into subdirectoriesz-rtype recursionzhcontrol the maximum recursion level. if `-l` and `-r` options are specified, then `-r` takes precedence.z-f store_truer"z/force rebuild even if timestamps are up to datez-qcountr zIoutput only error messages; -qq will suppress the error messages as well.z-br$z0use legacy (pre-PEP3147) compiled file locationsz-dmetavarZDESTDIRr zdirectory to prepend to file paths for use in compile-time tracebacks and in runtime tracebacks in cases where the source file is unavailablez-xZREGEXPr#zskip files matching the regular expression; the regexp is searched for in the full path of each file considered for compilationz-iZFILEflistzzadd all the files and directories listed in FILE to the list considered for compilation; if "-", names are read from stdin compile_destzFILE|DIRnargs*zrzero or more file and directory names to compile; if no arguments given, defaults to the equivalent of -l sys.pathz-jz --workersr zRun compileall concurrently-rzError reading file list {}FTr*z [interrupted]) argparseArgumentParser add_argumentr@ parse_argsrdr#rerHr_r rcrLstdinrEappendstriprr rrr*rrr;rr r"r$rrKeyboardInterrupt) rhparserargsZ compile_destsrlr fliner,r\r r r!mains~            * "        ru__main__rwrw)__doc__rrLimportlib.utilr<rGrCZconcurrent.futuresr ImportError functoolsr__all__rrrrrurSr@Z exit_statusexitr r r r! s,        ' P  [