Rh{g2dZddlZddlZddlZddlZddlZddlZddlZddlZdZ eje Z GddZ d dZd dZe dk(rd Z edZej*eyy#e$r!Zed ezej( YdZ[5dZ[wwxYw)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)pipceZdZdZ ddZdZdZdZdZdZ e jd k7rdd Z ndd Z d Z d ZdZdZdZdZdZdZy) 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 Nc||_||_||_||_||_||_|dk(r1t jjt j}||_ ||_ y)N.) system_site_packagesclearsymlinksupgradewith_pip orig_promptospathbasenamegetcwdprompt upgrade_deps)selfrr r r r rrs $/usr/lib/python3.12/venv/__init__.py__init__zEnvBuilder.__init__/s`%9!      ! S=WW%%biik2F (ctjj|}|j|}|j}d|_|j ||j ||jr|j||js"|j||j||rd|_|j ||jr|j|yy)z Create a virtual environment in a directory. :param env_dir: The target directory to create an environment in. FTN)rrabspathensure_directoriesrcreate_configuration setup_pythonr _setup_pipr setup_scripts post_setuprupgrade_dependencies)renv_dircontexttrue_system_site_packagess rcreatezEnvBuilder.create=s''//'*))'2%)$=$=!$)! !!'* '" == OOG $||   w ' OOG $ $)-D %  % %g .     % %g . rctj|D]}tjj||}tjj |stjj |rtj |wtjj|stj|yN) rlistdirrjoinislinkisfileremoveisdirshutilrmtree)rrfns rclear_directoryzEnvBuilder.clear_directoryYst**T" "BdB'Bww~~b!RWW^^B%7 " r" b!  "rc@||||d}tj|d|S)N)baseplatbaseinstalled_baseinstalled_platbasevenv)schemevars) sysconfigget_path)rr!namer8s r _venv_pathzEnvBuilder._venv_pathas,%")   !!$vDAArcd}tjtj|vr td|dtjdtjj |r|j r|j|tj}||_ tjj|d|_ |j |jn |j}d|z|_ ||tj}|s tdtjjtjj!|\}}||_||_||_|j)|d}|j)|d } |j)|d } | |_|| | |_|| tj.d kDr{tj0d k(rhtj2d k7rUtjj5|d} tjj | stj6d| ||_tjj;|||_tjj5|||_|||j>|_ tj2dk(rtjjC|j>} tjjE| tjjE|j>k7r(tFjId|j>| | |_ |S)z Create the directories for the environment. Returns a context object which holds paths in the environment, for use by subsequent logic. ctjj|stj|ytjj |stjj |rt d|zy)NzUnable to create directory %r)rrexistsmakedirsr)r* ValueError)ds rcreate_if_neededz7EnvBuilder.ensure_directories..create_if_neededrsR77>>!$ A"bggnnQ&7 !@1!DEE'8rzRefusing to create a venv in z( because it contains the PATH separator rz(%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")%rpathsepfspathrArr?r r0typesSimpleNamespacer!splitenv_namersys_base_executabler executable python_dir python_exer<inc_pathlib_pathmaxsizer;platformr(symlinkbin_pathrelpathbin_nameenv_exe env_exec_cmdrealpathnormcaseloggerwarning) rr!rCr"rrUdirnameexenamebinpathincpathlibpath link_path real_env_exes rrzEnvBuilder.ensure_directoriesjs F ::7+ +>' "tzz   )'')!77==1!4 $ 7W=M=M 6)!)) ./ /77==)DE'$$//'95//'95//'95"!"! [[5 rww''9 \\X % Wg6I77>>), 5),"77??7G<'',,w8! ' <<7 "77++GOO (4$rctjj|jdx|_}t |dd5}|j d|jz|jrd}nd}|j d|z|j d tjd d z|j|j d |jd |j dtjjtjzg}tjdk(}|r|jr|j!d|s|js|j!d|j"s|j!d|jr|j!d|j$r|j!d|j&r|j!d|j(r|j!d|j*|j!d|j*d|j!|jdj|}|j dtjd|d d d d y #1swYy xYw)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_pathopenwriterVrrS version_inforrbrUr;r appendr r r rr )rr"rfinclargsrus rrzEnvBuilder.create_configurations#%'',,w "MM4 $g . D! GGMG$6$66 7(( GG9D@ A GG*S-=-=bq-AA B{{&)DKK?"56 GG'"''*:*:3>>*JJ KDDBdmm L)dmm J'== O,(( 45zz I&|| K(   ,-+ j)9)9(:!<= KK (88D>D GGj 0 $rB CA D D Ds H4I==Jruc|j }|s tjj|s|rutjj |tjj |k(sJtj tjj ||ntj |||rtj||yy#t$rtjd||d}Y>wxYw)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 &77>>#./#%77??3#7277??3;O#OO#OJJrww'7'7'>#3F/FG}}WRWW^^C5HK+!wws3rwws7KKKK 277#3#3C#8#> 3, GG,,RWW-=-=c-BCMHcGGLL!:!*!%!)C1E ((*"''..2G$$T**C'}Hx'-H*.Hggll277??3#7CH77>>#&NN#6< OOC %9!KNN#?cJKs0A6I2'I22 JJc|j}|j}|j}|j}tj dk7r||j |tjj|st j|ddddtjdfD]}tjj||}tjj|rC||j|dtjj|rxt j|dy|jrt j|Dcgc]E}tjj!tjj#|dd vr|G}}t%j&r||Dcgc]2}tjj!|j)d r|4}}n>hd }tjj+|j} |j-| |D]i}tjj||} tjj/| sC|| tjj||kt%j&rt j0|jD]\} } } d | vs tjj+| }tjj|j2d |}tjj|st j4|tjj| d } tjj|d }t7j8| |yyycc}wcc}w)z Set up a Python executable in the environment. :param context: The information for the environment creation request being processed. ruirpython3zpython3.rDT)r).exez.dll)r vcruntime> python.exe pythonw.exe python_d.exe pythonw_d.exezinit.tclLibN)r]r`rrVrr;rUrr)chmodrSrr(r?r r'rcrr9r startswithraddrwalkr!r@r-r)rr"rhrcopierrfsuffixrsuffixesbase_exerrootdirsfilestcldirrs rrzEnvBuilder.setup_pythons""%%$$ 77d? 7%%t ,77>>$'u%#Y(3;K;KA;N:O0PQ .ww||GV4ww~~d+7??DtL77>>$/u- .}} "zz'2GG$$RWW%5%5a%8%;<@PP,,.#+ ((+667NO H  Z77++GOO< X&" ?ggll7F377??3'3 Wf => ? ((*)+1C1C)D %D$!U*!#!1!1$!7!#goouf!M!ww~~f5KK/ ggll4< ggll6:>S1 +'  s A N<=7Oc6|jg|}tjjx|d<}|j|d<|j dd|j dd|j|d<|j|d<t j|fi|y)z8Executes the newly created Python using safe-ish optionsenv VIRTUAL_ENV PYTHONHOMEN PYTHONPATHcwdrU)rarenvironcopyr!pop subprocess check_output)rr"py_argskwargsrrs r_call_new_pythonzEnvBuilder._call_new_pythonWs $$/w/ jjoo//u $__M  d#  d#u &33|//rc |j|ddddtjy #tj$r}t j d}t jj|dsLtdjt j|jtjd d }~wwxYw) z1Installs or upgrades pip in a virtual environment-m ensurepipr{z --default-pip)stderrstdlibz/ensurepip/__main__.pyanThe virtual environment was not created successfully because ensurepip is not available. On Debian/Ubuntu systems, you need to install the python3-venv package using the following command. apt install python{}-venv You may need to use sudo with that command. After installing the python3-venv package, recreate your virtual environment. Failing command: {} rDN)rrSTDOUTCalledProcessErrorr9r:rrr?printformatget_python_versionrarSexit)rr"errrs rrzEnvBuilder._setup_pipfs   ! !'4k"1*:K:K " M,, ''1F77>>VH,B"CD  F9 ' ' )7+?+?@ B ! s%(CBB??Cctjjtjjt}tjj |d}|j ||y)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. rEN)rrrrfrr(install_scripts)rr"rs rrzEnvBuilder.setup_scripts}sGwwrwwx89ww||D), Wd+rcy)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. Nrr"s rrzEnvBuilder.post_setups rc|j|j|j|j|jd}d}d}t j }|j}|jdr|}n$|jdr|}nt j }|jD cic]\}} ||| }}} |jD]\}} |j|| }|Scc} }w)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__c2|jdd}d|dS)a This should satisfy PowerShell quoting rules [1], unless the quoted string is passed directly to Windows native commands [2]. [1]: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_quoting_rules [2]: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_parsing#passing-arguments-that-contain-quote-characters 'z'')replacess r quote_ps1z/EnvBuilder.replace_variables..quote_ps1s! #t$Aqc8Orc|Sr&rrs r quote_batz/EnvBuilder.replace_variables..quote_batsHrz.ps1z.bat) r!rRrr_r`shlexquote script_pathritemsr) rtextr" replacementsrrrrkeyrquoteds rreplace_variableszEnvBuilder.replace_variabless$OO$--&~~!(!1!1&     ))    'E  ! !& )EKKE4@4F4F4HI&#qU1X I I'--/ -KC<<V,D - Js(C*c|j}t|}tj|D]\}}}||k(r1|ddD](}|dtjfvs|j |*>|D]} tjdk(r#| j dr| jdr:tjj|| } ||djtjdd} | s|} n tjj|g| } tjj| stj| tjj| | } t| d5} | j}ddd| jds<| |_ j#d}|j%||}|j'd}nt| d 5} | j/|dddt1j2| | y#1swYxYw#t($r#}d}t*j-d | |Yd}~zd}~wwxYw#1swYaxYw) 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(rQsepr?r@rreadrdecoderencode UnicodeErrorrdrerr-copymode)rr"rrhplenrrrrBrsrcfilerdstdirdstfiledataes rrzEnvBuilder.install_scriptss""4y!#" 6 D$t|a'A277 33 A' 6GGtO X(>JJ'78'',,tQ/de**2662126$FWW\\';F;Fww~~f-KK''',,vq1'4($A668D$''(89*1G'H#{{73#55dGD#{{73 #gt,& &OOGW59 6 " 6&$$(H#(;%G7==LMMg.A.A&}}")"2"2!(")"2"2 '&-&:&: r%s       8 $i/i/X7