Skip to content

Commit

Permalink
Type fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
uranusjr committed Feb 22, 2021
1 parent 08c2829 commit 790bd02
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
12 changes: 10 additions & 2 deletions src/pip/_internal/locations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,16 @@ def get_prefixed_libs(prefix):
"""Return the lib locations under ``prefix``."""
old_pure, old_plat = _distutils.get_prefixed_libs(prefix)
new_pure, new_plat = _sysconfig.get_prefixed_libs(prefix)
_warn_if_mismatch(old_pure, new_pure, key="prefixed-purelib")
_warn_if_mismatch(old_plat, new_plat, key="prefixed-platlib")
_warn_if_mismatch(
pathlib.Path(old_pure),
pathlib.Path(new_pure),
key="prefixed-purelib",
)
_warn_if_mismatch(
pathlib.Path(old_plat),
pathlib.Path(new_plat),
key="prefixed-platlib",
)
if old_pure == old_plat:
return [old_pure]
return [old_pure, old_plat]
25 changes: 13 additions & 12 deletions src/pip/_internal/locations/_sysconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@


def _infer_scheme(variant):
# (typing.Literal["home", "prefix", "user"]) -> str
# type: (typing.Literal["home", "prefix", "user"]) -> str
"""Try to find a scheme for the current platform.
Unfortunately ``_get_default_scheme()`` is private, so there's no way to
Expand Down Expand Up @@ -46,16 +46,16 @@ def _infer_scheme(variant):


# Update these keys if the user sets a custom home.
_HOME_KEYS = (
_HOME_KEYS = [
"installed_base",
"base",
"installed_platbase",
"platbase",
"prefix",
"exec_prefix",
)
]
if sysconfig.get_config_var("userbase") is not None:
_HOME_KEYS += ("userbase",)
_HOME_KEYS.append("userbase")


def get_scheme(
Expand Down Expand Up @@ -86,11 +86,11 @@ def get_scheme(
raise InvalidSchemeCombination("--home", "--prefix")

if home is not None:
scheme = _infer_scheme("home")
scheme_name = _infer_scheme("home")
elif user:
scheme = _infer_scheme("user")
scheme_name = _infer_scheme("user")
else:
scheme = _infer_scheme("prefix")
scheme_name = _infer_scheme("prefix")

if home is not None:
variables = {k: home for k in _HOME_KEYS}
Expand All @@ -99,7 +99,7 @@ def get_scheme(
else:
variables = {}

paths = sysconfig.get_paths(scheme=scheme, vars=variables)
paths = sysconfig.get_paths(scheme=scheme_name, vars=variables)

# Special header path for compatibility to distutils.
if running_under_virtualenv():
Expand All @@ -126,21 +126,22 @@ def get_bin_prefix():
# Forcing to use /usr/local/bin for standard macOS framework installs.
if sys.platform[:6] == "darwin" and sys.prefix[:16] == "/System/Library/":
return "/usr/local/bin"
return sysconfig.get_path("scripts", scheme=_infer_scheme("prefix"))
return sysconfig.get_paths(scheme=_infer_scheme("prefix"))["scripts"]


def get_bin_user():
return sysconfig.get_path("scripts", scheme=_infer_scheme("user"))
# type: () -> str
return sysconfig.get_paths(scheme=_infer_scheme("user"))["scripts"]


def get_purelib():
# type: () -> str
return sysconfig.get_path("purelib")
return sysconfig.get_paths()["purelib"]


def get_platlib():
# type: () -> str
return sysconfig.get_path("platlib")
return sysconfig.get_paths()["platlib"]


def get_prefixed_libs(prefix):
Expand Down
2 changes: 1 addition & 1 deletion src/pip/_internal/locations/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ def get_src_prefix():
try:
# Use getusersitepackages if this is present, as it ensures that the
# value is initialised properly.
user_site = site.getusersitepackages()
user_site = site.getusersitepackages() # type: typing.Optional[str]
except AttributeError:
user_site = site.USER_SITE

0 comments on commit 790bd02

Please sign in to comment.