Skip to content

Commit

Permalink
Merge pull request #9838 from uranusjr/sysconfig-header-with-none-pro…
Browse files Browse the repository at this point in the history
…ject

Set project name to UNKNOWN when empty
  • Loading branch information
sbidoul authored Apr 25, 2021
2 parents 75ba96c + 2a009a0 commit 914bcc3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
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.
8 changes: 7 additions & 1 deletion src/pip/_internal/locations/_sysconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,20 @@ 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)
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 914bcc3

Please sign in to comment.