_dFVdZddlZddlZddlZddlZddlZddlZddlZddl Z ddl m Z m Z ddl mZddlmZddlmZdZd Zej(d k(rdad Zd Zd ZdZdZdZdZe j:dZdZdZ ddZ!dxa"xa#a$dZ%dZ&ddZ'dZ( ddZ)dZ*y)zudistutils.util Miscellaneous utility functions -- anything that doesn't fit into one of the other *util.py modules. N)DistutilsPlatformErrorDistutilsByteCompileError)newer)spawn)logctjdkrUtjdk(rBdtjj vrydtjj vrytjdkrUtjdk(rBt td r2tj\}}}}}|d d d k(rd dlm }||||StjS)z Return a string that identifies the current platform. Use this function to distinguish platform-specific build directories and platform-specific built distributions. )ntz(arm) win-arm32z(arm64) win-arm64)r posixunameNr aixr) aix_platform) sys version_infoosnameversionlowerhasattrr py38compatr sysconfig get_platform)osnamehostreleasermachiners -@@  r$darwinMACOSX_DEPLOYMENT_TARGETcday)zFor testing only. Do not call.N)_syscfg_macosx_verr$r"_clear_cached_macosx_verr5Es r$cbt$ddlm}|jtxsd}|r|atS)zGet the version of macOS latched in the Python interpreter configuration. Returns the version as a string or None if can't obtain one. Cached.r)r)r3 distutilsrget_config_varMACOSX_VERSION_VAR)rvers r"!get_macosx_target_ver_from_syscfgr<Ks4!'&i&&'9:@b !$  r$ct}tjjt}|rB|r>t |ddgk\r.t |ddgkrdtzd|d|dz}t ||S|S)aReturn the version of macOS for which we are building. The target version defaults to the version in sysconfig latched at time the Python interpreter was built, unless overridden by an environment variable. If neither source has a value, then None is returned r $z mismatch: now "z" but "z*" during configure; must use 10.3 or later)r<rr,r-r: split_versionr) syscfg_verenv_vermy_msgs r"get_macosx_target_verrDXs34Jjjnn/0G j)b!W4g&"a0((,3Z,AA  )0 0 r$c\|jdDcgc] }t|c}Scc}w)zEConvert a dot-separated string into a list of numbers for comparisons.)splitint)sns r"r@r@xs"GGCL )qCF )) )s)c>tjdk(r|S|s|S|ddk(rtd|z|ddk(rtd|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. /rzpath '%s' cannot be absolutezpath '%s' cannot end with '/'rF)rsep ValueErrorrGremovecurdirpathjoin)pathnamepathss r" convert_pathrV}s vv} {c7(BCC|s88CDD NN3 E , S , yy 77<< r$ctjdk(rbtjj|s tjj ||Stjj ||ddStjdk(rOtjj |\}}|ddk(r|dd}tjj ||St dtjd) 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. rrNr r\znothing known about platform '')rrrRisabsrS splitdriver)new_rootrTdriverRs r" change_rootr^s  ww'ww}}X&77<<(3 377<<(12,7 7 D**84  7d?8Dww||Hd++ #A"''!!L MMr$cLtjdk(rNdtjvr< ddl}|j tj dtjd<dtjvrttjd<yy#t tf$rY@wxYw)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()') rHOMErNPLAT) rrr,pwdgetpwuidgetuid ImportErrorKeyErrorr)rcs r" check_environrhs ww'fBJJ6  !$biik!:1!=BJJv  RZZ)^ 6 X&   s;BB#"B#ctttj}|j d|j D t |j|S#t$r}td|d}~wwxYw)a Perform variable substitution on 'string'. Variables are indicated by format-style braces ("{var}"). 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'. c3<K|]\}}|t|fywNstr).0rvalues r" zsubst_vars..sKu4U$Kszinvalid variable N) rhdictrr,updateitems _subst_compat format_maprgrO)rI local_varslookupvars r" subst_varsryspO "** F MMK 8H8H8JKK4Q**622 4,SE2334s A%% B.A<<Bcxd}tjd||}||k7rddl}|jdt|S)zb Replace shell/Perl-style variable substitution with format-style. For compatibility. c,d|jddS)N{r})group)matchs r"_substz_subst_compat.._substsEKKN#2&&r$z\$([a-zA-Z_][a-zA-Z_0-9]*)rNz-shell/Perl-style substitutions are deprecated)resubwarningswarnDeprecationWarning)rIrreplrs r"rtrts? ' 66/ ;D qy ;   Kr$c|t|zSrkrl)excprefixs r"grok_environment_errorrs CH r$ctjdtjzatjdatjday)Nz [^\\\'\"%s ]*z'(?:[^'\\]|\\.)*'z"(?:[^"\\]|\\.)*")rcompilestring whitespace _wordchars_re _squote_re _dquote_rer4r$r" _init_regexrs:JJ/&2C2CCDM01J01Jr$c*t t|j}g}d}|rktj||}|j }|t |k(r|j |d| |S||tjvr*|j |d|||dj}d}n||dk(r|d|||dzdz}|dz}n||dk(rtj||}n0||dk(rtj||}ntd||z|td||z|j\}}|d|||dz|dz z||dz}|j d z }|t |k\r|j | |S|rk|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. NrrXrrY"z!this can't happen (bad char '%c')z"bad string (mismatched %s quotes?))rrstriprendlenappendrrlstriprr RuntimeErrorrOspan)rIwordsposmrbegs r" split_quotedrs   A E C   3 'eeg #a&= LL4C ! D LA S6V&& & LL4C !#$ AC sVt^$3!C!GI,&A'Cv}$$Q,33$$Q,"#F3#OPPy !E#!NOOJS#$3!C!GcAg..348A%%'A+C #a&= LLO  LO N Lr$c|,dj|j|}|dddk(r|dddz}tj||s||yy)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}z,)r))format__name__rinfo)funcargsmsgverbosedry_runs r"executerAsT {oodmmT2 rs8t a)c/CHHSM  d  r$cj|j}|dvry|dvrytdj|)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)rJnoffalseoff0rzinvalid truth value {!r})rrOr)vals r" strtoboolrTs> ))+C 22 5 53::3?@@r$c^tjr td||dk(}|s1 ddlm}|d\} } tjd| |s| tj| d} n t| d} | 5| jd | jd jtt|d z| jd |d |d|d|d|d dddtj g} | j#t%j&| j)| t+| |t-tj.| fd| z|yddlm}|D]}|dddk7r |dk\r+|dk(rdn|}t4j6j9||}nt4j6j9|}|}|r0|dt;||k7rt=d|d||t;|d}|r tj>j||}tj>jA|}|s|s tC||r&tjd|||r||||tjDd||!y#t $rddlm} d| d} } YfwxYw#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. zbyte-compiling is disabled.Nr)mkstempz.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) )rz removing %s)rr7) optimizationzinvalid prefix: filename z doesn't start with zbyte-compiling %s to %sz%skipping byte-compilation of %s to %s)#rdont_write_bytecodertempfilerrfrrrrfdopenopenwriterSmaprepr executableextend subprocess"_optim_args_from_interpreter_flagsrrrrP py_compiler importlibutilcache_from_sourcerrOrRbasenamerdebug)py_filesoptimizeforcerbase_dirrrdirectr script_fd script_namerscriptcmdrfileoptcfiledfile cfile_bases r" byte_compilerdswP '(EFF~'1}  ; ('.u~ $Y 7E$9c2k3/  " UZZD((;=;+FPWX ' YDBCyE! 1}$Mbx!88C8P!88>E #f+&&0$)c&km, Xu5))%0JE$.HH6jI"eU3IIEtZXA Yk ; ''+VE] Y ;  sJ7A$J"JJ"J,cJ|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 )rGrS)headerlinesrNs r" rfc822_escapers% LL E C 88E?r$)zerror: )Nrr)rrNNrrN)+__doc__importlib.utilrrrrrrr functoolserrorsrrdep_utilrr_logrr#rplatformr3r:r5r<rDr@rVr^ lru_cacherhryrtrrrrrrrrrrr4r$r"rs   E$: <<8/ @*  :N*,,,4&(+/. . Z2<D& A$   TYnr$