B b^ªtÍq\×ã@sdZddlZddlZddlZddlZddlZddlmZddl m Z ddl m Z ddl mZddlmZdd „Zd d „Zd d „Zdadd„Zdd„Zd(dd„Zdaaadd„Zdd„Zd)dd„Zdd„Zd*dd„Zd d!„Zd+d"d#„Z d,d$d%„Z!Gd&d'„d'ƒZ"dS)-zudistutils.util Miscellaneous utility functions -- anything that doesn't fit into one of the other *util.py modules. éN)ÚDistutilsPlatformError)Únewer)Úspawn)Úlog)ÚDistutilsByteCompileErrorc Cs²tjdkr"dtj ¡krdStjSdtjkr6tjdStjdksJttdƒsPtjSt ¡\}}}}}| ¡  dd¡}|  d d ¡}|  dd ¡}|d d …dkr¦d||fS|d d …dkr|ddkr¤d}dt |dƒd|dd …f}dddœ}|d|tj 7}nœ|d d…dkr(d|||fS|d d…dkrfd}t   dt j¡}| |¡}|r¤| ¡}n>|d d…d kr¤dd l}dd l} | | j ¡|||¡\}}}d!|||fS)"aúReturn 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'. ÚntZamd64z win-amd64Z_PYTHON_HOST_PLATFORMÚposixÚunameú/Úú Ú_ú-NéZlinuxz%s-%sZsunosrÚ5Zsolarisz%d.%sééZ32bitZ64bit)iÿÿÿlÿÿÿÿz.%sZaixz%s-%s.%séÚcygwinz[\d.]+Údarwinz%s-%s-%s)ÚosÚnameÚsysÚversionÚlowerÚplatformÚenvironÚhasattrr ÚreplaceÚintÚmaxsizeÚreÚcompileÚASCIIÚmatchÚgroupÚ _osx_supportZdistutils.sysconfigZget_platform_osxZ sysconfigZget_config_vars) ZosnameZhostÚreleaserÚmachineZbitnessZrel_reÚmr&Ú distutils©r+ú3/opt/alt/python37/lib64/python3.7/distutils/util.pyÚ get_platformsD          r-cCs~tjdkr|S|s|S|ddkr.td|ƒ‚|ddkrFtd|ƒ‚| d¡}xd|krf| d¡qRW|srtjStjj|ŽS)aÎReturn '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 absoluteéÿÿÿÿzpath '%s' cannot end with '/'Ú.)rÚsepÚ ValueErrorÚsplitÚremoveÚcurdirÚpathÚjoin)ÚpathnameÚpathsr+r+r,Ú convert_path`s       r9cCsŽtjdkrc CsxtrdStjdkrZdtjkrZy$ddl}| t ¡¡dtjd<Wnttfk rXYnXdtjkrpt ƒtjd<dadS)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ÚHOMErrZPLATr:) Ú_environ_checkedrrrÚpwdÚgetpwuidÚgetuidÚ ImportErrorÚKeyErrorr-)rAr+r+r,Ú check_environ“s   rFc CsTtƒ|fdd„}yt d||¡Stk rN}ztd|ƒ‚Wdd}~XYnXdS)aàPerform 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'. cSs,| d¡}||krt||ƒStj|SdS)Nr:)r%Ústrrr)r$Ú local_varsZvar_namer+r+r,Ú_subst¸s  zsubst_vars.._substz\$([a-zA-Z_][a-zA-Z_0-9]*)zinvalid variable '$%s'N)rFr!ÚsubrEr1)ÚsrHrIÚvarr+r+r,Ú subst_vars®s  rMúerror: cCs |t|ƒS)N)rG)ÚexcÚprefixr+r+r,Úgrok_environment_errorÇsrQcCs(t dtj¡at d¡at d¡adS)Nz [^\\\'\"%s ]*z'(?:[^'\\]|\\.)*'z"(?:[^"\\]|\\.)*")r!r"ÚstringÚ whitespaceÚ _wordchars_reÚ _squote_reÚ _dquote_rer+r+r+r,Ú _init_regexÐs rWcCs†tdkrtƒ| ¡}g}d}x`|r€t ||¡}| ¡}|t|ƒkr\| |d|…¡P||tjkr’| |d|…¡||d…  ¡}d}nÔ||dkrÄ|d|…||dd…}|d}n¢||dkrÞt  ||¡}n*||dkrøt  ||¡}nt d||ƒ‚|dkr"t d||ƒ‚| ¡\}}|d|…||d|d…||d…}| ¡d }|t|ƒkr"| |¡Pq"W|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)rTrWÚstripr$ÚendÚlenÚappendrRrSÚlstriprUrVÚ RuntimeErrorr1Úspan)rKZwordsÚposr)r[Zbegr+r+r,Ú split_quotedÖs@         ,   rbcCsP|dkr6d|j|f}|dd…dkr6|dd…d}t |¡|sL||ŽdS)aœPerform 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%s%réþÿÿÿz,)rú))Ú__name__rÚinfo)ÚfuncÚargsÚmsgÚverboseÚdry_runr+r+r,Úexecutes  rlcCs2| ¡}|dkrdS|dkr dStd|fƒ‚dS)zôConvert 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. )ÚyZyesÚtÚtrueZonÚ1r:)ÚnZnoÚfZfalseZoffÚ0rzinvalid truth value %rN)rr1)Úvalr+r+r,Ú strtobool&s rur:cCsRddl}tjrtdƒ‚|dkr*do(|dk}|s8yddlm} | dƒ\} } Wn.tk rzddlm} d| dƒ} } YnXt  d| ¡|sð| dk r¢t   | d ¡} n t | d ƒ} |   d ¡|   d  tt|ƒ¡d ¡|   d |||||f¡|  ¡tjg}| | ¡¡| | ¡t||dtt j| fd| |dnddlm}x|D]þ}|dd…dkrfqL|dkr”|dkr~dn|}tjj||d}n tj |¡}|}|rà|dt|ƒ…|krÐtd||fƒ‚|t|ƒd…}|rôt j  ||¡}t j  !|¡}|rL|st"||ƒr:t  d||¡|sH||||ƒnt #d||¡qLWdS)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.T)Úmkstempz.py)Úmktempz$writing byte-compilation script '%s'Úwz2from distutils.util import byte_compile files = [ z, z] zŒ byte_compile(files, optimize=%r, force=%r, prefix=%r, base_dir=%r, verbose=%r, dry_run=0, direct=1) )rkz removing %s)r"éýÿÿÿr )Ú optimizationz1invalid prefix: filename %r doesn't start with %rzbyte-compiling %s to %sz%skipping byte-compilation of %s to %s)$Ú subprocessrÚdont_write_bytecoderZtempfilervrDrwrrfrÚfdopenÚopenÚwriter6ÚmapÚreprÚcloseÚ executableÚextendZ"_optim_args_from_interpreter_flagsr]rrlr3Ú py_compiler"Ú importlibÚutilÚcache_from_sourcer\r1r5ÚbasenamerÚdebug)Zpy_filesÚoptimizeZforcerPZbase_dirrjrkZdirectr{rvZ script_fdZ script_namerwZscriptÚcmdr"ÚfileZoptÚcfileÚdfileZ cfile_baser+r+r,Ú byte_compile6sl$                rcCs| d¡}d}| |¡S)zŒReturn a version of the string escaped for inclusion in an RFC-822 header, by ensuring there are 8 spaces space after each newline. Ú z )r2r6)ÚheaderÚlinesr0r+r+r,Ú rfc822_escapeÌs r”cCsV|sdSddlm}m}Gdd„d|ƒ}|dkr8|dƒ}|||d}|j|dd 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)ÚRefactoringToolÚget_fixers_from_packagec@s$eZdZdd„Zdd„Zdd„ZdS)z*run_2to3..DistutilsRefactoringToolc_stj|f|žŽdS)N)rÚerror)ÚselfrirhÚkwr+r+r,Ú log_errorãsz4run_2to3..DistutilsRefactoringTool.log_errorcWstj|f|žŽdS)N)rrf)r˜rirhr+r+r,Ú log_messageæsz6run_2to3..DistutilsRefactoringTool.log_messagecWstj|f|žŽdS)N)rrŠ)r˜rirhr+r+r,Ú log_debugész4run_2to3..DistutilsRefactoringTool.log_debugN)reÚ __module__Ú __qualname__ršr›rœr+r+r+r,ÚDistutilsRefactoringToolâsrŸz lib2to3.fixes)ÚoptionsT)r)Zlib2to3.refactorr•r–Zrefactor)ÚfilesÚ fixer_namesr Úexplicitr•r–rŸÚrr+r+r,Úrun_2to3Ös  r¥c Csddlm}ddlm}ddlm}|ƒ} t ¡} t |¡z |   ¡Wdt | ¡X| j | j dd…<|r”x(|  ¡D]} |   ¡} | s†qt|  | ¡qtWg} xV| j D]L} tj || ¡}|tj |¡ƒ|tj || ¡|dd}|dr |  |¡q Wtdd „| Dƒ|||d | S) zÏRecursively 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:)ÚupdatecSsg|]}| ¡ d¡r|‘qS)z.py)rÚendswith)Ú.0Úfnr+r+r,ú sz$copydir_run_2to3..)r¢r r£)Zdistutils.dir_utilr¦Zdistutils.file_utilr§Zdistutils.filelistr¨rÚgetcwdÚchdirÚfindallZallfilesr¡Ú splitlinesrZZprocess_template_liner5r6Údirnamer]r¥)ÚsrcÚdestÚtemplater¢r r£r¦r§r¨Zfilelistr4ÚlineZcopiedÚfilenameZoutnameZresr+r+r,Úcopydir_run_2to3ñs4        r¸c@s$eZdZdZdZdZdZdd„ZdS)Ú Mixin2to3zÀMixin class for commands that run 2to3. To configure 2to3, setup scripts may either change the class variables, or inherit from individual commands to override how 2to3 is invoked.NcCst||j|j|jƒS)N)r¥r¢r r£)r˜r¡r+r+r,r¥"szMixin2to3.run_2to3)rerržÚ__doc__r¢r r£r¥r+r+r+r,r¹s r¹)rN)Nrr)rrNNr:rN)NNN)NNNN)#rºrr!Úimportlib.utilr†rRrZdistutils.errorsrZdistutils.dep_utilrZdistutils.spawnrr*rrr-r9r>r@rFrMrQrTrUrVrWrbrlrurr”r¥r¸r¹r+r+r+r,Ús@     N  =