From 6203b1aa8cb52b5c181457054cf6ddaa40361437 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Mon, 12 Nov 2018 13:47:41 -0500 Subject: [PATCH] Automatically bypassed the patched prefix. Fixes #36. --- CHANGES.rst | 7 +++++++ pip_run/deps.py | 13 ++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index dcf1bd4..b07211e 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -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 --- diff --git a/pip_run/deps.py b/pip_run/deps.py index 7724a16..086bfe8 100644 --- a/pip_run/deps.py +++ b/pip_run/deps.py @@ -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')