Skip to content

Commit

Permalink
Better freeze using direct_url.json
Browse files Browse the repository at this point in the history
  • Loading branch information
sbidoul committed Feb 1, 2020
1 parent ea498ec commit bdd6e58
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions news/609.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Pip freeze now implements PEP 610, so ``pip freeze`` has now better fidelity
in presence of distributions installed from Direct URL requirements.
16 changes: 16 additions & 0 deletions src/pip/_internal/operations/freeze.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
install_req_from_line,
)
from pip._internal.req.req_file import COMMENT_RE
from pip._internal.utils.direct_url_helpers import (
direct_url_as_pep440_direct_reference,
dist_get_direct_url,
)
from pip._internal.utils.misc import (
dist_is_editable,
get_installed_distributions,
Expand Down Expand Up @@ -252,8 +256,20 @@ def __init__(self, name, req, editable, comments=()):
@classmethod
def from_dist(cls, dist):
# type: (Distribution) -> FrozenRequirement
# TODO `get_requirement_info` is taking care of editable requirements.
# TODO This should be refactored when we will add detection of
# TODO editable that provide .dist-info metadata.
req, editable, comments = get_requirement_info(dist)
if req is None and not editable:
# if PEP 610 metadata is present, attempt to use it
direct_url = dist_get_direct_url(dist)
if direct_url:
req = direct_url_as_pep440_direct_reference(
direct_url, dist.project_name
)
comments = []
if req is None:
# name==version requirement
req = dist.as_requirement()

return cls(dist.project_name, req, editable, comments=comments)
Expand Down
8 changes: 8 additions & 0 deletions tests/functional/test_freeze.py
Original file line number Diff line number Diff line change
Expand Up @@ -782,3 +782,11 @@ def test_freeze_path_multiple(tmpdir, script, data):
simple2==3.0
<BLANKLINE>""")
_check_output(result.stdout, expected)


def test_freeze_direct_url_archive(script, data, with_wheel):
req = "simple @ " + path_to_url(data.packages / "simple-2.0.tar.gz")
assert req.startswith("simple @ file://")
script.pip("install", req)
result = script.pip("freeze")
assert req in result.stdout

0 comments on commit bdd6e58

Please sign in to comment.