Wc(Rcs 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)DistutilsByteCompileErrorcstjdkr}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'. ntZamd64 win-amd64z(arm) win-arm32z(arm64)z win-arm64Z_PYTHON_HOST_PLATFORMposixuname/z Z_z-NZlinuxZsunosrZ5Zsolarisz%d.%siZ32bitZ64bit)ilz.%sZaix) aix_platformiZcygwinz[\d.]+Zdarwin)osnamesysversionlowerZplatformenvironZhasattrr ZreplaceZintZmaxsizeZ _aix_supportrrecompileZASCIImatchgroup _osx_supportZdistutils.sysconfigZget_platform_osxZ sysconfigZget_config_vars) ZosnameZhostZreleaserZmachineZbitnessrZrel_remr distutilss '/usr/lib64/python3.12/distutils/util.pyget_host_platformrs( 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  '' 22cstjdkrCdddd}|jtjjdp t St S)NrZwin32rr)Zx86Zx64ZarmZVSCMD_ARG_TGT_ARCH)rrZgetrr)ZTARGET_TO_PLAT r get_platformr!csW ww$   !!"**..1E"FG^K\K^^ ""rcsbtjdkr|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. r rzpath '%s' cannot be absoluteizpath '%s' cannot end with '/'z.)rsep ValueErrorsplitremovecurdirpathjoin)pathnameZpaths r convert_pathr+ns vv}} 8{c7(BCC|s88CDD NN3 E ,, S ,, 5yy 77<< rcstjdkrhtjj|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. r Nrr\z!nothing known about platform '%s')rrr'Zisabsr(Z splitdriver)Znew_rootr)Zdriver' r change_rootr/s  ww'ww}}X&&77<<(3 377<<(12,7 7 D**84  7d??8Dww||Hd++%%H277%RSSrcstrdStjdkrVdtjvrC 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()') Nr ZHOMErr ZPLATr,) _environ_checkedrrrpwdZgetpwuidZgetuid ImportErrorKeyErrorr!)r1r r check_environr4s ww'fBJJ66  JJJ!$biik!:1!=BJJv  RZZ)^ 6X&    D sAB**B>=B>cst|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'. cs|jd}||vrt||Stj|S)Nr,)rstrrr)r local_varsZvar_name r_substzsubst_vars.._substs9;;q> z ! !z(+, ,::h' 'rz\$([a-zA-Z_][a-zA-Z_0-9]*)zinvalid variable '$%s'N)r4rZsubr3r#)sr6r8Zvarr.r subst_varsr:skOO",((((9vv3VQ?? 9991C7889s, A AA error: cs"|t|zSN)r5)Zexcprefixr*rgrok_environment_errorr>s CH rcstjdtjzatjdatjdadS)Nz [^\\\'\"%s ]*z'(?:[^'\\]|\\.)*'z"(?:[^"\\]|\\.)*")rrstring whitespace _wordchars_re _squote_re _dquote_rerr _init_regexrEs>JJ/&2C2CCDM01J01JJJrcst 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'z"z!this can't happen (bad char '%c')z"bad string (mismatched %s quotes?)r)rArEstriprendlenappendr?r@ZlstriprBrCZ RuntimeErrorr#Zspan)r9ZwordsZposrrGZbegs r split_quotedrJskmm  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 Lrcs|!|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. Niz,)rz))__name__rinfo)Zfuncargsmsgverbosedry_runs rexecuterQ!sc { tt, rs8t  a)c/CHHSMM 7 d  7rcs\|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. )ZyZyesZtZtrueZonZ1r,)ZnZnoZfZfalseZoffZ0rzinvalid truth value )rr#)Zvalr r strtoboolrR4sC ))+C 222q 5 5 5qjSS:;;rr,csddl}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'Zwz2from 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)rPz removing %s)rir )Z optimizationzinvalid prefix: filename z doesn't start with zbyte-compiling %s to %sz%skipping byte-compilation of %s to %s)% subprocessrZdont_write_bytecoderZtempfilerSr2rUrrLrZfdopenZopenwriter(ZmapZreprrZ_DEPRECATION_MESSAGEZ executableZextendZ"_optim_args_from_interpreter_flagsrIrrQr%Z py_compiler importlibZutilZcache_from_sourcerHr#r'Zbasenamerdebug)Zpy_filesZoptimizeZforcer=Zbase_dirrOrPZdirectrVrSZ script_fdZ script_namerUZscriptrNZcmdrZfileZoptZcfileZdfileZ cfile_bases r byte_compilerZDsH '(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;>LcsN|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 z )r$r()ZheaderZlinesr"r7r rfc822_escaper[s% LL E C 88E?rcs|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_packagecs eZdZdZdZdZdS)*run_2to3..DistutilsRefactoringToolc4tj|g|RdSr<)rZerror)selfrNrMZkwr.r log_errorz4run_2to3..DistutilsRefactoringTool.log_error" IIc !D ! ! ! ! ! !rcr_r<)rrLr`rNrMr7r log_messagez6run_2to3..DistutilsRefactoringTool.log_messages" HHS 4 rcr_r<)rrYrcr7r log_debugz4run_2to3..DistutilsRefactoringTool.log_debugrbrN)rK __module__ __qualname__rardrerDrrDistutilsRefactoringToolr^sA " " " ! ! ! " " " " "rrhz lib2to3.fixes)optionsT)rW)Zlib2to3.refactorr\r]Zrefactor)files fixer_namesriexplicitr\r]rhZrs rrun_2to3rms 5JIIIIIII"""""?""--o>   g>>AJJuDJ!!!!rcsBddlm}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,)ZupdatecsXg|]&}|jjds%|(S)rT)rZendswith)Z.0Zfnr*rz z$copydir_run_2to3..s- @ @ @RRXXZ%8%8%?%?bbb @r)rkrirl)Zdistutils.dir_utilrnZdistutils.file_utilroZdistutils.filelistrprZgetcwdZchdirZfindallZallfilesrjZ splitlinesrFZprocess_template_liner'r(ZdirnamerIrm)ZsrcZdestZtemplaterkrirlrnrorpZfilelistr&ZlineZcopiedZfilenameZoutnameZress rcopydir_run_2to3rqs*)))))------++++++xzH YY[FHHSMM  ))HNN11x'') 1 1D::rArBrCrErJrQrRrZr[rmrqrrrDrrrts   333333$$$$$$!!!!!!666666N3N3N3` # # #   8TTT,69992+/. . Z222 888z& < < <"%&(,%& S0S0S0S0n""""6<@,0BNNNNNNNNNr