a RÛf­Zã @sÌdZddlZddlZddlZddlZddlZddlZddlZdZe  e ¡Z Gdd„dƒZ ddd„Z dd d „Ze d krÈd ZzeƒdZWn6ey¼Zzed eejdWYdZ[n dZ[00e 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. éN)ÚpipZ setuptoolsc@s’eZdZdZd dd„Zdd„Zdd „Zd d „Zd d „Ze j dkrLd!dd„Z n d"dd„Z dd„Z dd„Z dd„Zdd„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. :param upgrade_deps: Update the base venv modules to the latest on PyPI FNcCsF||_||_||_||_||_|dkr6tj t ¡¡}||_ ||_ dS)NÚ.) Úsystem_site_packagesÚclearÚsymlinksÚupgradeÚwith_pipÚosÚpathÚbasenameÚgetcwdÚpromptÚ upgrade_deps)Úselfrrrrr rr©rú2/opt/alt/python39/lib64/python3.9/venv/__init__.pyÚ__init__.szEnvBuilder.__init__cCsˆtj |¡}| |¡}|j}d|_| |¡| |¡|jrF| |¡|j s`|  |¡|  |¡|rtd|_| |¡|j r„|  |¡dS)zŠ Create a virtual environment in a directory. :param env_dir: The target directory to create an environment in. FTN)r r ÚabspathÚensure_directoriesrÚcreate_configurationÚ setup_pythonr Ú _setup_piprÚ setup_scriptsÚ post_setuprÚupgrade_dependencies)rÚenv_dirÚcontextZtrue_system_site_packagesrrrÚcreate;s         zEnvBuilder.createcCs\t |¡D]L}tj ||¡}tj |¡s4tj |¡r@t |¡q tj |¡r t  |¡q dS)N) r Úlistdirr ÚjoinÚislinkÚisfileÚremoveÚisdirÚshutilZrmtree)rr ÚfnrrrÚclear_directoryWs   zEnvBuilder.clear_directorycCsâdd„}tj |¡r$|jr$| |¡t ¡}||_tj |¡d|_ |j durT|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 | |¡|_|| ƒ|j|_t jdkrÞtj |j¡}tj |¡tj |j¡krÞt d|j|¡||_|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ÚdarwinZlib64z†Actual environment location may have moved due to redirects, links or junctions. Requested location: "%s" Actual location: "%s") r r r(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Ú env_exec_cmdÚrealpathÚnormcaseÚloggerÚwarning)rrr,rrr:ÚdirnameZexenameZbinnameZincpathZlibpathr Z link_pathÚbinpathZ real_env_exerrrr_s\    þÿ  üzEnvBuilder.ensure_directoriescCs¬tj |jd¡|_}t|dddt}| d|j¡|jrBd}nd}| d|¡| d t j d d …¡|j d urŠ| d |j ›d ¡Wd ƒn1sž0Yd 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 = Ú ) r r r rZcfg_pathÚopenÚwriter;rr8r=r)rrr ÚfZinclrrrr¡s  zEnvBuilder.create_configurationÚntcCs||j }|shz6tj |¡s@|r4t tj |¡|¡n t ||¡Wn$tyft d||¡d}Yn0|rxt   ||¡dS)úY Try symlinking a file, and if that fails, fall back to copying. úUnable to symlink %r to %rTN) rr r r!r@r Ú ExceptionrGrHr%Úcopyfile)rÚsrcÚdstÚrelative_symlinks_okZ force_copyrrrÚsymlink_or_copy·s   zEnvBuilder.symlink_or_copycCsZtj |¡otj |¡ }|jr~|s~tj |¡s~z,|rLt tj |¡|¡n t ||¡WdSty|t   d||¡Yn0tj  tj |¡¡\}}tj  tj  t¡dd||¡}t d¡sÌtj |¡s"| d¡rêd|}|dd…}|dkrød }n|d krd }tj  tj  |¡||¡}n|}tj |¡sJ|sFt   d |¡dSt ||¡dS) rUNrVÚscriptsrTTZ_déþÿÿÿÚpythonZ venvlauncherZpythonwZ venvwlauncherzUnable to copy %r)r r Úlexistsr(rr!r@r rWrGrHÚsplitextr rIÚ__file__Ú sysconfigÚis_python_buildr"Úendswithr%rX)rrYrZr[Zbad_srcr ZextZsrcfnrrrr\Ês<  ý    cCsÐ|j}|j}|j}|j}tjdkr¨||j|ƒtj |¡sFt  |d¡dddt j d›fD]F}tj  ||¡}tj  |¡s\||j|ddtj |¡s\t  |d¡q\n$|jrÜd d „t |¡Dƒ}t d¡rüd d „|Dƒ}n hd £}tj |j¡}| |¡|D]6}tj  ||¡} tj | ¡r|| tj  ||¡ƒqt d¡rÌt |j¡D]z\} } } d | vrPtj | ¡} tj  |jd| ¡} tj  | ¡sšt | ¡tj  | d ¡} tj  | d ¡}t | |¡qÌqPdS)z· Set up a Python executable in the environment. :param context: The information for the environment creation request being processed. rTiír_Zpython3zpython3.r-T)r[cSs,g|]$}tj tj |¡d¡dvr|‘qS)r-)ú.exez.dll)r r rFra©Ú.0rSrrrÚ sÿz+EnvBuilder.setup_python..cSs"g|]}tj |¡ d¡r|‘qS))r_Z vcruntime)r r rFÚ startswithrgrrrrisÿ>z pythonw.exez python_d.exez python.exez pythonw_d.exezinit.tclr.N)rArCr\r;r r?r:r r!Úchmodr8r=r r(rrrcrdr Úaddr`Úwalkrr)r%rX)rrrJr ZcopierrIÚsuffixÚsuffixesZbase_exerYÚrootÚdirsÚfilesZtcldirrZrrrrõsP      ÿ ÿ      zEnvBuilder.setup_pythoncCs$|jddddg}tj|tjddS)z1Installs or upgrades pip in a virtual environmentz-ImZ ensurepipú --upgradez --default-pip)ÚstderrN)rDÚ subprocessZ check_outputZSTDOUT©rrÚcmdrrrr2s ÿ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. r]N)r r rrIrbr Úinstall_scripts)rrr rrrr;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)rrrrrrJszEnvBuilder.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__)Úreplacerr7rrBrC)rÚtextrrrrÚreplace_variablesTs zEnvBuilder.replace_variablesc CsÞ|j}t|ƒ}t |¡D]¾\}}}||krX|dd…D]}|dtjfvr8| |¡q8q|D]x} tjdkr‚|  d¡r‚|  d¡r‚q\tj  || ¡} ||d…  tj ¡dd…} | s¶|} ntjj |g| ¢RŽ} tj  | ¡sàt  | ¡tj  | | ¡} t| dƒ} |  ¡}Wdƒn1s0Y|  d¡sŒz$| d¡}| ||¡}| d¡}Wn8tyŠ}zd}t d | |¡WYd}~n d}~00|dur\t| d ƒ} |  |¡Wdƒn1sÀ0Yt | | ¡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ÚcommonrTr_)rfz.pdbr1ÚrbrLz+unable to copy script %r, may be binary: %sÚwb)rAÚlenr rmr?r#rjrer r r6Úsepr(r)rQÚreadÚdecoder{ÚencodeÚ UnicodeErrorrGrHrRr%Zcopymode)rrr rJZplenrprqrrr+rSZsrcfilernZdstdirZdstfileÚdataÚerrrrxfsJ   ÿ   (   ÿ *zEnvBuilder.install_scriptscCs@t dt›d|j›¡|jddddg}| t¡t |¡dS)Nz Upgrading z packages in z-mrZinstallrs)rGÚdebugÚCORE_VENV_DEPSrArDÚextendruZ check_callrvrrrr˜s ÿ zEnvBuilder.upgrade_dependencies)FFFFFNF)F)F)Ú__name__Ú __module__Ú __qualname__Ú__doc__rrr'rrr r?r\rrrrr{rxrrrrrrs&þ B   +=  2rFcCs"t||||||d}| |¡dS)z,Create a virtual environment in a directory.)rrrr rrN)rr)rrrrr rrÚbuilderrrrr¡s þrc Cs‚d}tjdkrd}nttdƒs"d}|s2tdƒ‚nLddl}|jtddd }|jd d d d d|jddddddtj dkr€d}nd}|  ¡}|jd|dddd|jd| dddd|jdddddd|jddddd d|jd!d"ddd#d$|jd%d&d'|jd(ddd)d*  d+  t ¡¡d| |¡}|jrB|jrBtd,ƒ‚t|j|j|j|j|j|j|jd-}|jD]}| |¡qldS).NT)rOrOFÚ 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 descriptionZepilogrqZENV_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”rTz --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.rsrzlUpgrade 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™r—r˜r”z--promptz;Provides an alternative prompt prefix for this environment.)r”z--upgrade-depsrz;Upgrade core dependencies: {} to the latest version in PyPIú z1you cannot supply --upgrade and --clear together.)rrrrr rr)r8r=Úhasattrr*ÚargparseÚArgumentParserrŠÚ add_argumentr r?Zadd_mutually_exclusive_groupÚformatr rˆÚ parse_argsrrrr–rr rrrqr) ÚargsZ compatiblerœÚparserZ use_symlinksÚgroupZoptionsrŽr+rrrÚmain©s~   û ÿþ þ þ ÿ ÿþÿ þþ ú r¤Ú__main__r-z Error: %s)Úfile)FFFFNF)N)rZloggingr r%rur8rcr4rˆZ getLoggerrŠrGrrr¤ZrcrWr†ÚprintrtÚexitrrrrÚs2 ÿ  N(