Skip to content

Commit

Permalink
Automatically bypassed the patched prefix. Fixes #36.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Nov 12, 2018
1 parent 5aa7b62 commit 6203b1a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
7 changes: 7 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
5.3
---

#36: Instead of soliciting the environment variable,
the workaround for pip #4106 is now automatically
applied, but only when it is needed.

5.2
---

Expand Down
13 changes: 12 additions & 1 deletion pip_run/deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,24 @@ def load(*args):
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 os.environ.get('PIP_RUN_NO_PATCH_PREFIX'):
if not _needs_pip_4106_workaround():
yield
return
cfg_fn = os.path.expanduser('~/.pydistutils.cfg')
Expand Down

0 comments on commit 6203b1a

Please sign in to comment.