Commit 319663cc authored by Xavier Thompson's avatar Xavier Thompson

[fixup] Fix leaked temporary pip $HOME on exit

Fixup "711d8710"
parent e7b90ad1
...@@ -18,7 +18,6 @@ It doesn't install scripts. It uses setuptools and requires it to be ...@@ -18,7 +18,6 @@ It doesn't install scripts. It uses setuptools and requires it to be
installed. installed.
""" """
import atexit
import copy import copy
import distutils.errors import distutils.errors
import distutils.sysconfig import distutils.sysconfig
...@@ -1846,21 +1845,18 @@ try: ...@@ -1846,21 +1845,18 @@ try:
except ImportError: except ImportError:
PIP_HAS_PYTHON_VERSION_WARNING_OPTION = False PIP_HAS_PYTHON_VERSION_WARNING_OPTION = False
# Temporary HOME with .pydistutils.cfg to disable setup_requires
pip_pydistutils_home = tempfile.mkdtemp('pip-pydistutils-home')
with open(os.path.join(pip_pydistutils_home, '.pydistutils.cfg'), 'w') as f:
f.write("[easy_install]\n"
"index-url = file:///dev/null")
atexit.register(zc.buildout.rmtree.rmtree, pip_pydistutils_home)
def call_pip_command(command, operand, options, verbosity=-10): def call_pip_command(command, operand, options, verbosity=-10):
""" """
Call `pip <command...> <operand...>` from a subprocess Call `pip <command...> <operand...>` from a subprocess
with appropriate options and environment. with appropriate options and environment.
""" """
cleanup = []
try:
env = os.environ.copy() env = os.environ.copy()
pythonpath = pip_path[:] pythonpath = pip_path[:]
pythonpath.extend(env.get(k) for k in ('PYTHONPATH', 'PYTHONEXTRAPATH')) pythonpath.extend(
env.get(k) for k in ('PYTHONPATH', 'PYTHONEXTRAPATH'))
env['PYTHONPATH'] = os.pathsep.join(p for p in pythonpath if p) env['PYTHONPATH'] = os.pathsep.join(p for p in pythonpath if p)
args = [sys.executable, '-m', 'pip'] args = [sys.executable, '-m', 'pip']
...@@ -1870,9 +1866,9 @@ def call_pip_command(command, operand, options, verbosity=-10): ...@@ -1870,9 +1866,9 @@ def call_pip_command(command, operand, options, verbosity=-10):
log_level = logger.getEffectiveLevel() log_level = logger.getEffectiveLevel()
pip_level = log_level - verbosity pip_level = log_level - verbosity
if pip_level >= logging.WARNING: if pip_level >= logging.WARNING:
args.append('-' + 'q' * (1 + (pip_level >= logging.ERROR))) # -q or -qq args.append('-' + 'q' * (1 + (pip_level >= logging.ERROR)))
elif pip_level < logging.INFO: elif pip_level < logging.INFO:
args.append('-' + 'v' * (1 + (pip_level < logging.DEBUG))) # -v or -vv args.append('-' + 'v' * (1 + (pip_level < logging.DEBUG)))
# Note: more recent pip accepts even -vvv and -qqq. # Note: more recent pip accepts even -vvv and -qqq.
if not options._allow_picked_versions: if not options._allow_picked_versions:
...@@ -1887,7 +1883,12 @@ def call_pip_command(command, operand, options, verbosity=-10): ...@@ -1887,7 +1883,12 @@ def call_pip_command(command, operand, options, verbosity=-10):
# build dependencies specified in setup_requires option of # build dependencies specified in setup_requires option of
# legacy setup.py by providing a crafted .pydistutils.cfg. # legacy setup.py by providing a crafted .pydistutils.cfg.
# This is used in complement to --no-build-isolation. # This is used in complement to --no-build-isolation.
env['HOME'] = pip_pydistutils_home pip_home = tempfile.mkdtemp('pip-pydistutils-home')
cleanup.append(lambda: zc.buildout.rmtree.rmtree(pip_home))
with open(os.path.join(pip_home, '.pydistutils.cfg'), 'w') as f:
f.write("[easy_install]\n"
"index_url = file:///dev/null")
env['HOME'] = pip_home
if PIP_HAS_PYTHON_VERSION_WARNING_OPTION: if PIP_HAS_PYTHON_VERSION_WARNING_OPTION:
# Let pip display Python warnings only on first run. # Let pip display Python warnings only on first run.
...@@ -1903,10 +1904,14 @@ def call_pip_command(command, operand, options, verbosity=-10): ...@@ -1903,10 +1904,14 @@ def call_pip_command(command, operand, options, verbosity=-10):
logger.debug('Running pip %s', ' '.join(command[0:1] + operand)) logger.debug('Running pip %s', ' '.join(command[0:1] + operand))
if log_level < 0: if log_level < 0:
# Log this only when buildout log level is even lower # Log this only when buildout log level is even lower
logger.debug('%s\nPYTHONPATH=%s\n', ' '.join(args), env['PYTHONPATH']) logger.debug(
'%s\nPYTHONPATH=%s\n', ' '.join(args), env['PYTHONPATH'])
sys.stdout.flush() # We want any pending output first sys.stdout.flush() # We want any pending output first
subprocess.check_call(args, env=env) subprocess.check_call(args, env=env)
finally:
for f in cleanup:
f()
def call_pip_editable(path, dest, options, verbosity=-10): def call_pip_editable(path, dest, options, verbosity=-10):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment