aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/src/Lib/venv
diff options
context:
space:
mode:
authorshadchin <shadchin@yandex-team.ru>2022-02-10 16:44:30 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:44:30 +0300
commit2598ef1d0aee359b4b6d5fdd1758916d5907d04f (patch)
tree012bb94d777798f1f56ac1cec429509766d05181 /contrib/tools/python3/src/Lib/venv
parent6751af0b0c1b952fede40b19b71da8025b5d8bcf (diff)
downloadydb-2598ef1d0aee359b4b6d5fdd1758916d5907d04f.tar.gz
Restoring authorship annotation for <shadchin@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'contrib/tools/python3/src/Lib/venv')
-rw-r--r--contrib/tools/python3/src/Lib/venv/__init__.py208
1 files changed, 104 insertions, 104 deletions
diff --git a/contrib/tools/python3/src/Lib/venv/__init__.py b/contrib/tools/python3/src/Lib/venv/__init__.py
index 6f1af294ae..2e8e7d4341 100644
--- a/contrib/tools/python3/src/Lib/venv/__init__.py
+++ b/contrib/tools/python3/src/Lib/venv/__init__.py
@@ -12,8 +12,8 @@ import sys
import sysconfig
import types
-
-CORE_VENV_DEPS = ('pip', 'setuptools')
+
+CORE_VENV_DEPS = ('pip', 'setuptools')
logger = logging.getLogger(__name__)
@@ -40,21 +40,21 @@ class EnvBuilder:
: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
+ :param upgrade_deps: Update the base venv modules to the latest on PyPI
"""
def __init__(self, system_site_packages=False, clear=False,
- symlinks=False, upgrade=False, with_pip=False, prompt=None,
- upgrade_deps=False):
+ symlinks=False, upgrade=False, with_pip=False, prompt=None,
+ upgrade_deps=False):
self.system_site_packages = system_site_packages
self.clear = clear
self.symlinks = symlinks
self.upgrade = upgrade
self.with_pip = with_pip
- if prompt == '.': # see bpo-38901
- prompt = os.path.basename(os.getcwd())
+ if prompt == '.': # see bpo-38901
+ prompt = os.path.basename(os.getcwd())
self.prompt = prompt
- self.upgrade_deps = upgrade_deps
+ self.upgrade_deps = upgrade_deps
def create(self, env_dir):
"""
@@ -81,8 +81,8 @@ class EnvBuilder:
# restore it and rewrite the configuration
self.system_site_packages = True
self.create_configuration(context)
- if self.upgrade_deps:
- self.upgrade_dependencies(context)
+ if self.upgrade_deps:
+ self.upgrade_dependencies(context)
def clear_directory(self, path):
for fn in os.listdir(path):
@@ -114,7 +114,7 @@ class EnvBuilder:
prompt = self.prompt if self.prompt is not None else context.env_name
context.prompt = '(%s) ' % prompt
create_if_needed(env_dir)
- executable = sys._base_executable
+ executable = sys._base_executable
dirname, exename = os.path.split(os.path.abspath(executable))
context.executable = executable
context.python_dir = dirname
@@ -142,20 +142,20 @@ class EnvBuilder:
context.bin_name = binname
context.env_exe = os.path.join(binpath, exename)
create_if_needed(binpath)
- # Assign and update the command to use when launching the newly created
- # environment, in case it isn't simply the executable script (e.g. bpo-45337)
- context.env_exec_cmd = context.env_exe
- if sys.platform == 'win32':
- # bpo-45337: Fix up env_exec_cmd to account for file system redirections.
- # Some redirects only apply to CreateFile and not CreateProcess
- real_env_exe = os.path.realpath(context.env_exe)
- if os.path.normcase(real_env_exe) != os.path.normcase(context.env_exe):
- logger.warning('Actual environment location may have moved due to '
- 'redirects, links or junctions.\n'
- ' Requested location: "%s"\n'
- ' Actual location: "%s"',
- context.env_exe, real_env_exe)
- context.env_exec_cmd = real_env_exe
+ # Assign and update the command to use when launching the newly created
+ # environment, in case it isn't simply the executable script (e.g. bpo-45337)
+ context.env_exec_cmd = context.env_exe
+ if sys.platform == 'win32':
+ # bpo-45337: Fix up env_exec_cmd to account for file system redirections.
+ # Some redirects only apply to CreateFile and not CreateProcess
+ real_env_exe = os.path.realpath(context.env_exe)
+ if os.path.normcase(real_env_exe) != os.path.normcase(context.env_exe):
+ logger.warning('Actual environment location may have moved due to '
+ 'redirects, links or junctions.\n'
+ ' Requested location: "%s"\n'
+ ' Actual location: "%s"',
+ context.env_exe, real_env_exe)
+ context.env_exec_cmd = real_env_exe
return context
def create_configuration(self, context):
@@ -176,69 +176,69 @@ class EnvBuilder:
incl = 'false'
f.write('include-system-site-packages = %s\n' % incl)
f.write('version = %d.%d.%d\n' % sys.version_info[:3])
- if self.prompt is not None:
- f.write(f'prompt = {self.prompt!r}\n')
-
- if os.name != 'nt':
- def symlink_or_copy(self, src, dst, relative_symlinks_ok=False):
- """
- Try symlinking a file, and if that fails, fall back to copying.
- """
- force_copy = not self.symlinks
- if not force_copy:
- try:
- if not os.path.islink(dst): # can't link to itself!
- if relative_symlinks_ok:
- assert os.path.dirname(src) == os.path.dirname(dst)
- os.symlink(os.path.basename(src), dst)
- else:
- os.symlink(src, dst)
- except Exception: # may need to use a more specific exception
- logger.warning('Unable to symlink %r to %r', src, dst)
- force_copy = True
- if force_copy:
- shutil.copyfile(src, dst)
- else:
- def symlink_or_copy(self, src, dst, relative_symlinks_ok=False):
- """
- Try symlinking a file, and if that fails, fall back to copying.
- """
- bad_src = os.path.lexists(src) and not os.path.exists(src)
- if self.symlinks and not bad_src and not os.path.islink(dst):
- try:
+ if self.prompt is not None:
+ f.write(f'prompt = {self.prompt!r}\n')
+
+ if os.name != 'nt':
+ def symlink_or_copy(self, src, dst, relative_symlinks_ok=False):
+ """
+ Try symlinking a file, and if that fails, fall back to copying.
+ """
+ force_copy = not self.symlinks
+ if not force_copy:
+ try:
+ if not os.path.islink(dst): # can't link to itself!
+ if relative_symlinks_ok:
+ assert os.path.dirname(src) == os.path.dirname(dst)
+ os.symlink(os.path.basename(src), dst)
+ else:
+ os.symlink(src, dst)
+ except Exception: # may need to use a more specific exception
+ logger.warning('Unable to symlink %r to %r', src, dst)
+ force_copy = True
+ if force_copy:
+ shutil.copyfile(src, dst)
+ else:
+ def symlink_or_copy(self, src, dst, relative_symlinks_ok=False):
+ """
+ Try symlinking a file, and if that fails, fall back to copying.
+ """
+ bad_src = os.path.lexists(src) and not os.path.exists(src)
+ if self.symlinks and not bad_src and not os.path.islink(dst):
+ try:
if relative_symlinks_ok:
assert os.path.dirname(src) == os.path.dirname(dst)
os.symlink(os.path.basename(src), dst)
else:
os.symlink(src, dst)
- return
- except Exception: # may need to use a more specific exception
- logger.warning('Unable to symlink %r to %r', src, dst)
-
- # On Windows, we rewrite symlinks to our base python.exe into
- # copies of venvlauncher.exe
- basename, ext = os.path.splitext(os.path.basename(src))
- srcfn = os.path.join(os.path.dirname(__file__),
- "scripts",
- "nt",
- basename + ext)
- # Builds or venv's from builds need to remap source file
- # locations, as we do not put them into Lib/venv/scripts
- if sysconfig.is_python_build(True) or not os.path.isfile(srcfn):
+ return
+ except Exception: # may need to use a more specific exception
+ logger.warning('Unable to symlink %r to %r', src, dst)
+
+ # On Windows, we rewrite symlinks to our base python.exe into
+ # copies of venvlauncher.exe
+ basename, ext = os.path.splitext(os.path.basename(src))
+ srcfn = os.path.join(os.path.dirname(__file__),
+ "scripts",
+ "nt",
+ basename + ext)
+ # Builds or venv's from builds need to remap source file
+ # locations, as we do not put them into Lib/venv/scripts
+ if sysconfig.is_python_build(True) or not os.path.isfile(srcfn):
if basename.endswith('_d'):
ext = '_d' + ext
basename = basename[:-2]
- if basename == 'python':
- basename = 'venvlauncher'
- elif basename == 'pythonw':
- basename = 'venvwlauncher'
- src = os.path.join(os.path.dirname(src), basename + ext)
- else:
- src = srcfn
- if not os.path.exists(src):
- if not bad_src:
- logger.warning('Unable to copy %r', src)
- return
+ if basename == 'python':
+ basename = 'venvlauncher'
+ elif basename == 'pythonw':
+ basename = 'venvwlauncher'
+ src = os.path.join(os.path.dirname(src), basename + ext)
+ else:
+ src = srcfn
+ if not os.path.exists(src):
+ if not bad_src:
+ logger.warning('Unable to copy %r', src)
+ return
shutil.copyfile(src, dst)
@@ -257,7 +257,7 @@ class EnvBuilder:
copier(context.executable, path)
if not os.path.islink(path):
os.chmod(path, 0o755)
- for suffix in ('python', 'python3', f'python3.{sys.version_info[1]}'):
+ for suffix in ('python', 'python3', f'python3.{sys.version_info[1]}'):
path = os.path.join(binpath, suffix)
if not os.path.exists(path):
# Issue 18807: make copies if
@@ -281,13 +281,13 @@ class EnvBuilder:
os.path.normcase(f).startswith(('python', 'vcruntime'))
]
else:
- suffixes = {'python.exe', 'python_d.exe', 'pythonw.exe', 'pythonw_d.exe'}
- base_exe = os.path.basename(context.env_exe)
- suffixes.add(base_exe)
+ suffixes = {'python.exe', 'python_d.exe', 'pythonw.exe', 'pythonw_d.exe'}
+ base_exe = os.path.basename(context.env_exe)
+ suffixes.add(base_exe)
for suffix in suffixes:
src = os.path.join(dirname, suffix)
- if os.path.lexists(src):
+ if os.path.lexists(src):
copier(src, os.path.join(binpath, suffix))
if sysconfig.is_python_build(True):
@@ -308,8 +308,8 @@ class EnvBuilder:
# We run ensurepip in isolated mode to avoid side effects from
# environment vars, the current directory and anything else
# intended for the global Python environment
- cmd = [context.env_exec_cmd, '-Im', 'ensurepip', '--upgrade',
- '--default-pip']
+ cmd = [context.env_exec_cmd, '-Im', 'ensurepip', '--upgrade',
+ '--default-pip']
subprocess.check_output(cmd, stderr=subprocess.STDOUT)
def setup_scripts(self, context):
@@ -405,21 +405,21 @@ class EnvBuilder:
f.write(data)
shutil.copymode(srcfile, dstfile)
- def upgrade_dependencies(self, context):
- logger.debug(
- f'Upgrading {CORE_VENV_DEPS} packages in {context.bin_path}'
- )
- cmd = [context.env_exec_cmd, '-m', 'pip', 'install', '--upgrade']
- cmd.extend(CORE_VENV_DEPS)
- subprocess.check_call(cmd)
-
+ def upgrade_dependencies(self, context):
+ logger.debug(
+ f'Upgrading {CORE_VENV_DEPS} packages in {context.bin_path}'
+ )
+ cmd = [context.env_exec_cmd, '-m', 'pip', 'install', '--upgrade']
+ cmd.extend(CORE_VENV_DEPS)
+ subprocess.check_call(cmd)
+
def create(env_dir, system_site_packages=False, clear=False,
- symlinks=False, with_pip=False, prompt=None, upgrade_deps=False):
+ symlinks=False, with_pip=False, prompt=None, upgrade_deps=False):
"""Create a virtual environment in a directory."""
builder = EnvBuilder(system_site_packages=system_site_packages,
clear=clear, symlinks=symlinks, with_pip=with_pip,
- prompt=prompt, upgrade_deps=upgrade_deps)
+ prompt=prompt, upgrade_deps=upgrade_deps)
builder.create(env_dir)
def main(args=None):
@@ -482,11 +482,11 @@ def main(args=None):
parser.add_argument('--prompt',
help='Provides an alternative prompt prefix for '
'this environment.')
- parser.add_argument('--upgrade-deps', default=False, action='store_true',
- dest='upgrade_deps',
- help='Upgrade core dependencies: {} to the latest '
- 'version in PyPI'.format(
- ' '.join(CORE_VENV_DEPS)))
+ parser.add_argument('--upgrade-deps', default=False, action='store_true',
+ dest='upgrade_deps',
+ help='Upgrade core dependencies: {} to the latest '
+ 'version in PyPI'.format(
+ ' '.join(CORE_VENV_DEPS)))
options = parser.parse_args(args)
if options.upgrade and options.clear:
raise ValueError('you cannot supply --upgrade and --clear together.')
@@ -495,8 +495,8 @@ def main(args=None):
symlinks=options.symlinks,
upgrade=options.upgrade,
with_pip=options.with_pip,
- prompt=options.prompt,
- upgrade_deps=options.upgrade_deps)
+ prompt=options.prompt,
+ upgrade_deps=options.upgrade_deps)
for d in options.dirs:
builder.create(d)