-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Vendor in latest pipdeptree to solve some of the pkg_resources conver…
…sion errors.
- Loading branch information
Showing
9 changed files
with
266 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +0,0 @@ | ||
import os | ||
import sys | ||
|
||
pardir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | ||
# for finding pipdeptree itself | ||
sys.path.append(pardir) | ||
# for finding stuff in vendor and patched | ||
sys.path.append(os.path.dirname(os.path.dirname(pardir))) | ||
|
||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
from __future__ import annotations | ||
|
||
from json import JSONDecodeError | ||
from pathlib import Path | ||
from typing import TYPE_CHECKING | ||
|
||
from pipenv.patched.pip._internal.models.direct_url import ( | ||
DirectUrl, # noqa: PLC2701 | ||
DirectUrlValidationError, # noqa: PLC2701 | ||
) | ||
from pipenv.patched.pip._internal.utils.egg_link import egg_link_path_from_sys_path # noqa: PLC2701 | ||
from pipenv.patched.pip._vendor.packaging.version import Version # noqa: PLC2701 | ||
|
||
if TYPE_CHECKING: | ||
from importlib.metadata import Distribution | ||
|
||
|
||
class PipBaseDistributionAdapter: | ||
""" | ||
An adapter class for pip's `pipenv.patched.pip._internal.metadata.BaseDistribution` abstract class. | ||
It essentially wraps over an importlib.metadata.Distribution object and provides just enough fields/methods found in | ||
pip's `BaseDistribution` so that we can use `pipenv.patched.pip._internal.operations.freeze.FrozenRequirement.from_dist()`. | ||
:param dist: Represents an `importlib.metadata.Distribution` object. | ||
""" | ||
|
||
DIRECT_URL_METADATA_NAME = "direct_url.json" | ||
|
||
def __init__(self, dist: Distribution) -> None: | ||
self._dist = dist | ||
self._raw_name = dist.metadata["Name"] | ||
self._version = Version(dist.version) | ||
|
||
@property | ||
def raw_name(self) -> str: | ||
return self._raw_name | ||
|
||
@property | ||
def version(self) -> Version: | ||
return self._version | ||
|
||
@property | ||
def editable(self) -> bool: | ||
return self.editable_project_location is not None | ||
|
||
@property | ||
def direct_url(self) -> DirectUrl | None: | ||
result = None | ||
json_str = self._dist.read_text(self.DIRECT_URL_METADATA_NAME) | ||
try: | ||
if json_str: | ||
result = DirectUrl.from_json(json_str) | ||
except ( | ||
UnicodeDecodeError, | ||
JSONDecodeError, | ||
DirectUrlValidationError, | ||
): | ||
return result | ||
return result | ||
|
||
@property | ||
def editable_project_location(self) -> str | None: | ||
direct_url = self.direct_url | ||
if direct_url and direct_url.is_local_editable(): | ||
from pipenv.patched.pip._internal.utils.urls import url_to_path # noqa: PLC2701, PLC0415 | ||
|
||
return url_to_path(direct_url.url) | ||
|
||
result = None | ||
egg_link_path = egg_link_path_from_sys_path(self.raw_name) | ||
if egg_link_path: | ||
with Path(egg_link_path).open("r") as f: | ||
result = f.readline().rstrip() | ||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.