\d=b2dZddlZddlZddlZddlZddlZddlZddlZdZej e Z GddZ d dZ ddZe d krId Z edZn'#e$rZed ezej YdZ[ndZ[wwxYwejedSdS)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)pip setuptoolsceZdZdZ ddZdZdZdZdZd Z e j d krdd Z ndd Z d Z dZdZdZdZdZdZdZdS) 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 FNc||_||_||_||_||_||_|dkr0t jt j }||_ ||_ dS)N.) system_site_packagesclearsymlinksupgradewith_pip orig_promptospathbasenamegetcwdprompt upgrade_deps)selfr r r r r rrs ..\python\lib\venv\__init__.py__init__zEnvBuilder.__init__.si%9!      ! S==W%%bikk22F (ctj|}||}|j}d|_|||||jr|||j s*| || ||rd|_|||j r| |dSdS)z Create a virtual environment in a directory. :param env_dir: The target directory to create an environment in. FTN)rrabspathensure_directoriesr create_configuration setup_pythonr _setup_pipr setup_scripts post_setuprupgrade_dependencies)renv_dircontexttrue_system_site_packagess rcreatezEnvBuilder.create<s'//'**))'22%)$=!$)! !!'*** '""" = % OOG $ $ $| %   w ' ' ' OOG $ $ $ $ /)-D %  % %g . . .   /  % %g . . . . . / /rctj|D]}tj||}tj|stj|rtj|utj|rtj |dSN) rlistdirrjoinislinkisfileremoveisdirshutilrmtree)rrfns rclear_directoryzEnvBuilder.clear_directoryXs*T"" " "BdB''Bw~~b!! "RW^^B%7%7 " " r"" " b!!!  " "rc>||||d}tj|d|S)N)baseplatbaseinstalled_baseinstalled_platbasevenv)schemevars) sysconfigget_path)rr"namer9s r _venv_pathzEnvBuilder._venv_path`s4%")    !$vDAAAArcd}tjtj|vr td|dtjdtj|r|jr||tj }||_ tj |d|_ |j |j n|j }d|z|_ ||tj}|stdtj tj|\}}||_||_||_||d }||d } ||d } | |_|| || tjd krttjd krdtjdkrTtj|d} tj| stjd| ||_tj|||_tj|||_|||j|_tjdkrtj |j} tj!| tj!|jkr(tD#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. ctj|stj|dStj|stj|rt d|zdS)NzUnable to create directory %r)rrexistsmakedirsr*r+ ValueError)ds rcreate_if_neededz7EnvBuilder.ensure_directories..create_if_neededqsw7>>!$$ F A"" FbgnnQ&7&7 F !@1!DEEE F FrzRefusing to create a venv in z( because it contains the PATH separator rNz(%s) zUnable to determine path to the running Python interpreter. Provide an explicit path or check that your PATH environment variable is correctly set.scriptsincludepureliblposixdarwinlib64libwin32zActual environment location may have moved due to redirects, links or junctions. Requested location: "%s" Actual location: "%s")$rpathsepfspathrBrr@r r1typesSimpleNamespacer"splitenv_namersys_base_executabler executable python_dir python_exer=inc_pathmaxsizer<platformr)symlinkbin_pathrelpathbin_nameenv_exe env_exec_cmdrealpathnormcaseloggerwarning) rr"rDr#rrVdirnameexenamebinpathincpathlibpath link_path real_env_exes rrzEnvBuilder.ensure_directoriesis  F F F :7++ + +MWMM?AzMMMNN N 7>>' " " *tz *   ) ) )'))!7==11!4 $ 7W=M 6)!!!)  /.// /7==)D)DEE'$$//'955//'955//'955"!!!!!! [5 rw''9'9 \X % % Wg66I7>>),, - 5),,,"7??7G<<',,w88!!! ' <7 " "7++GO<>> (4$rctj|jdx|_}t |dd5}|d|jz|jrd}nd}|d|z|d tj d d z|j |d |j d |dtj tj zg}tjdk}|r|jr|d|s|js|d|js|d|jr|d|jr|d|jr|d|jr|d|j|d|jd||jd|}|dtj d|d d d d d S#1swxYwYd 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.cfgwutf-8)encodingz home = %s truefalsez"include-system-site-packages = %s zversion = %d.%d.%d Nz prompt =  zexecutable = %s nt --symlinks--copies --without-pip--system-site-packages--clear --upgrade--upgrade-depsz --prompt="" z command = z -m venv )rrr)r"cfg_pathopenwriterWr rT version_inforrbrVr<r appendr r r rr)rr#rfinclargsrus rrzEnvBuilder.create_configurations#%',,w "M"MM4 $g . . . D! GGMG$66 7 7 7(  GG9D@ A A A GG*S-=bqb-AA B B B{&5DK555666 GG'"'*:*:3>*J*JJ K K KDDB *dm * L))) (dm ( J'''= - O,,,( 6 4555z ' I&&&| ) K(((  . ,---+ <)9<<<=== KK ( ( (88D>>D GGBBB$BBB C C CA D D D D D D D D D D D D D D D D D DsH$I00I47I4ruc|j }|s tj|s|rutj|tj|ksJtjtj||ntj||n.#t$r!t d||d}YnwxYw|rtj ||dSdS)Y Try symlinking a file, and if that fails, fall back to copying. Unable to symlink %r to %rTN) r rrr*rfr\r Exceptionrdrer.copyfile)rsrcdstrelative_symlinks_ok force_copys rsymlink_or_copyzEnvBuilder.symlink_or_copys"]*J & &7>>#..1/1#%7??3#7#727??3;O;O#O#O#O#OJrw'7'7'<'>#3F3F/FG} KW KRW^^C5H5H KK+-!ws33rws7K7KKKKK 27#3#3C#8#8#>>>> 3,,,F KKKNN#?cJJJJJK G,,RW-=-=c-B-BCCMHcGLL!:!:!*!%!)C11E (** "'..2G2G $$T**-*C'}Hx''-HH**.Hgll27??3#7#7CHH7>>#&& =NN#6<<< OC % % % % %s)B C77&D D c |j}|j}|j}|j}tjdkr||j|tj|st j |ddddtj dfD]}tj ||}tj |sG||j|dtj|st j |ddS|jr>d t j|D}t!jr d |D}n=hd }tj|j}|||D]k}tj ||} tj| r*|| tj ||lt!jrt j|jD]\} } } d | vrtj| } tj |jd | } tj | st j| tj | d } tj | d }t1j| |dSdSdS)z Set up a Python executable in the environment. :param context: The information for the environment creation request being processed. ruirpython3zpython3.rET)rcg|]H}tjtj|ddvF|IS)rE).exez.dll)rrrcr.0rs r z+EnvBuilder.setup_python..5sSG$$RW%5%5a%8%8%;<<@PPPPPPrcvg|]6}tj|d4|7S))r vcruntime)rrrc startswithrs rrz+EnvBuilder.setup_python..:sM   ((++667NOO    r> python.exe pythonw.exe python_d.exe pythonw_d.exezinit.tclLibN)r]r`rrWrr<rVrr*chmodrTrr)r@r r(r:rraddrwalkr"rAr.r)rr#rhrcopierrfsuffixsuffixesbase_exerrootdirsfilestcldirrs rrzEnvBuilder.setup_pythons"%$ 7d?? F7%t , , ,7>>$'' &u%%%#Y0P3;KA;N0P0PQ . .w||GV44w~~d++.F7?DtLLLL7>>$//.u--- . .} ' !z'22,..  #+   H ZYY7++GO<< X&&&" ? ?gll7F337??3''?F3 Wf = =>>>(** )+1C)D)D  %D$!U**!#!1!1$!7!7!#gouf!M!M!w~~f550K/// gll4<< gll6:>>S111+    rc|jg|}tjx|d<}|j|d<|dd|dd|j|d<|j|d<t j|fi|dS)z8Executes the newly created Python using safe-ish optionsenv VIRTUAL_ENV PYTHONHOMEN PYTHONPATHcwdrV)rarenvironcopyr"pop subprocess check_output)rr#py_argskwargsrrs r_call_new_pythonzEnvBuilder._call_new_pythonUs $/w/ joo///u $_M  d###  d###u &3|///////rcP||ddddtjdS)z1Installs or upgrades pip in a virtual environment-m ensurepipr{z --default-pip)stderrN)rrSTDOUTrr#s rrzEnvBuilder._setup_pipds> gt[+-j6G  I I I I Irctjtjt}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. rFN)rrrrfrr)install_scripts)rr#rs rrzEnvBuilder.setup_scriptsisVwrwx8899w||D),, Wd+++++rcdS)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. Nrs rr zEnvBuilder.post_setupxs  rc|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. __VENV_DIR__ __VENV_NAME____VENV_PROMPT____VENV_BIN_NAME____VENV_PYTHON__)replacer"rSrr_r`)rtextr#s rreplace_variableszEnvBuilder.replace_variablessw||NGO<<||OW-=>>||-w~>>||/1ABB||-w?? rc|j}t|}tj|D]\\}}}||kr3|ddD]'}|dtjfvr||(@|D]} tjdkr+| dr| dr>tj || } ||d tj dd} | s|} ntjj |g| R} tj | stj | tj | | } t| d5} | }dddn #1swxYwY| dsw |d}|||}|d}n5#t&$r(}d}t(d | |Yd}~nd}~wwxYw|Rt| d 5} | |dddn #1swxYwYt/j| | ^dS) 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. Ncommonrur)rz.pdbrbroz+unable to copy script %r, may be binary: %swb)r]lenrrr<r,rrrr)rRsepr@rArreaddecoderencode UnicodeErrorrdrerr.copymode)rr#rrhplenrrrrCrsrcfilerdstdirdstfiledataes rrzEnvBuilder.install_scriptss$"4yy!#! 6! 6 D$t||aaa''A27 333 A 6 6GtOO X(>(>OJJ'788$',,tQ//dee**26221226<$FFW\';F;;;Fw~~f--(K'''',,vq11'4(($A6688D$$$$$$$$$$$$$$$''(899HH#{{733#55dGDD#{{733'HHH#(;= 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.)prog descriptionepilogrENV_DIR+z)A directory to create the environment in.)metavarnargshelpry store_true system_sitezDGive the virtual environment access to the system site-packages dir.)defaultactiondestrrurvr z[Try to use symlinks rather than copies, when symlinks are not the default for the platform.rw store_falsez\Try to use copies rather than symlinks, even when symlinks are the default for the platform.rzr zcDelete the contents of the environment directory if it already exists, before environment creation.r{r zlUpgrade the environment directory to use this version of Python, assuming Python has been upgraded in-place.rxr z]Skips installing or upgrading pip in the virtual environment (pip is bootstrapped by default))rrrrz--promptz;Provides an alternative prompt prefix for this environment.)rr|rz;Upgrade core dependencies: {} to the latest version in PyPIr~z1you cannot supply --upgrade and --clear together.)r r r r r rr)rTrhasattrrBargparseArgumentParserr add_argumentrr<add_mutually_exclusive_groupformatr)r parse_argsr r rrr r rrrr%) r compatiblerparser use_symlinksgroupoptionsrrCs rmainrsJ &   S- ( ( FIJJJ((h6D1H ) I I FIS!L  N N N4e#/m"=  > > > 7d?? LLL3355 <".Z!0  1 1 1 : @@@  A NN1      r__main__rEz Error: %s)file)FFFFNFr')rloggingrr.rrTr:rPr getLoggerrrdrr%rrcrrprintrexitrrrrsb    '  8 $ $w/w/w/w/w/w/w/w/t 7