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/news/9839.bugfix.rst b/news/9839.bugfix.rst new file mode 100644 index 00000000000..b42717859b6 --- /dev/null +++ b/news/9839.bugfix.rst @@ -0,0 +1 @@ +Fix compatibility between distutils and sysconfig when the returned location is a symbolic link. diff --git a/src/pip/_internal/locations/__init__.py b/src/pip/_internal/locations/__init__.py index 18bf0319f3d..b5b5edb88a2 100644 --- a/src/pip/_internal/locations/__init__.py +++ b/src/pip/_internal/locations/__init__.py @@ -1,3 +1,4 @@ +import contextlib import logging import pathlib import sys @@ -45,6 +46,9 @@ def _default_base(*, user: bool) -> str: def _warn_if_mismatch(old: pathlib.Path, new: pathlib.Path, *, key: str) -> bool: if old == new: return False + with contextlib.suppress(OSError): + if old.samefile(new): + return False issue_url = "https://github.com/pypa/pip/issues/9617" message = ( "Value for %s does not match. Please report this to <%s>" 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"],