-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
59 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Add ``--report`` to the install command to generate a json report of what was installed. | ||
In combination with ``--dry-run`` and ``--ignore-installed`` it can be used to resolve | ||
the requirements. |
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,37 @@ | ||
from typing import Any, Dict | ||
|
||
from pip._internal.req.req_install import InstallRequirement | ||
from pip._internal.req.req_set import RequirementSet | ||
|
||
|
||
class InstallationReport: | ||
def __init__(self, req_set: RequirementSet): | ||
self._req_set = req_set | ||
|
||
@classmethod | ||
def _install_req_to_dict(cls, ireq: InstallRequirement) -> Dict[str, Any]: | ||
assert ireq.download_info, f"No download_info for {ireq}" | ||
res = { | ||
# PEP 610 json for the download URL | ||
"download_info": ireq.download_info.to_dict(), | ||
# is_direct is true if the requirement was a direct URL reference (which | ||
# includes editable requirements), and false if the requirement was | ||
# downloaded from a PEP 503 index or --find-links. | ||
"is_direct": bool(ireq.original_link), | ||
# requested is true if the requirement was specified by the user (aka | ||
# top level requirement), and false if it was installed as a dependency of a | ||
# requirement. https://peps.python.org/pep-0376/#requested | ||
"requested": ireq.user_supplied, | ||
# PEP 566 json encoding for metadata | ||
# https://www.python.org/dev/peps/pep-0566/#json-compatible-metadata | ||
"metadata": ireq.get_dist().json_metadata, | ||
} | ||
return res | ||
|
||
def to_dict(self) -> Dict[str, Any]: | ||
return { | ||
"install": { | ||
name: self._install_req_to_dict(ireq) | ||
for name, ireq in self._req_set.requirements.items() | ||
} | ||
} |