Skip to content

Commit

Permalink
Remove workaround for pypa/pip#4106. Fixes #43.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed May 2, 2020
1 parent 8855c43 commit 051581f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 31 deletions.
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
v6.2.0
------

#43: Removed workaround for pip 4106. Project now requires
pip 19.3 or later.

v6.1.0
------

Expand Down
31 changes: 1 addition & 30 deletions pip_run/deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,42 +48,13 @@ def _installable(args):
def load(*args):
target = tempfile.mkdtemp(prefix='pip-run-')
cmd = (sys.executable, '-m', 'pip', 'install', '-t', target) + args
with _patch_prefix():
_installable(args) and subprocess.check_call(cmd)
_installable(args) and subprocess.check_call(cmd)
try:
yield target
finally:
shutil.rmtree(target)


def _needs_pip_4106_workaround():
"""
Detect if the environment is configured with a prefix, as
the workaround is only required under those conditions.
"""
import distutils.dist

dist = distutils.dist.Distribution()
dist.parse_config_files()
return 'prefix' in dist.get_option_dict('install')


@contextlib.contextmanager
def _patch_prefix():
"""
To workaround pypa/pip#4106, override the system prefix with
a user prefix, restoring the original file after.
"""
if not _needs_pip_4106_workaround():
yield
return
cfg_fn = os.path.expanduser('~/.pydistutils.cfg')
with _save_file(cfg_fn):
with open(cfg_fn, 'w') as cfg:
cfg.write('[install]\nprefix=\n')
yield


@contextlib.contextmanager
def _save_file(filename):
"""
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ packages = find:
include_package_data = true
py_modules = pip-run
python_requires = >=2.7
install_requires = pip
install_requires = pip >= 19.3
setup_requires = setuptools_scm >= 1.15.0

[options.extras_require]
Expand Down

0 comments on commit 051581f

Please sign in to comment.