U kgn5 @sdZddlZddlZddlZddlZddlZddlmZdddgZ ddd Z dd dZ ddZ dddZ dddZddZedkree ZeedS)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)partial compile_dir compile_file compile_path ccs|dkrt|tjrt|}|s0td|zt|}Wn.tk rl|dkrdtd|g}YnX||D]}|dkrqztj ||}|dk rtj ||}nd}tj |s||fVqz|dkrz|tj krz|tj krztj |rztj |szt|||d|dEdHqzdS)NzListing {!r}...zCan't list {!r} __pycache__r)ddir maxlevelsquiet) isinstanceosPathLikefspathprintformatlistdirOSErrorsortpathjoinisdircurdirpardirislink _walk_dir)dirr r r namesnamefullnamedfiler" /usr/lib/python3.8/compileall.pyrs:      rFr c  Csd} |dkrtd|dkrFzddlm} Wntk rDd}YnXt||||d} d} |dkr| dk r|ppd}| |d0} | tt|||||| d | }t|dd } W5QRXn(| D]"\}}t |||||||| sd } q| 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 invalidation_mode: how the up-to-dateness of the pyc will be checked Nrz%workers must be greater or equal to 0r )ProcessPoolExecutor)r r r T)Z max_workers)forcerxr legacyoptimizeinvalidation_mode)defaultF) ValueErrorZconcurrent.futuresr% ImportErrorrmapr_compile_file_tupleminr)rr r r&r'r r(r)workersr*r%Zfiles_and_ddirssuccessZexecutorZresultsfiler!r"r"r#r2sF    cKs|\}}t||f|S)z-Needs to be toplevel for ProcessPoolExecutor.)r)Zfile_and_dfilekwargsr3r!r"r"r#r/esr/c Csd}|dkr"t|tjr"t|}tj|} |dk rFtj|| } nd} |dk rd||} | rd|Stj|r|r|d} nB|dkr|dkr|nd} t j j || d} n t j |} tj | }| dd | d d}}|d kr|s\zXt t|j}td t j jd|}t| d }|d }W5QRX||krB|WSWntk rZYnX|sptd|ztj|| | d||d}Wntjk r}zjd}|dkr|WYRS|rtd|n tddd|jjtjjdd}| tjj}t|W5d}~XYnt!t"tfk r}zRd}|dkrJ|WY:S|r`td|n tdddt|j#j$d|W5d}~XYnX|dkrd}|S)aTByte-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 invalidation_mode: how the up-to-dateness of the pyc will be checked TrNcrr ) optimizationz.pyz<4sllrb zCompiling {!r}...)r)r*Fz*** Error compiling {!r}...z*** )endbackslashreplace)errors:)%r rrrrbasenamersearchisfile importlibutilcache_from_sourcedirnameintstatst_mtimestructZpack MAGIC_NUMBERopenreadrrr py_compilecompilePyCompileErrormsgencodesysstdoutencodingdecode SyntaxError UnicodeError __class____name__)r r r&r'r r(r)r*r2rr!ZmocfileZoptZ cache_dirheadtailmtimeZexpectZchandleZactualokerrrPer"r"r#rjs                    $ c CsTd}tjD]D}|r|tjkr2|r2|dkrNtdq |oLt||d|||||d}q |S)aByte-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() TrzSkipping current directoryN)r r(r)r*)rRrrrrr) Z skip_curdirr r&r r(r)r*r2rr"r"r#rs    c Csddl}|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/d0d1td2d3d4d5tjD}|jd6t|d7d8|}|j}|j r$ddl }| |j |_ |j dk r8|j }n|j }|jrzF|jd9krZtjnt|j }|D]}||qjW5QRXWn4tk r|jd:krtd;|jYd} z|rl|D]h} tj| r6t| |j|j |j |j|j!| d?sbd<} n,t"| ||j|j |j |j|j!|j#| d@ sd<} q| WSt$|j!|j |j| dAWSWn,t%k r|jd:krtdBYdS)CzScript main program.rNz1Utilities to support installing Python libraries.)Z descriptionz-lZ store_constrr z!don't recurse into subdirectories)actionZconstr+desthelpz-r recursionzhcontrol the maximum recursion level. if `-l` and `-r` options are specified, then `-r` takes precedence.)typerbrcz-f store_truer&z/force rebuild even if timestamps are up to date)rarbrcz-qcountr zIoutput only error messages; -qq will suppress the error messages as well.)rarbr+rcz-br(z0use legacy (pre-PEP3147) compiled file locationsz-dZDESTDIRr zdirectory to prepend to file paths for use in compile-time tracebacks and in runtime tracebacks in cases where the source file is unavailable)metavarrbr+rcz-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)rhrbrc compile_destzFILE|DIR*zrzero or more file and directory names to compile; if no arguments given, defaults to the equivalent of -l sys.path)rhnargsrcz-jz --workersr zRun compileall concurrently)r+rerccSsg|]}|jddqS)_-)rlowerreplace).0moder"r"r# szmain..z--invalidation-modezset .pyc invalidation mode; defaults to "checked-hash" if the SOURCE_DATE_EPOCH environment variable is set, and "timestamp" otherwise.)choicesrcrnrzError reading file list {}FrmT)r*)r1r*)r(r&r r*z [interrupted])&argparseArgumentParser add_argumentrFrMPycInvalidationModesorted parse_argsrjr'rerNrdr rirRstdinrKappendstriprr rrr*rpupperrrrArr r&r(rr1rKeyboardInterrupt) ruparserZinvalidation_modesargsZ compile_destsr{r flineZivl_moder*r2rbr"r"r#mains                  r__main__)Nrr) rNFNrFr$r N)NFNrFr$N)r rFrFr$N)__doc__rrRimportlib.utilrBrMrI functoolsr__all__rrr/rrrrYrFZ exit_statusexitr"r"r"r#s<     3 V "i