Qfc*dZddlZddlZddlZddlZddlZddlZddlZdZeje Z GddZ d dZ d 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 ddZdZdZdZedZ dZ d Z e jd k7rdd Zndd Zd ZdZdZdZdZdZdZdZy) 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 4/opt/alt/python312/lib64/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_directoryXso**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_path`s,%")   !!$vDAArc tjdk(rtjj |tjj |k(ryddl} |j tj|} |j tj|}tjj |tjj |k(ryy||k(S#t$rYvwxYw#t$rY`wxYw)zCheck whether two paths appear the same. Whether they refer to the same file is irrelevant; we're testing for whether a human reader would look at the path string and easily tell that they're the same file. win32TrNF) sysplatformrrnormcase_winapiGetLongPathNamefsdecodeOSError)clspath1path2rBs r _same_pathzEnvBuilder._same_pathis <<7 "ww&"''*:*:5*AA  // E0BC // E0BCww&"''*:*:5*AAE> !    s$$C(>$C7( C43C47 DDcxd}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(rmtjjC|j>} |jE| |j>s(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_neededsR77>>!$ 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.scriptsincludepureliblposixdarwinlib64libr>zActual environment location may have moved due to redirects, links or junctions. Requested location: "%s" Actual location: "%s")%rpathsepfspathrNrrLr r0typesSimpleNamespacer!splitenv_namerr?_base_executabler executable python_dir python_exer<inc_pathlib_pathmaxsizer;r@r(symlinkbin_pathrelpathbin_nameenv_exe env_exec_cmdrealpathrIloggerwarning) rr!rPr"rr`dirnameexenamebinpathincpathlibpath link_path real_env_exes rrzEnvBuilder.ensure_directoriess~ 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_pathopenwriterarr? version_inforrlr`r;r appendr r r rr )rr"rfinclargsr~s rrzEnvBuilder.create_configurations#%'',,w "MM4 $g .! 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/ . .s H4I==Jr~c|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)rorfr Exceptionrmrnr-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. r~irpython3zpython3.rQT)r).exez.dll)r vcruntime> python.exe pythonw.exe python_d.exe pythonw_d.exezinit.tclLibN)rgrjrrarr;r`rr)chmodr?rr(rLr r'rArr9r startswithraddrwalkr!rMr-r)rr"rqrcopierrosuffixrsuffixesbase_exerrootdirsfilestcldirrs rrzEnvBuilder.setup_python4s""%%$$ 77d? 7%%t ,77>>$'u%#Y(3;K;KA;N:O0PQww||GV4ww~~d+7??DtL77>>$/u-R}} "zz'22!GG$$RWW%5%5a%8%;<@PP2,,.#+ #+a((+667NO8  Z77++GOO< X&"ggll7F377??3'3 Wf =># ((*)+1C1C)D%D$!U*!#!1!1$!7!#goouf!M!ww~~f5KK/ ggll4< ggll6:>S1*E+'  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 PYTHONPATHcwdr`)rkrenvironcopyr!pop subprocess check_output)rr"py_argskwargsrrs r_call_new_pythonzEnvBuilder._call_new_pythonqs $$/w/ jjoo//u $__M  d#  d#u &33|//rcN|j|ddddtjy)z1Installs or upgrades pip in a virtual environment-m ensurepiprz --default-pip)stderrN)rrSTDOUTrr"s rrzEnvBuilder._setup_pips) gt[+-j6G6G  Irctjjtjjt}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. rRN)rrrrorr(install_scripts)rr"rs rrzEnvBuilder.setup_scriptssGwwrwwx89ww||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. Nrs rrzEnvBuilder.post_setups rc|jd|j}|jd|j}|jd|j}|jd|j}|jd|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!r^rrirj)rtextr"s rreplace_variableszEnvBuilder.replace_variablesst||NGOO<||OW-=-=>||-w~~>||/1A1AB||-w? rc|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| jds5 j!d}|j#||}|j%d}gt| d 5} | j-|dddt/j0| | 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. Ncommonr~r)rz.pdbrbrxz+unable to copy script %r, may be binary: %swb)rglenrrr;r+rrrr(r]seprLrMrreaddecoderencode UnicodeErrorrmrnrr-copymode)rr"rrqplenrrrrOrsrcfilerdstdirdstfiledataes rrzEnvBuilder.install_scriptss""4y!# D$t|aA277 33 A!GGtO X(>JJ'78'',,tQ/de**2662126$FWW\\';F;Fww~~f-KK''',,vq1'4(A668D)''(89H#{{73#55dGD#{{73 #gt, -OOGW57 "/&)((H#(;%G7==LMMg.A.A&}}")"2"2!(")"2"2 '&-&:&: rs       8 $S/S/l7