U e5dFRã @sÆdZddlZddlZddlZddlZddlZddlZddlZe e ¡Z Gdd„dƒZ ddd„Z ddd „Z e d krÂd Zze ƒdZWn4ek r¶Zzed eejd W5dZ[XYnXe e¡dS)z› Virtual environment (venv) package for Python. Based on PEP 405. Copyright (C) 2011-2014 Vinay Sajip. Licensed to the PSF under a contributor agreement. éNc@sŠeZdZdZddd„Zdd„Zdd „Zd d „Zd d „Ze j dkrLddd„Z n d dd„Z dd„Z dd„Z dd„Zdd„Zdd„Zdd„ZdS)!Ú EnvBuildera– This class exists to allow virtual environment creation to be customized. The constructor parameters determine the builder's behaviour when called upon to create a virtual environment. By default, the builder makes the system (global) site-packages dir *un*available to the created environment. If invoked using the Python -m option, the default is to use copying on Windows platforms but symlinks elsewhere. If instantiated some other way, the default is to *not* use symlinks. :param system_site_packages: If True, the system (global) site-packages dir is available to created environments. :param clear: If True, delete the contents of the environment directory if it already exists, before environment creation. :param symlinks: If True, attempt to symlink rather than copy files into virtual environment. :param upgrade: If True, upgrade an existing virtual environment. :param with_pip: If True, ensure pip is installed in the virtual environment :param prompt: Alternative terminal prefix for the environment. FNcCs(||_||_||_||_||_||_dS©N©Úsystem_site_packagesÚclearÚsymlinksÚupgradeÚwith_pipÚprompt)Úselfrrrrr r ©r ú%/usr/lib64/python3.8/venv/__init__.pyÚ__init__+s zEnvBuilder.__init__cCsxtj |¡}| |¡}|j}d|_| |¡| |¡|jrF| |¡|j s`|  |¡|  |¡|rtd|_| |¡dS)zŠ Create a virtual environment in a directory. :param env_dir: The target directory to create an environment in. FTN) ÚosÚpathÚabspathÚensure_directoriesrÚcreate_configurationÚ setup_pythonr Ú _setup_piprÚ setup_scriptsÚ post_setup)r Úenv_dirÚcontextZtrue_system_site_packagesr r r Úcreate4s       zEnvBuilder.createcCs\t |¡D]L}tj ||¡}tj |¡s4tj |¡r@t |¡q tj |¡r t  |¡q dSr) rÚlistdirrÚjoinÚislinkÚisfileÚremoveÚisdirÚshutilZrmtree)r rÚfnr r r Úclear_directoryNs   zEnvBuilder.clear_directorycCsŽdd„}tj |¡r$|jr$| |¡t ¡}||_tj |¡d|_ |j dk rT|j n|j }d||_ ||ƒt j }tj tj  |¡¡\}}||_||_||_t jdkrÀd}d} tj |d d ¡} n(d }d } tj |d dt jdd…d ¡} tj || ¡|_} || ƒ|| ƒt jdkrXtjdkrXt jdkrXtj |d¡} tj | ¡sXt d | ¡tj ||¡|_} ||_tj | |¡|_|| ƒ|S)zª Create the directories for the environment. Returns a context object which holds paths in the environment, for use by subsequent logic. cSs@tj |¡st |¡n$tj |¡s0tj |¡r.create_if_neededéNz(%s) Zwin32ZScriptsZIncludeÚLibz site-packagesÚbinZincludeÚlibz python%d.%délÚposixÚdarwinÚlib64)rrr$rr#ÚtypesÚSimpleNamespacerÚsplitÚenv_namer ÚsysÚ_base_executablerÚ executableÚ python_dirZ python_exeÚplatformrÚ version_infoZinc_pathÚmaxsizeÚnameÚsymlinkÚbin_pathÚbin_nameÚenv_exe)r rr(rr r7ÚdirnameZexenameZbinnameZincpathZlibpathrZ link_pathÚbinpathr r r rVsL    þÿ zEnvBuilder.ensure_directoriesc Cs˜tj |jd¡|_}t|dddj}| d|j¡|jrBd}nd}| d|¡| d t j d d …¡|j d k rŠ| d |j ›d ¡W5QRXd S)aA Create a configuration file indicating where the environment's Python was copied from, and whether the system site-packages should be made available in the environment. :param context: The information for the environment creation request being processed. z pyvenv.cfgÚwúutf-8)Úencodingz home = %s ÚtrueZfalsez"include-system-site-packages = %s zversion = %d.%d.%d Néz prompt = Ú ) rrrrZcfg_pathÚopenÚwriter8rr5r:r )r rrÚfZinclr r r rŠs  zEnvBuilder.create_configurationÚntcCsš|j }|s†zRtj |¡s\|rPtj |¡tj |¡ks:t‚t tj |¡|¡n t ||¡Wn&tk r„t   d||¡d}YnX|r–t   ||¡dS)úY Try symlinking a file, and if that fails, fall back to copying. úUnable to symlink %r to %rTN) rrrrrAÚAssertionErrorr=ÚbasenameÚ ExceptionÚloggerÚwarningr!Úcopyfile)r ÚsrcÚdstÚrelative_symlinks_okZ force_copyr r r Úsymlink_or_copy s  zEnvBuilder.symlink_or_copycCs|tj |¡otj |¡ }|jrœ|sœtj |¡sœzH|rhtj |¡tj |¡ksRt‚t tj  |¡|¡n t ||¡WdSt k ršt   d||¡YnXtj  tj  |¡¡\}}tj tj t¡dd||¡}t d¡sêtj |¡sD| d¡r d|}|dd…}|dkrd }n|d kr(d }tj tj |¡||¡}n|}tj |¡sl|sht   d |¡dSt ||¡dS) rMNrNÚscriptsrLTZ_déþÿÿÿÚpythonZ venvlauncherZpythonwZ venvwlauncherzUnable to copy %r)rrÚlexistsr$rrrArOr=rPrQrRrSÚsplitextrÚ__file__Ú sysconfigÚis_python_buildrÚendswithr!rT)r rUrVrWZbad_srcrPZextZsrcfnr r r rX³s> ý     cCs¦|j}|j}|j}|j}tjdkr–||j|ƒtj |¡sFt  |d¡dD]F}tj  ||¡}tj  |¡sJ||j|ddtj |¡sJt  |d¡qJn |j rÊdd„t  |¡Dƒ}t d¡rÖdd„|Dƒ}n d d d d g}|D]2}tj  ||¡}tj |¡rÚ||tj  ||¡ƒqÚt d¡r¢t |j¡D]z\} } } d | kr&tj | ¡} tj  |jd| ¡} tj  | ¡spt | ¡tj  | d ¡}tj  | d ¡} t || ¡q¢q&dS)z· Set up a Python executable in the environment. :param context: The information for the environment creation request being processed. rLií)r[Zpython3T)rWcSs,g|]$}tj tj |¡d¡dkr|‘qS)r))ú.exez.dll)rrÚnormcaser]©Ú.0rKr r r Ú ûsÿz+EnvBuilder.setup_python..cSs"g|]}tj |¡ d¡r|‘qS))r[Z vcruntime)rrrcÚ startswithrdr r r rfsÿz python.exez python_d.exez pythonw.exez pythonw_d.exezinit.tclr*N)r>r@rXr8rr<r7rrÚchmodrr$rrr_r`r\ÚwalkrPrr%r!rT)r rrBrZcopierrAÚsuffixÚsuffixesrUÚrootÚdirsÚfilesZtcldirrVr r r rÞsP      ÿ ÿÿ      zEnvBuilder.setup_pythoncCs$|jddddg}tj|tjddS)z1Installs or upgrades pip in a virtual environmentz-ImZ ensurepipú --upgradez --default-pip)ÚstderrN)r@Ú subprocessZ check_outputZSTDOUT)r rÚcmdr r r rs ÿzEnvBuilder._setup_pipcCs2tj tj t¡¡}tj |d¡}| ||¡dS)a× Set up scripts into the created environment from a directory. This method installs the default scripts into the environment being created. You can prevent the default installation by overriding this method if you really need to, or if you need to specify a different location for the scripts to install. By default, the 'scripts' directory in the venv package is used as the source of scripts to install. rYN)rrrrAr^rÚinstall_scripts)r rrr r r r#s zEnvBuilder.setup_scriptscCsdS)a Hook for post-setup modification of the venv. Subclasses may install additional packages or scripts here, add activation shell scripts, etc. :param context: The information for the environment creation request being processed. Nr )r rr r r r2szEnvBuilder.post_setupcCsJ| d|j¡}| d|j¡}| d|j¡}| d|j¡}| d|j¡}|S)ai Replace variable placeholders in script text with context-specific variables. Return the text passed in , but with variables replaced. :param text: The text in which to replace placeholder variables. :param context: The information for the environment creation request being processed. Z __VENV_DIR__Z __VENV_NAME__Z__VENV_PROMPT__Z__VENV_BIN_NAME__Z__VENV_PYTHON__)Úreplacerr4r r?r@)r Útextrr r r Úreplace_variables<s zEnvBuilder.replace_variablesc Cs®|j}t|ƒ}t |¡D]Ž\}}}||krX|dd…D]}|dtjfkr8| |¡q8q|D]H} tjdkr‚|  d¡r‚|  d¡r‚q\tj  || ¡} ||d…  tj ¡dd…} | s¶|} ntjj |f| žŽ} tj  | ¡sÞt  | ¡tj  | | ¡} t| dƒ} |  ¡}W5QRX|  d¡srz$| d¡}| ||¡}| d¡}Wn6tk rp}zd}t d | |¡W5d}~XYnX|dk r\t| d ƒ} |  |¡W5QRXt | | ¡q\qdS) as Install scripts into the created environment from a directory. :param context: The information for the environment creation request being processed. :param path: Absolute pathname of a directory containing script. Scripts in the 'common' subdirectory of this directory, and those in the directory named for the platform being run on, are installed in the created environment. Placeholder variables are replaced with environment- specific values. NÚcommonrLr[)rbz.pdbr-ÚrbrDz+unable to copy script %r, may be binary: %sÚwb)r>Úlenrrir<rrgrarrr3Úsepr$r%rIÚreadÚdecodervÚencodeÚ UnicodeErrorrRrSrJr!Zcopymode)r rrrBZplenrlrmrnr'rKZsrcfilerjZdstdirZdstfileÚdataÚer r r rsNsL   ÿ      ÿ zEnvBuilder.install_scripts)FFFFFN)F)F)Ú__name__Ú __module__Ú __qualname__Ú__doc__rrr#rrrr<rXrrrrrvrsr r r r rs(ÿ 4   +<  rFcCs t|||||d}| |¡dS)z,Create a virtual environment in a directory.)rrrr r N)rr)rrrrr r Úbuilderr r r rsþrc Cs^d}tjdkrd}nttdƒs"d}|s2tdƒ‚n(ddl}|jtddd }|jd d d d d|jddddddtj dkr€d}nd}|  ¡}|jd|dddd|jd| dddd|jdddddd|jddddd d|jd!d"ddd#d$|jd%d&d'|  |¡}|j r"|j r"td(ƒ‚t|j|j |j|j |j|jd)}|jD]}| |¡qHdS)*NT)rGrGFÚ base_prefixz.This script is only for use with Python >= 3.3rzFCreates virtual Python environments in one or more target directories.z|Once an environment has been created, you may wish to activate it, e.g. by sourcing an activate script in its bin directory.)ÚprogZ descriptionZepilogrmZENV_DIRú+z)A directory to create the environment in.)ÚmetavarÚnargsÚhelpz--system-site-packagesÚ store_trueÚ system_sitezDGive the virtual environment access to the system site-packages dir.)ÚdefaultÚactionÚdestrŒrLz --symlinksrz[Try to use symlinks rather than copies, when symlinks are not the default for the platform.z--copiesZ store_falsez\Try to use copies rather than symlinks, even when symlinks are the default for the platform.z--clearrzcDelete the contents of the environment directory if it already exists, before environment creation.rorzlUpgrade the environment directory to use this version of Python, assuming Python has been upgraded in-place.z --without-pipr z]Skips installing or upgrading pip in the virtual environment (pip is bootstrapped by default))r‘rrrŒz--promptz;Provides an alternative prompt prefix for this environment.)rŒz1you cannot supply --upgrade and --clear together.r)r5r:Úhasattrr&ÚargparseÚArgumentParserr‚Ú add_argumentrr<Zadd_mutually_exclusive_groupÚ parse_argsrrrrŽrr r rmr) ÚargsZ compatibler“ÚparserZ use_symlinksÚgroupZoptionsr†r'r r r Úmain‰s|   û ÿþ þ þ ÿ ÿþÿ û ršÚ__main__r)z Error: %s)Úfile)FFFFN)N)r…Zloggingrr!rqr5r_r1Z getLoggerr‚rRrrršZrcrQrÚprintrpÚexitr r r r Ús2 qÿ  H$