Skip to content

Commit

Permalink
Additional logging to get context
Browse files Browse the repository at this point in the history
  • Loading branch information
uranusjr committed Feb 24, 2021
1 parent a0a3bde commit e0d6028
Showing 1 changed file with 44 additions and 17 deletions.
61 changes: 44 additions & 17 deletions src/pip/_internal/locations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,30 @@ def _default_base(*, user):


def _warn_if_mismatch(old, new, *, key):
# type: (pathlib.Path, pathlib.Path, str) -> None
# type: (pathlib.Path, pathlib.Path, str) -> bool
if old == new:
return
return False
issue_url = "https://github.com/pypa/pip/issues/9617"
message = (
"Value for %s does not match. Please report this to %s"
"Value for %s does not match. Please report this to <%s>"
"\ndistutils: %s"
"\nsysconfig: %s"
)
logger.warning(message, key, issue_url, old, new)
return True


def _log_context(
*,
user: bool = False,
home: Optional[str] = None,
root: Optional[str] = None,
prefix: Optional[str] = None,
) -> None:
message = (
"Additional context:" "\nuser = %r" "\nhome = %r" "\nroot = %r" "\nprefix = %r"
)
logger.warning(message, user, home, root, prefix)


def get_scheme(
Expand Down Expand Up @@ -83,11 +97,15 @@ def get_scheme(
)

base = prefix or home or _default_base(user=user)
warned = []
for k in SCHEME_KEYS:
# Extra join because distutils can return relative paths.
old_v = pathlib.Path(base, getattr(old, k))
new_v = pathlib.Path(getattr(new, k))
_warn_if_mismatch(old_v, new_v, key=f"scheme.{k}")
warned.append(_warn_if_mismatch(old_v, new_v, key=f"scheme.{k}"))

if any(warned):
_log_context(user=user, home=home, root=root, prefix=prefix)

return old

Expand All @@ -96,7 +114,8 @@ def get_bin_prefix():
# type: () -> str
old = _distutils.get_bin_prefix()
new = _sysconfig.get_bin_prefix()
_warn_if_mismatch(pathlib.Path(old), pathlib.Path(new), key="bin_prefix")
if _warn_if_mismatch(pathlib.Path(old), pathlib.Path(new), key="bin_prefix"):
_log_context()
return old


Expand All @@ -105,7 +124,8 @@ def get_purelib():
"""Return the default pure-Python lib location."""
old = _distutils.get_purelib()
new = _sysconfig.get_purelib()
_warn_if_mismatch(pathlib.Path(old), pathlib.Path(new), key="purelib")
if _warn_if_mismatch(pathlib.Path(old), pathlib.Path(new), key="purelib"):
_log_context()
return old


Expand All @@ -114,7 +134,8 @@ def get_platlib():
"""Return the default platform-shared lib location."""
old = _distutils.get_platlib()
new = _sysconfig.get_platlib()
_warn_if_mismatch(pathlib.Path(old), pathlib.Path(new), key="platlib")
if _warn_if_mismatch(pathlib.Path(old), pathlib.Path(new), key="platlib"):
_log_context()
return old


Expand All @@ -123,16 +144,22 @@ 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(
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",
)

warned = [
_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 any(warned):
_log_context(prefix=prefix)

if old_pure == old_plat:
return [old_pure]
return [old_pure, old_plat]

0 comments on commit e0d6028

Please sign in to comment.