Wc(R dZddlZddlZddlZddlZddlZddlZddlm Z ddl m Z ddl m Z ddlmZddlmZdZd Zd Zd Zdad Zd ZddZdxaxaadZdZddZdZ ddZdZ ddZ! ddZ"GddZ#dS) zudistutils.util Miscellaneous utility functions -- anything that doesn't fit into one of the other *util.py modules. N)DistutilsPlatformError)newer)spawn)log)DistutilsByteCompileErrorctjdkr}dtjj vrdSdtjj vrdSdtjj vrdStj Sdtj vrtj dStjd ksttd stj Stj\}}}}}|j jd d }|jd d}|jd d}|dddkr|d|S|dddkrO|ddkrd}dt|ddz |ddfz}ddd}|d|tjzz }n|dddkrddl m }|S|dd d!krOd!}tjd"tj }|j#|}|rU|j%}nC|dd d#kr:ddl} ddl} | j+| j,j/|||\}}}|d|d|S)$aReturn a string that identifies the current platform. This is used mainly to distinguish platform-specific build directories and platform-specific built distributions. Typically includes the OS name and version and the architecture (as supplied by 'os.uname()'), although the exact information included depends on the OS; eg. on Linux, the kernel version isn't particularly important. Examples of returned values: linux-i586 linux-alpha (?) solaris-2.6-sun4u Windows will return one of: win-amd64 (64bit Windows on AMD64 (aka x86_64, Intel64, EM64T, etc) win32 (all others - specifically, sys.platform is returned) For other non-POSIX platforms, currently just returns 'sys.platform'. ntamd64 win-amd64z(arm) win-arm32z(arm64)z win-arm64_PYTHON_HOST_PLATFORMposixuname/ _-Nlinuxsunosr5solarisz%d.%s32bit64bit)ilz.%saix) aix_platformcygwinz[\d.]+darwin)osnamesysversionlowerplatformenvironhasattrrreplaceintmaxsize _aix_supportrrecompileASCIImatchgroup _osx_supportdistutils.sysconfigget_platform_osx sysconfigget_config_vars) osnamehostreleaser&machinebitnessrrel_remr4 distutilss '/usr/lib64/python3.12/distutils/util.pyget_host_platformrBs( ww$ ckk'') ) ); ckk'') ) );  ))+ + +;||"**,,zz122 ww'W!5!5||13 -VT7GW\\^ # #C ,Fooc3'Gooc3'G bqzW"6677++ w   1:  FWQZ1!4gabk BBG#*wGGG uws{{33 3GG u  ------|~ x  Y1 LL ! 1ggiGG x  00000000#/#@#@(1(;(;(K(K(M(.$B  '' 22ctjdkrCdddd}|jtjjdp t St S)Nr win32r r )x86x64armVSCMD_ARG_TGT_ARCH)r#r$getr)rB)TARGET_TO_PLATs rA get_platformrLcsW ww$   !!"**..1E"FG^K\K^^ ""rCcbtjdkr|S|s|S|ddkrtd|z|ddkrtd|z|jd}d|vr|j dd|vr|stj Stj j|S)aReturn 'pathname' as a name that will work on the native filesystem, i.e. split it on '/' and put it back together again using the current directory separator. Needed because filenames in the setup script are always supplied in Unix style, and have to be converted to the local convention before we can actually use them in the filesystem. Raises ValueError on non-Unix-ish systems if 'pathname' either starts or ends with a slash. rrzpath '%s' cannot be absolutezpath '%s' cannot end with '/'.)r#sep ValueErrorsplitremovecurdirpathjoin)pathnamepathss rA convert_pathrYns vv}} 8{c7(BCC|s88CDD NN3 E ,, S ,, 5yy 77<< rCctjdkrhtjj|s"tjj ||Stjj ||ddStjdkrWtjj |\}}|ddkr|dd}tjj ||St dtjz)a Return 'pathname' with 'new_root' prepended. If 'pathname' is relative, this is equivalent to "os.path.join(new_root,pathname)". Otherwise, it requires making 'pathname' relative and then joining the two, which is tricky on DOS/Windows and Mac OS. rNr r\z!nothing known about platform '%s')r#r$rUisabsrV splitdriver)new_rootrWdriverUs rA change_rootras  ww'ww}}X&&77<<(3 377<<(12,7 7 D**84  7d??8Dww||Hd++%%H277%RSSrCctrdStjdkrVdtjvrC ddl}|j tj dtjd<dtjvrttjd<dadS#ttf$rYHwxYw)aLEnsure that 'os.environ' has all the environment variables we guarantee that users can use in config files, command-line options, etc. Currently this includes: HOME - user's home directory (Unix only) PLAT - description of the current platform, including hardware and OS (see 'get_platform()') NrHOMErrPLATr[) _environ_checkedr#r$r)pwdgetpwuidgetuid ImportErrorKeyErrorrL)rfs rA check_environrks ww'fBJJ66  JJJ!$biik!:1!=BJJv  RZZ)^ 6X&    D sAB**B>=B>ct|fd} tjd||S#t$r}t d|zd}~wwxYw)aPerform shell/Perl-style variable substitution on 'string'. Every occurrence of '$' followed by a name is considered a variable, and variable is substituted by the value found in the 'local_vars' dictionary, or in 'os.environ' if it's not in 'local_vars'. 'os.environ' is first checked/augmented to guarantee that it contains certain values: see 'check_environ()'. Raise ValueError for any variables not found in either 'local_vars' or 'os.environ'. c|jd}||vrt||Stj|S)Nr[)r3strr#r))r2 local_varsvar_names rA_substzsubst_vars.._substs9;;q> z ! !z(+, ,::h' 'rCz\$([a-zA-Z_][a-zA-Z_0-9]*)zinvalid variable '$%s'N)rkr/subrjrQ)srorqvars rA subst_varsruskOO",((((9vv3VQ?? 9991C7889s, A AA error: c"|t|zSN)rn)excprefixs rAgrok_environment_errorr{s CH rCctjdtjzatjdatjdadS)Nz [^\\\'\"%s ]*z'(?:[^'\\]|\\.)*'z"(?:[^"\\]|\\.)*")r/r0string whitespace _wordchars_re _squote_re _dquote_rerCrA _init_regexrs>JJ/&2C2CCDM01J01JJJrCct t|j}g}d}|rtj||}|j }|t |kr|j |d| |S||tjvr,|j |d|||dj}d}n||dkr|d|||dzdz}|dz}n||dkrtj||}n;||dkrtj||}ntd||z|td||z|j\}}|d|||dz|dz z||dz}|j d z }|t |kr|j | |S|r|S) aSplit a string up according to Unix shell-like rules for quotes and backslashes. In short: words are delimited by spaces, as long as those spaces are not escaped by a backslash, or inside a quoted string. Single and double quotes are equivalent, and the quote characters can be backslash-escaped. The backslash is stripped from any two-character escape sequence, leaving only the escaped character. The quote characters are stripped from any quoted string. Returns a list of words. Nrr\r['"z!this can't happen (bad char '%c')z"bad string (mismatched %s quotes?)r)rrstripr2endlenappendr}r~lstriprr RuntimeErrorrQspan)rswordsposr?rbegs rA split_quotedrskmm  A E C !   3 'eeg #a&== LL4C ! ! > L; S6V&& & & LL4C ! !#$ ACC sVt^^$3!CEF)#Aa%CCv}}$$Q,33$$Q,"#F3#OPPy !E#!NOOJS#$3!CE#a%.(1ST72A%%'A+C #a&== LLOO  LI !H LrCc|!|j|}|dddkr|dddz}tj||s||dSdS)aPerform some action that affects the outside world (eg. by writing to the filesystem). Such actions are special because they are disabled by the 'dry_run' flag. This method takes care of all that bureaucracy for you; all you have to do is supply the function to call and an argument tuple for it (to embody the "external action" being performed), and an optional message to print. Nz,)r))__name__rinfo)funcargsmsgverbosedry_runs rAexecuter!sc { tt, rs8t  a)c/CHHSMM 7 d  7rCc\|j}|dvrdS|dvrdStd|)zConvert a string representation of truth to true (1) or false (0). True values are 'y', 'yes', 't', 'true', 'on', and '1'; false values are 'n', 'no', 'f', 'false', 'off', and '0'. Raises ValueError if 'val' is anything else. )yyesttrueon1r[)nnoffalseoff0rzinvalid truth value )r'rQ)vals rA strtoboolr4sC ))+C 222q 5 5 5qjSS:;;rCr[cddl}tjr td|d}|sm ddlm} | d\} } tjd| |s| tj| d } nt| d } | 5| jd | jd jtt |d z| jd |d|d|d|d|d dddt"j$}tj&g}|j)|j+|j-d|d|j-| t/||t1tj2| fd| z|dSddlm}|D]8}|dddkr|dkr.|dkrdn|}t8j:j=||}n!t8j:j=|}|}|r7|dt?||krtAd|d||t?|d}|r"tjBj||}tjBjE|}|s|stG||r*tjd|||r|||| tjHd||;dS#t $rddlm} d| d} } YwxYw#1swYxYw)a~Byte-compile a collection of Python source files to .pyc files in a __pycache__ subdirectory. 'py_files' is a list of files to compile; any files that don't end in ".py" are silently skipped. 'optimize' must be one of the following: 0 - don't optimize 1 - normal optimization (like "python -O") 2 - extra optimization (like "python -OO") If 'force' is true, all files are recompiled regardless of timestamps. The source filename encoded in each bytecode file defaults to the filenames listed in 'py_files'; you can modify these with 'prefix' and 'basedir'. 'prefix' is a string that will be stripped off of each source filename, and 'base_dir' is a directory name that will be prepended (after 'prefix' is stripped). You can supply either or both (or neither) of 'prefix' and 'base_dir', as you wish. If 'dry_run' is true, doesn't actually do anything that would affect the filesystem. Byte-compilation is either done directly in this interpreter process with the standard py_compile module, or indirectly by writing a temporary script and executing it. Normally, you should let 'byte_compile()' figure out to use direct compilation or not (see the source for details). The 'direct' flag is used by the script generated in indirect mode; unless you know what you're doing, leave it set to None. rNzbyte-compiling is disabled.F)mkstemp.py)mktempz$writing byte-compilation script '%s'wz2from distutils.util import byte_compile files = [ z, z] z byte_compile(files, optimize=z, force=z, prefix=z , base_dir=z, verbose=z$, dry_run=0, direct=1) z -Wignore:z:DeprecationWarning)rz removing %s)r0r) optimizationzinvalid prefix: filename z doesn't start with zbyte-compiling %s to %sz%skipping byte-compilation of %s to %s)% subprocessr%dont_write_bytecodertempfilerrirrrr#fdopenopenwriterVmapreprr@_DEPRECATION_MESSAGE executableextend"_optim_args_from_interpreter_flagsrrrrS py_compiler0 importlibutilcache_from_sourcerrQrUbasenamerdebug)py_filesoptimizeforcerzbase_dirrrdirectrr script_fd script_namerscriptrcmdr0fileoptcfiledfile cfile_bases rA byte_compilerDsH '(EFF~ 6 ; ( ( ( ( ( ('.wu~ $Y  7EEw$9c2k3/ 4 4 & UZZD((;=;+F ! ! ! ! ! '&&&&& 0 0DBCyE!! 1}}$MMbbx!88s9,"88>Ev V%//$*"ddFF&,--c&kl+x Xu5))%0Jv5E$..HH6jII"7eU333IIE"J000? 0 0m ; ; ; ' ' ' ' ' ''+VVE] YYY ; 4 4 4 4 4 4 4 4 4sKA+K>K;:K;>LcN|jd}d}|j|S)zReturn a version of the string escaped for inclusion in an RFC-822 header, by ensuring there are 8 spaces space after each newline.  z )rRrV)headerlinesrPs rA rfc822_escapers% LL E C 88E?rCc|sdSddlm}m}Gdd|}| |d}|||}|j|d dS) a Invoke 2to3 on a list of Python files. The files should all come from the build area, as the modification is done in-place. To reduce the build time, only files modified since the last invocation of this function should be passed in the files argument.Nr)RefactoringToolget_fixers_from_packagec eZdZdZdZdZdS)*run_2to3..DistutilsRefactoringToolc4tj|g|RdSrx)rerror)selfrrkws rA log_errorz4run_2to3..DistutilsRefactoringTool.log_error" IIc !D ! ! ! ! ! !rCc4tj|g|RdSrx)rrrrrs rA log_messagez6run_2to3..DistutilsRefactoringTool.log_messages" HHS 4 rCc4tj|g|RdSrx)rrrs rA log_debugz4run_2to3..DistutilsRefactoringTool.log_debugrrCN)r __module__ __qualname__rrrrrCrADistutilsRefactoringToolrsA " " " ! ! ! " " " " "rCrz lib2to3.fixes)optionsT)r)lib2to3.refactorrrrefactor)files fixer_namesrexplicitrrrrs rArun_2to3rs 5JIIIIIII"""""?""--o>   g>>AJJuDJ!!!!rCcBddlm}ddlm}ddlm}|} t j} t j| | jt j| | j| jdd|r;|jD](} | j} | s| j| *g} | jD]} t jj!|| }|t jj#||t jj!|| |d}|ds| j%|t'd| D||| | S#t j| wxYw) zRecursively copy a directory, only copying new and changed files, running run_2to3 over all newly copied Python modules afterward. If you give a template string, it's parsed like a MANIFEST.in. r)mkpath) copy_file)FileListNr[)updatecXg|]&}|jjds%|(S)r)r'endswith).0fns rA z$copydir_run_2to3..s- @ @ @RRXXZ%8%8%?%?bbb @rC)rrr)distutils.dir_utilrdistutils.file_utilrdistutils.filelistrr#getcwdchdirfindallallfilesr splitlinesrprocess_template_linerUrVdirnamerr)srcdesttemplaterrrrrrfilelistrTlinecopiedfilenameoutnameress rAcopydir_run_2to3rs*)))))------++++++xzH YY[FHHSMM  ))HNN11x'') 1 1D::rs   333333$$$$$$!!!!!!666666N3N3N3` # # #   8TTT,69992+/. . Z222 888z& < < <"%&(,%& S0S0S0S0n""""6<@,0BNNNNNNNNNrC