
    RhvP                         d Z ddlZddlZddlZddlZddlZddlZddlm	Z	 ddl
mZ g dZddZ	 	 	 ddddddd	Z	 	 	 ddddddd
Z	 	 	 ddZd Zedk(  r! e e              Z ej*                  e       yy)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, it 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_pathc              #     K   |dk  r/t        | t        j                        rt        j                  |       } |st	        dj                  |              	 t        j                  |       }|j                          |D ]  }|dk(  r	t        j                  j                  | |      }t        j                  j                  |      s| M|dkD  sS|t        j                  k7  sg|t        j                  k7  s{t        j                  j                  |      st        j                  j                  |      rt        ||dz
  |      E d {     y # t        $ r% |dk  rt	        dj                  |              g }Y w xY w7 8w)N   zListing {!r}...zCan't list {!r}__pycache__r      )	maxlevelsquiet)
isinstanceosPathLikefspathprintformatlistdirOSErrorsortpathjoinisdircurdirpardirislink	_walk_dir)dirr   r   namesnamefullnames         !/usr/lib/python3.12/compileall.pyr   r      s-    qyZR[[1iin&&s+,

3
 
JJL 	.= 77<<T*ww}}X&N!m		 1dbii6GggmmH%bggnnX.F Y]',. . .	.  19#**3/0.sU   AFE )A$FF"F6FF6F
FF*F <F?F  FFstripdir
prependdirlimit_sl_desthardlink_dupesc
                   d}||
|t        d      || }
|}d}|dk  rt        d      |dk7  rddlm} 	  |        ddlm} |t        j                         }t        | ||      }d	}|dk7  r|	 ddl	}|j                         d
k(  r|j                  d      }nd}|xs d} |||      5 }|j                  t        t        |||||||	|
|||      |      }t!        |d	      }ddd       |S |D ]  }t        ||||||||	|
|||      rd} |S # t
        $ r d}Y w xY w# t        $ r d}Y w xY w# 1 sw Y   |S xY w)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 `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 prependdirr   z%workers must be greater or equal to 0r   )_check_system_limits)ProcessPoolExecutor)r   r   Tfork
forkserver)max_workers
mp_context)ddirforcerxr   legacyoptimizeinvalidation_moder$   r%   r&   r'   )defaultr#   F)
ValueErrorconcurrent.futures.processr*   concurrent.futuresr+   NotImplementedErrorsysgetrecursionlimitr   multiprocessingget_start_methodget_contextImportErrormapr   r   min)r   r   r0   r1   r2   r   r3   r4   workersr5   r$   r%   r&   r'   r+   r*   filessuccessr=   r/   executorresultsfiles                          r"   r   r   0   s   8 X1Z5K G I 	I
{@AA!|C	? " ?))+	c)<EG!|+7	"//1V;,88F
!
 /T W,68 	1;Cll7<04E.0284<=N4<6@9F:H	$J $)
*G '40G	1, N  	 DdE2u &2C)1j.;/=	?
  	  NS # 	G	  	J		1, Ns/   D 3+D% .9D6D"!D"%D32D36E c          	      
   |||	t        d      d}t        j                  |       } |t        j                  |      nd}t        j                  j	                  |       }d}| t        j                  j                  ||      }|| j                  t        j                  j                        }|j                  t        j                  j                        }t        |      }t        ||      D ]  \  }}||k(  s|j                  |        t        j                  j
                  | }|	C|!t        j                  j                  |	|       }n t        j                  j                  |	|      }t        |t              r|g}t        t        |            }|rt        |      dk  rt        d      ||j!                  |       }|r|S |
]t        j                  j#                  |       r>t%        |
      j'                         t%        |       j'                         j(                  vr|S i }t        j                  j+                  |       r|D ]f  }|r	| dz   ||<   |dk\  r0|dk\  r|nd	}t,        j.                  j1                  | |
      }|||<   Ct,        j.                  j1                  |       }|||<   h |dd |dd }}|dk(  rU|s	 t        t        j2                  |       j4                        }t7        j8                  dt,        j.                  j:                  d|dz        }|j=                         D ]/  }t?        |d      5 }|jA                  d      }ddd       |k7  s/ n |S 	 |stE        djG                  |              	 tI        |      D ]}  \  }}||   }tK        jL                  | ||d||      } |dkD  s,|s/|||dz
        }!tO        jP                  ||!d      sSt        jR                  |       t        jT                  |!|        	  dk(  rd}|S |S # 1 sw Y   xY w# tB        $ r Y w xY w# tJ        jV                  $ r}"d}|dk\  r|cY d}"~"S |rtE        djG                  |              ntE        dd	       tX        jZ                  j\                  xs tY        j^                         }#|"j`                  jc                  |#d      je                  |#      }$tE        |$       Y d}"~"|S d}"~"wtf        th        tB        f$ rf}%d}|dk\  r|cY d}%~%S |rtE        djG                  |              ntE        dd	       tE        |%jj                  jl                  dz   |%       Y d}%~%|S d}%~%ww xY w)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:  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)   Tr	   zXHardlinking of duplicated bytecode makes sense only for more than one optimization levelcr   r    )optimizationz.pyz<4sLLl    rb   zCompiling {!r}...)r4   r5   F)shallowz*** Error compiling {!r}...z*** )endbackslashreplace)errors:)7r7   r   r   r   basenamer   splitseplistzipremover   intsortedsetlensearchr   r   resolveparentsisfile	importlibutilcache_from_sourcestatst_mtimestructpackMAGIC_NUMBERvaluesopenreadr   r   r   	enumerate
py_compilecompilefilecmpcmpunlinklinkPyCompileErrorr;   stdoutencodinggetdefaultencodingmsgencodedecodeSyntaxErrorUnicodeError	__class____name__)&r!   r0   r1   r2   r   r3   r4   r5   r$   r%   r&   r'   rE   r    dfilefullname_partsstripdir_parts
ddir_partsspartopartmo
opt_cfiles	opt_leveloptcfileheadtailmtimeexpectchandleactualindexokprevious_cfileerrrw   ry   es&                                         r"   r   r      s   6 X1Z5K G I 	I Gyy"H&.&:ryy"H77H%DET4(!4!4.)
? 	)LE5~!!%(	) j)=GGLLX6EGGLLU3E(C : c(m$H#h-!+ F G 	G 
~YYx N RWW^^H%=&&(X0F0F0H0P0PPNJ	ww~~h! 	2I(03
9%>'0A~)2C&^^==%C > 9E,1Jy)%NN<<XFE,1Jy)	2 #2YRS	d5= 1 : :;E#[[)..2M2M)*EK,?AF!+!2!2!4 '!%. 6'%,\\"%5F6!V+!	'  ' "
 )00:;"$(1((; 	;$E9&y1E#++HeUD5>>OQB qy^)3HUQY4G)H";;uneLIIe,GGNE:	;@ 7#GN7N[6 6   ,, A:"N7>>xHI&b)::..J#2H2H2JggnnX6HnIPPQYZc

 N  w7 5A:"N7>>xHI&b)akk**S0!44 N5s   A:P( PP( "P( 6P7 <P7 ?#P7 #-P7 P%	!P( (	P43P47U,
S/U,BS//U,U'U,AU''U,c                     d}t         j                  D ]B  }|r|t        j                  k(  r| r|dk  s t	        d       ,|xr t        ||d|||||      }D |S )a  Byte-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()
    Tr	   zSkipping current directoryN)r   r3   r4   r5   )r;   r   r   r   r   r   )	skip_curdirr   r1   r   r3   r4   r5   rE   r   s	            r"   r   r     sl     Gxx sbii'[qy23 	+!"3	#G N    c                  
   ddl } | j                  d      }|j                  dddddd	       |j                  d
t        dd       |j                  dddd       |j                  ddddd       |j                  dddd       |j                  ddddd       |j                  d d!d"dd#       |j                  d$d%d&dd'       |j                  d(d)d*dd+       |j                  d,d-d.d/0       |j                  d1d2d3d45       |j                  d6d7d8t        d9:       t        j
                  D cg c],  }|j                  j                         j                  d;d<      . }}|j                  d=t        |      d>?       |j                  d@dAt        dBdCD       |j                  dEdFdGdH0       |j                  dIddJdK       |j                         }|j                  }|j                  r$ddl}|j                  |j                        |_        |j                  dLk(  rd|_        |j                   |j                   }n|j"                  }|j$                  dMg|_        t'        |j$                        d8k(  r|j(                  r|j+                  dN       |j,                  )|j.                  |j0                  |j+                  dO       |j2                  rg	 |j2                  d<k(  rt4        j6                  nt9        |j2                  dPQ      5 }|D ]!  }	|j;                  |	j=                                # 	 ddd       |jF                  r>|jF                  j                  d<d;      jI                         }
t        j
                  |
   }nd}dU}	 |r4|D ],  }tJ        jL                  jO                  |      rtQ        ||j,                  |jR                  |j                  |j@                  |jT                  ||j.                  |j0                  |j$                  |j                  |j(                  V      rdT}tW        |||j,                  |jR                  |j                  |j@                  |jT                  |jX                  ||j.                  |j0                  |j$                  |j                  |j(                  W      r+dT}/ |S t[        |jT                  |jR                  |j@                  |X      S c c}w # 1 sw Y   xY w# t>        $ r6 |j@                  dRk  r$tC        dSjE                  |j2                               Y yTw xY w# t\        $ r |j@                  dRk  rtC        dY       Y yTw xY w)ZzScript main program.r   Nz1Utilities to support installing Python libraries.)descriptionz-lstore_constr   z!don't recurse into subdirectories)actionconstr6   desthelpz-r	recursionzhcontrol the maximum recursion level. if `-l` and `-r` options are specified, then `-r` takes precedence.)typer   r   z-f
store_truer1   z/force rebuild even if timestamps are up to date)r   r   r   z-qcountr   zIoutput only error messages; -qq will suppress the error messages as well.)r   r   r6   r   z-br3   z0use legacy (pre-PEP3147) compiled file locationsz-dDESTDIRr0   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   r6   r   z-sSTRIPDIRr$   zpart of path to left-strip from path to source file - for example buildroot. `-d` and `-s` options cannot be specified together.z-p
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-xREGEXPr2   zskip files matching the regular expression; the regexp is searched for in the full path of each file considered for compilationz-iFILEflistzzadd all the files and directories listed in FILE to the list considered for compilation; if "-", names are read from stdin)r   r   r   compile_destzFILE|DIR*zrzero or more file and directory names to compile; if no arguments given, defaults to the equivalent of -l sys.path)r   nargsr   z-jz	--workersr   zRun compileall concurrently)r6   r   r   _-z--invalidation-modezset .pyc invalidation mode; defaults to "checked-hash" if the SOURCE_DATE_EPOCH environment variable is set, and "timestamp" otherwise.)choicesr   z-oappend
opt_levelszOptimization levels to run compilation with. Default is -1 which uses the optimization level of the Python interpreter itself (see -O).)r   r   r   r   z-eDIRr&   z+Ignore symlinks pointing outsite of the DIRz--hardlink-dupesr'   zHardlink duplicated pyc filesrK   zYHardlinking of duplicated bytecode makes sense only for more than one optimization level.z.-d cannot be used in combination with -s or -pzutf-8)rw   r	   zError reading file list {}FT)r5   r$   r%   r4   r&   r'   )rC   r5   r$   r%   r4   r&   r'   )r3   r1   r   r5   z
[interrupted])/argparseArgumentParseradd_argumentr[   ro   PycInvalidationModer    lowerreplacer\   
parse_argsr   r2   rerp   r&   r   r   r   r^   r'   errorr0   r$   r%   r   r;   stdinrl   r   stripr   r   r   r   r5   upperr   r   rb   r   r1   r3   r   rC   r   KeyboardInterrupt)r   parsermodeinvalidation_modesargscompile_destsr   r   flineivl_moder5   rE   r   s                 r"   mainr   =  sr   $$G % IF
]! $;@  B 3[<  > \N  P
W7A;  < \O  Q
ivt,  .
 j
 $4  6 l, $4  6 hT4H  J f7B  D 
#A  C k1 'D  F '1&D&DF" ))//+33C= F F
- &'9 :7  9 XClK  M e/J  L
*<-<  > D%%Mww**TWW%R!~~!NN	NN	$
4??q T%8%8 C 	E yy!T__%@EF zz	#zz3#))g67;< 7D!((677 ))11#s;AAC&::8D G % (77>>$''diiTWW(,

DKK:K1537??156:6H6H7;7J7JL #(&tY		'+zz477DJJ'+{{DLL9J0426//04595G5G6:6I6IK #(+(, Nt{{$**&*jj2CE EuF`7 7  	zzA~299$**EF	R  ::>#$sV   51S46T 'S99T B#U 4B
U  U ,U 9T>T <UU#U.-U.__main__)r   )	NNFNr   Fr   r   N)NFNr   Fr   N)r   r   Fr   Fr   N)__doc__r   r;   importlib.utilrc   ro   rh   rq   	functoolsr   pathlibr   __all__r   r   r   r   r   r   r[   exit_statusexit r   r"   <module>r      s    
 
      
7.. 7<EF"&T48tETl CD(*#'S59d#ESj AB(*#'DVr z$&j/KCHH[ r   