Skip to content

Commit

Permalink
attempt to account for is_relative_to not available in py3.8
Browse files Browse the repository at this point in the history
  • Loading branch information
matteius committed Apr 24, 2024
1 parent b3ad3b2 commit cbd6eaf
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion pipenv/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,21 @@ def dist_is_in_project(self, dist: importlib_metadata.Distribution) -> bool:
if not location:
return False

return any(location.is_relative_to(libdir) for libdir in libdirs)
# Since is_relative_to is not available in Python 3.8, we use a workaround
if sys.version_info == (3, 8):

def is_relative_to(path, to_path):
try:
# Attempt to resolve the relative path
path.relative_to(to_path)
return True
except ValueError:
# If ValueError, it means the path is not relative
return False

return any(is_relative_to(location, Path(libdir)) for libdir in libdirs)
else:
return any(location.is_relative_to(libdir) for libdir in libdirs)

def get_installed_packages(self) -> list[importlib_metadata.Distribution]:
"""Returns all of the installed packages in a given environment"""
Expand Down

0 comments on commit cbd6eaf

Please sign in to comment.