o ?OgO@sdZddlZddlZddlZddlZddlZddlZddlm Z ddl m Z gdZ dddZ  dddddd d d Z  dddddd ddZ  dddZddZedkrhee ZeedSdS)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|}|std|zt|}Wnty6|dkr2td|g}Ynw||D]>}|dkrDq=tj ||}tj |sU|Vq=|dkr{|tj kr{|tj kr{tj |r{tj |s{t||d|dEdHq=dS)NzListing {!r}...zCan't list {!r} __pycache__r) maxlevelsquiet) isinstanceosPathLikefspathprintformatlistdirOSErrorsortpathjoinisdircurdirpardirislink _walk_dir)dirr r namesnamefullnamer 1/opt/alt/python310/lib64/python3.10/compileall.pyrs:       rFr stripdir prependdir limit_sl_desthardlink_dupesc CsZd}|dur| dus| durtd|dur|} |} d}|dkr$td|dkrEddlm}z|Wn ty>d}Ynwddlm}|durMt}t|||d}d }|dkr|dur|pad}||d #}| t t ||||||| | | | | d |}t |d d }Wd|S1swY|S|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 )_check_system_limits)ProcessPoolExecutor)r r T)Z max_workers) ddirforcerxr legacyoptimizeinvalidation_moder$r%r&r')defaultr#F) ValueErrorZconcurrent.futures.processr)NotImplementedErrorZconcurrent.futuresr*sysgetrecursionlimitrmaprrmin)rr r+r,r-r r.r/workersr0r$r%r&r'r*r)filessuccessZexecutorZresultsfiler r r!r0sh        rc& Csn|dur|dus | durtdd} t|}|dur t|nd}tj|} d}|dur5tj|| }|durd|tjj}|tjj}t|}t ||D] \}}||kr]| |qPtjj|}| dur{|durttj| |}ntj| |}t |t r|g}t t|}| rt|dkrtd|dur||}|r| S| durtj|rt| t|jvr| Si}tj|r5|D].}|r|d||<q|dkr|dkr|nd }tjj||d }|||<qtj|}|||<q| dd | d d}}|d kr5|sXzCt t|j}td tjjd|d@}|D]%}t|d }| d}Wdn 1s;wY||krGnq#| WSWn t!yWYnw|sbt"d#|z?t$|D]8\}}||}t%j&|||d||d} |dkr| r|||d}!t'j(||!ddrt)|t*|!|qgWnt%j+y}"z?d} |dkr| WYd}"~"S|rt"d#|nt"dd dt,j-j.pt,/}#|"j0j1|#dd2|#}$t"|$WYd}"~"| Sd}"~"wt3t4t!fy-}%z0d} |dkr| WYd}%~%S|rt"d#|nt"dd dt"|%j5j6d|%WYd}%~%| Sd}%~%ww| dkr5d} | 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 levelcrr ) optimizationz.pyz<4sLLlrb zCompiling {!r}...)r/r0F)Zshallowz*** Error compiling {!r}...z*** )endbackslashreplace)errors:)7r2r rrbasenamersplitseplistzipremover intsortedsetlensearchrrZresolveparentsisfile importlibutilcache_from_sourcestatst_mtimestructZpack MAGIC_NUMBERvaluesopenreadrrr enumerate py_compilecompilefilecmpZcmpunlinklinkPyCompileErrorr4stdoutencodinggetdefaultencodingmsgencodedecode SyntaxError UnicodeError __class____name__)&rr+r,r-r r.r/r0r$r%r&r'r:rdfileZfullname_partsZstripdir_partsZ ddir_partsZspartZopartZmoZ opt_cfiles opt_leveloptcfileheadtailmtimeZexpectZchandleZactualindexokZprevious_cfileerrrerger r r!r}s                          rc CsTd}tjD]"}|r|tjkr|r|dkrtdq|o&t||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/r0)r4rr rrr) Z skip_curdirr r,r r.r/r0r:rr r r!rs"  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|jrQz0|jdPkrtjnt|jdQdR}|D] }||qWdn 1s1wYWntyP|jdSkrMtdT|jYdUSw|j rd|j !dPdV"} tj| } nd} dW} z^|r|D]I} t#j$%| rt&| |j|j'|j |j|j(| |j|j|j|j |jdX sdU} qnt)| ||j|j'|j |j|j(|j*| |j|j|j|j |jdYsdU} qn| WSt+|j(|j'|j| dZWSt,y|jdSkrtd[YdUSw)\zScript main program.rNz1Utilities to support installing Python libraries.) descriptionz-lZ store_constr z!don't recurse into subdirectories)actionZconstr1desthelpz-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)rzr{r|z-qcountr zIoutput only error messages; -qq will suppress the error messages as well.)rzr{r1r|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{r1r|z-sZSTRIPDIRr$zpart of path to left-strip from path to source file - for example buildroot. `-d` and `-s` options cannot be specified together.z-pZ PREPENDDIRr%zpath 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)rr{r| compile_destzFILE|DIR*zrzero or more file and directory names to compile; if no arguments given, defaults to the equivalent of -l sys.path)rnargsr|z-jz --workersr zRun compileall concurrently)r1r~r|cSsg|] }|jddqS)_-)rlowerreplace).0moder r r! iszmain..z--invalidation-modezset .pyc invalidation mode; defaults to "checked-hash" if the SOURCE_DATE_EPOCH environment variable is set, and "timestamp" otherwise.)choicesr|z-oappend opt_levelszOptimization levels to run compilation with. Default is -1 which uses the optimization level of the Python interpreter itself (see -O).)rzr~r{r|z-eZDIRr&z+Ignore symlinks pointing outsite of the DIRz--hardlink-dupesr'zHardlink duplicated pyc filesr=r"zYHardlinking of duplicated bytecode makes sense only for more than one optimization level.z.-d cannot be used in combination with -s or -przutf-8)rerzError reading file list {}FrT)r0r$r%r/r&r')r8r0r$r%r/r&r')r.r,r r0z [interrupted])-argparseArgumentParser add_argumentrLr^PycInvalidationModerM parse_argsrr-rer_r&r}r rrOr'errorr+r$r%rr4stdinr[rstriprr rrr0rupperr rrRrr,r.rr8rKeyboardInterrupt) rparserZinvalidation_modesargsZ compile_destsrr flineZivl_moder0r:r{r r r!main4s                            r__main__)r) NNFNrFr"r N)NFNrFr"N)r rFrFr"N)__doc__r r4importlib.utilrSr^rXr` functoolsrZpathlibr__all__rrrrrrmrLZ exit_statusexitr r r r!sH     M  "