Skip to content

Commit

Permalink
Set dist_name to UNKNOWN when empty outside venv
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
uranusjr committed Apr 24, 2021
1 parent 75ba96c commit e7b1722
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions news/9838.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix compatibility between distutils and sysconfig when the project name is unknown outside of a virtual environment.
3 changes: 3 additions & 0 deletions src/pip/_internal/locations/_sysconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,16 @@ 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)
else:
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"],
Expand Down

0 comments on commit e7b1722

Please sign in to comment.