U e5dFRã @sÂddlZddlZddlZddlZddlZddlZddlZe e¡Z Gdd„dƒZ d dd„Z ddd„Z ed kr¾d Z ze ƒdZ Wn4ek r²Zzed eejd W5dZ[XYnXe e ¡dS)éNc@s†eZdZddd„Zdd„Zdd„Zd d „Zd d „Zej d krHddd„Z n ddd„Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„ZdS) Ú EnvBuilderFNcCs(||_||_||_||_||_||_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)NFT) Ú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 |dd ¡} n(d }d } tj |d d t jdd…d ¡} tj || ¡|_} || ƒ|| ƒt jdkrXtjdkrXt jdkrXtj |d¡} tj | ¡sXt d | ¡tj ||¡|_} ||_tj | |¡|_|| ƒ|S)NcSs@tj |¡st |¡n$tj |¡s0tj |¡r.create_if_neededéz(%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 dd …¡|j dk rŠ| d |j ›d ¡W5QRXdS) Nz pyvenv.cfgÚwúutf-8)Úencodingz home = %s ÚtrueZfalsez"include-system-site-packages = %s zversion = %d.%d.%d éz prompt = Ú ) rrrrZcfg_pathÚopenÚwriter8rr5r:r )r rrÚfZinclr r r rŠs  zEnvBuilder.create_configurationÚntcCs~|j }|sjz6tj |¡s@|r4t tj |¡|¡n t ||¡Wn&tk rht d||¡d}YnX|rzt   ||¡dS)NúUnable to symlink %r to %rT) rrrrr=Ú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€z,|rLt tj |¡|¡n t ||¡WdStk r~t   d||¡YnXtj  tj |¡¡\}}tj  tj  t¡dd||¡}t d¡sÎtj |¡s$| d¡rìd|}|dd…}|dkrúd}n|d krd }tj  tj  |¡||¡}n|}tj |¡sL|sHt   d |¡dSt ||¡dS) NrMÚscriptsrLTZ_déþÿÿÿÚpythonZ venvlauncherZpythonwZ venvwlauncherzUnable to copy %r)rrÚlexistsr$rrr=rNrOrPrQÚsplitextrrAÚ__file__Ú sysconfigÚis_python_buildrÚendswithr!rR)r rSrTrUZbad_srcrNZextZsrcfnr r r rV³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)NrLií)rYZpython3T)rUcSs,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))rYZ vcruntime)rrraÚ startswithrbr r r rdsÿz python.exez python_d.exez pythonw.exez pythonw_d.exezinit.tclr*)r>r@rVr8rr<r7rrÚchmodrr$rrr]r^rZÚwalkrNrr%r!rR)r rrBrZcopierrAÚsuffixÚsuffixesrSÚrootÚdirsÚfilesZtcldirrTr r r rÞsP      ÿ ÿÿ      zEnvBuilder.setup_pythoncCs$|jddddg}tj|tjddS)Nz-ImZ ensurepipú --upgradez --default-pip)Ústderr)r@Ú subprocessZ check_outputZSTDOUT)r rÚcmdr r r rs ÿzEnvBuilder._setup_pipcCs2tj tj t¡¡}tj |d¡}| ||¡dS)NrW)rrrrAr\rÚinstall_scripts)r rrr r r r#s zEnvBuilder.setup_scriptscCsdSrr )r rr r r r2szEnvBuilder.post_setupcCsJ| d|j¡}| d|j¡}| d|j¡}| d|j¡}| d|j¡}|S)NZ __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) NÚcommonrLrY)r`z.pdbr-ÚrbrDz+unable to copy script %r, may be binary: %sÚwb)r>Úlenrrgr<rrer_rrr3Úsepr$r%rIÚreadÚdecodertÚencodeÚ UnicodeErrorrPrQrJr!Zcopymode)r rrrBZplenrjrkrlr'rKZsrcfilerhZdstdirZdstfileÚdataÚer r r rqNsL   ÿ      ÿ zEnvBuilder.install_scripts)FFFFFN)F)F)Ú__name__Ú __module__Ú __qualname__rrr#rrrr<rVrrrrrtrqr r r r rs&ÿ 4   +<  rFcCs t|||||d}| |¡dS)N)rrrr r )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 descriptionZepilogrkZENV_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.rmrzlUpgrade 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Œrr‰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 rkr) ÚargsZ compatiblerÚparserZ use_symlinksÚgroupZoptionsrƒr'r r r Úmain‰s|   û ÿþ þ þ ÿ ÿþÿ û r—Ú__main__r)z Error: %s)Úfile)FFFFN)N)Zloggingrr!ror5r]r1Z getLoggerr€rPrrr—ZrcrOrÚprintrnÚexitr r r r Ús0 qÿ  H$