From e7b1722efeaf4ff403142847ce1b52caedd5efcd Mon Sep 17 00:00:00 2001 From: Tzu-ping Chung Date: Sun, 25 Apr 2021 04:47:23 +0800 Subject: [PATCH 1/2] Set dist_name to UNKNOWN when empty outside venv For compatibility with distutils. This is only done when pip is not inside a virtual environment due to a quirk in pip's previous implementation to the header path. --- news/9838.bugfix.rst | 1 + src/pip/_internal/locations/_sysconfig.py | 3 +++ 2 files changed, 4 insertions(+) create mode 100644 news/9838.bugfix.rst diff --git a/news/9838.bugfix.rst b/news/9838.bugfix.rst new file mode 100644 index 00000000000..4e2342e364b --- /dev/null +++ b/news/9838.bugfix.rst @@ -0,0 +1 @@ +Fix compatibility between distutils and sysconfig when the project name is unknown outside of a virtual environment. diff --git a/src/pip/_internal/locations/_sysconfig.py b/src/pip/_internal/locations/_sysconfig.py index e4d66d25d24..1a15619bf2f 100644 --- a/src/pip/_internal/locations/_sysconfig.py +++ b/src/pip/_internal/locations/_sysconfig.py @@ -128,6 +128,7 @@ def get_scheme( paths = sysconfig.get_paths(scheme=scheme_name, vars=variables) # Pip historically uses a special header path in virtual environments. + # Logic here is very arbitrary, we're doing it for compatibility, don't ask. if running_under_virtualenv(): if user: base = variables.get("userbase", sys.prefix) @@ -135,6 +136,8 @@ def get_scheme( base = variables.get("base", sys.prefix) python_xy = f"python{get_major_minor_version()}" paths["include"] = os.path.join(base, "include", "site", python_xy) + elif not dist_name: + dist_name = "UNKNOWN" scheme = Scheme( platlib=paths["platlib"], From 2a009a0b8a5d8d03117897f0f11f9c1dcf2a4b5a Mon Sep 17 00:00:00 2001 From: Tzu-ping Chung Date: Sun, 25 Apr 2021 17:04:43 +0800 Subject: [PATCH 2/2] Better explanatory comment --- src/pip/_internal/locations/_sysconfig.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/pip/_internal/locations/_sysconfig.py b/src/pip/_internal/locations/_sysconfig.py index 1a15619bf2f..03366ce6e71 100644 --- a/src/pip/_internal/locations/_sysconfig.py +++ b/src/pip/_internal/locations/_sysconfig.py @@ -127,8 +127,11 @@ def get_scheme( paths = sysconfig.get_paths(scheme=scheme_name, vars=variables) - # Pip historically uses a special header path in virtual environments. # Logic here is very arbitrary, we're doing it for compatibility, don't ask. + # 1. Pip historically uses a special header path in virtual environments. + # 2. If the distribution name is not known, distutils uses 'UNKNOWN'. We + # only do the same when not running in a virtual environment because + # pip's historical header path logic (see point 1) did not do this. if running_under_virtualenv(): if user: base = variables.get("userbase", sys.prefix)