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 cbd6eaf commit 33261cc
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions pipenv/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,16 +528,14 @@ def dist_is_in_project(self, dist: importlib_metadata.Distribution) -> bool:
# 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)
def is_subpath(path, base_path):
# Ensure both paths are absolute and resolve any symlinks
abs_path = path.resolve()
abs_base_path = base_path.resolve()
# Convert to string and check prefix match
return abs_path.parts[: len(abs_base_path.parts)] == abs_base_path.parts

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

Expand Down

0 comments on commit 33261cc

Please sign in to comment.