U
jV
@ s d Z ddlZddlZddlZddlZddlZddlZddlZddlZe e
ZG dd dZdddZ
ddd Ze
d
krdZze dZW n4 ek
r Z zede ejd
W 5 dZ[X Y nX ee 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.
Nc @ s e Zd ZdZdddZdd Zdd Zd
d Zdd
Ze j
dkrLdddZn
d ddZdd Zdd Z
dd 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.
FNc C s( || _ || _|| _|| _|| _|| _d S Nsystem_site_packagesclearsymlinksupgradewith_pipprompt)selfr r r r r r
r 2/opt/alt/python38/lib64/python3.8/venv/__init__.py__init__, s zEnvBuilder.__init__c C sx t j|}| |}| j}d| _| | | | | jrF| | | j s`|
| | | |rtd| _| | dS )z
Create a virtual environment in a directory.
:param env_dir: The target directory to create an environment in.
FTN)ospathabspathensure_directoriesr create_configurationsetup_pythonr
_setup_pipr
setup_scripts
post_setup)r env_dircontextZtrue_system_site_packagesr r r
create5 s
zEnvBuilder.createc C s\ t |D ]L}t j||}t j|s4t j|r@t | q
t j|r
t | q
d S r )
r listdirr joinislinkisfileremoveisdirshutilZrmtree)r r fnr r r
clear_directoryO s zEnvBuilder.clear_directoryc C s dd }t j|r$| jr$| | t }||_t j|d |_ | j
dk rT| j
n|j }d| |_
|| tj}t jt j
|\}}||_||_||_tjdkrd}d} t j|d d
}
n(d}d} t j|d
dtjdd d
}
t j|| |_}|| ||
tjdkrXt jdkrXtjdkrXt j|d}t j|sXt d
| t j|| |_}
||_t j|
||_||
|S )z
Create the directories for the environment.
Returns a context object which holds paths in the environment,
for use by subsequent logic.
c S s@ t j| st | n$t j| s0t j| r<td| d S )NzUnable to create directory %r)r r existsmakedirsr r
ValueError)dr r r
create_if_needed_ s z7EnvBuilder.ensure_directories.<locals>.create_if_needed Nz(%s) Zwin32ZScriptsZIncludeLibz
site-packagesbinZincludelibzpython%d.%d l posixdarwinlib64)r r r$ r r# typesSimpleNamespacer splitenv_namer
sys_base_executabler
executable
python_dirZ
python_exeplatformr version_infoZinc_pathmaxsizenamesymlinkbin_pathbin_nameenv_exe)r r r( r r
r7 dirnameZexenameZbinnameZincpathZlibpathr Z link_pathbinpathr r r
r W sL
zEnvBuilder.ensure_directoriesc C s t j|jd |_}t|dddj}|d|j | jrBd}nd}|d| |d t j
d
d | jd
k r|d| jd
W 5 Q R X d
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
trueZfalsez"include-system-site-packages = %s
zversion = %d.%d.%d
N z prompt =
)r r r r Zcfg_pathopenwriter8 r r5 r: r
)r r r fZinclr r r
r s
zEnvBuilder.create_configurationntc C s | j }|szRtj|s\|rPtj|tj|ks:tttj|| nt|| W n& tk
r t
d|| d}Y nX |rt|| dS )Y
Try symlinking a file, and if that fails, fall back to copying.
Unable to symlink %r to %rTN)
r r r r rA AssertionErrorr= basename Exceptionloggerwarningr! copyfile)r srcdstrelative_symlinks_okZ
force_copyr r r
symlink_or_copy s
zEnvBuilder.symlink_or_copyc C s| t j|ot j| }| jr|st j|szH|rht j|t j|ksRtt t j || nt || W dS t
k
r td|| Y nX t j
t j |\}}t jt jtdd|| }tdst j|sD|dr
d| }|dd }|dkrd }n|d
kr(d}t jt j||| }n|}t j|sl|shtd| dS t|| dS )
rM NrN scriptsrL TZ_dpythonZvenvlauncherZpythonwZ
venvwlauncherzUnable to copy %r)r r lexistsr$ r r rA rO r= rP rQ rR rS splitextr __file__ sysconfigis_python_buildr endswithr! rT )r rU rV rW Zbad_srcrP ZextZsrcfnr r r
rX s>