a Z^Nc @sdZddlZddlZddlZddlZddlZddlZddlm Z ddl m Z gdZ dddZ dddddd d d Zdddddd ddZdddZddZedkree 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)Path) compile_dir compile_file compile_pathccs|dkrt|tjrt|}|s0td|zt|}Wn,tyj|dkrbtd|g}Yn0||D]|}|dkrqxtj ||}tj |s|Vqx|dkrx|tj krx|tj krxtj |rxtj |sxt||d|dEdHqxdS)NzListing {!r}...zCan't list {!r}Z __pycache__r) maxlevelsquiet) isinstanceosPathLikefspathprintformatZlistdirOSErrorZsortpathjoinZisdircurdirZpardirislink _walk_dir)dirrr Znamesnamefullnamer"/usr/lib64/python3.9/compileall.pyrs2       rFrstripdir prependdir limit_sl_desthardlink_dupesc CsNd}|dur$| dus| dur$td|dur8|} |} d}|dkrHtd|dkrxzddlm}Wntyvd}Yn0|durt}t|||d}d}|dkr|dur|pd}||d D}|tt ||||||| | | | | d |}t |dd }Wdn1s 0Yn2|D],}t |||||||| | | | | d 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 `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 NPDestination dir (ddir) cannot be used in combination with stripdir or prependdirrz%workers must be greater or equal to 0r)ProcessPoolExecutor)r rT)Z max_workers) ddirforcerxr legacyoptimizeinvalidation_moderrrr )defaultrF) ValueErrorZconcurrent.futuresr"Z ImportErrorsysZgetrecursionlimitrZmaprrZmin)rrr#r$r%r r&r'workersr(rrrr r"ZfilessuccessZexecutorZresultsZfilerrrr0sX     . rc% Csz|dur |dus| dur tdd} |dkrBt|tjrBt|}tj|} d}|durhtj|| }|dur|tjj }|tjj }t |}t ||D]\}}||kr| |qtjj|}| dur|durtj| |}ntj| |}t|t r|g}tt|}| r.t|dkr.td|durL||}|rL| S| durtj|rt| t|jvr| Si}tj|rv|D]d}|r|d||<nJ|dkr|dkr|nd }tjj||d }|||<ntj|}|||<q| dd | d d}}|d krv|szt t|j}td tjjd|}|D]L}t |d}|!d}Wdn1s0Y||krXqqX| WSWnt"yYn0|st#d$|zt%|D]p\}}||}t&j'|||d||d} |dkr| r|||d}!t(j)||!ddrt*|t+|!|qWnt&j,y}"zvd} |dkr| WYd}"~"S|rt#d$|n t#dd d|"j-j.t/j0j1dd}#|#2t/j0j1}#t#|#WYd}"~"nd}"~"0t3t4t"fyf}$z^d} |dkr| WYd}$~$S|r4t#d$|n t#dd dt#|$j5j6d|$WYd}$~$nd}$~$00| dkrvd} | S)aByte-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!TrzXHardlinking of duplicated bytecode makes sense only for more than one optimization levelZcrr)Z optimizationiz.pyz<4sllZrbi zCompiling {!r}...)r'r(F)Zshallowz*** Error compiling {!r}...z*** )ZendZbackslashreplace)Zerrorsz:)7r*r r r r rZbasenamerZsplitZsepZlistZzipZremoveintsortedZsetlenZsearchrrZresolveZparentsisfile importlibZutilZcache_from_sourceZstatZst_mtimestructZpackZ MAGIC_NUMBERZvaluesopenZreadrrrZ enumerate py_compilecompilefilecmpZcmpZunlinkZlinkZPyCompileErrormsgZencoder+ZstdoutZencodingZdecodeZ SyntaxErrorZ UnicodeErrorZ __class____name__)%rr#r$r%r r&r'r(rrrr r-rZdfileZfullname_partsZstripdir_partsZ ddir_partsZspartZopartZmoZ opt_cfilesZ opt_levelZoptZcfileZheadZtailZmtimeZexpectZchandleZactualZindexZokZprevious_cfileZerrr9Zerrrr{s                *          ( rc 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()r+rr rrr) Z skip_curdirrr$r r&r'r(r-rrrrrs    rc Csddl}|jdd}|jddddddd |jd td d d |jddddd|jdddddd|jddddd|jdddddd|jd d!d"dd#d|jd$d%d&dd'd|jd(d)d*dd+d|jd,d-d.d/d0|jd1d2d3d4d5|jd6d7d8td9d:d;d<tjD}|jd=t|d>d?|jd@dAtdBdCdD|jdEdFdGdHd0|jdIddJdKd|}|j}|j rddl }| |j |_ |j dLkrd|_ |j dur|j }n|j}|jdurdMg|_t|jd8kr|jr|dN|jdur|jdus |jdur|dO|jrz\|jdPkr0tjnt|j*}|D]}||q@Wdn1sl0YWn2ty|jdQkrtdR|jYdSS0|j r|j !dPdT"} tj| } nd} dU} z|r~|D]} t#j$%| r4t&| |j|j'|j |j|j(| |j|j|j|j |jdV stdS} n@t)| ||j|j'|j |j|j(|j*| |j|j|j|j |jdWsdS} q| WSt+|j(|j'|j| dXWSWn*t,y|jdQkrtdYYdSS0dUS)ZzScript main program.rNz1Utilities to support installing Python libraries.)Z descriptionz-lZ store_constrz!don't recurse into subdirectories)actionZconstr)desthelpz-r recursionzhcontrol the maximum recursion level. if `-l` and `-r` options are specified, then `-r` takes precedence.)typer<r=z-fZ store_truer$z/force rebuild even if timestamps are up to date)r;r<r=z-qZcountr zIoutput only error messages; -qq will suppress the error messages as well.)r;r<r)r=z-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)metavarr<r)r=z-sZSTRIPDIRrzpart of path to left-strip from path to source file - for example buildroot. `-d` and `-s` options cannot be specified together.z-pZ PREPENDDIRrzpath 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-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)r@r<r= compile_destzFILE|DIRZ*zrzero or more file and directory names to compile; if no arguments given, defaults to the equivalent of -l sys.path)r@Znargsr=z-jz --workersrzRun compileall concurrently)r)r?r=cSsg|]}|jddqS)_-)rZlowerreplace)Z.0ZmoderrrZ hszmain..z--invalidation-modezset .pyc invalidation mode; defaults to "checked-hash" if the SOURCE_DATE_EPOCH environment variable is set, and "timestamp" otherwise.)Zchoicesr=z-oappend opt_levelszOptimization levels to run compilation with.Default is -1 which uses optimization level ofPython interpreter itself (specified by -O).)r;r?r<r=z-eZDIRrz+Ignore symlinks pointing outsite of the DIRz--hardlink-dupesr zHardlink duplicated pyc filesr.rzYHardlinking of duplicated bytecode makes sense only for more than one optimization level.z.-d cannot be used in combination with -s or -prDrzError reading file list {}FrCT)r(rrr'rr )r,r(rrr'rr )r&r$r r(z [interrupted])-argparseZArgumentParserZ add_argumentr/r6ZPycInvalidationModer0Z parse_argsrBr%rer7rr>rrGr1r Zerrorr#rrrAr+Zstdinr5rFZstriprr rrr(rEZupperr rr2rr$r&rr,rZKeyboardInterrupt) rHZparserZinvalidation_modesZargsZ compile_destsrIrZfZlineZivl_moder(r-r<rrrmain3s                    6        rJZ__main__)r) NNFNrFrrN)NFNrFrN)rrFrFrN)Z__doc__r r+Zimportlib.utilr3r6r4r8Z functoolsrZpathlibrZ__all__rrrrrJr:r/Z exit_statusZexitrrrrZsD     K  "