Skip to content

Commit 5c0402c

Browse files
committed
Better freeze using direct_url.json
1 parent 532e2cc commit 5c0402c

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

news/609.feature

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Pip freeze now implements PEP 610, so ``pip freeze`` has now better fidelity
2+
in presence of distributions installed from Direct URL requirements.

src/pip/_internal/operations/freeze.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
install_req_from_line,
2020
)
2121
from pip._internal.req.req_file import COMMENT_RE
22+
from pip._internal.utils.direct_url_helpers import (
23+
direct_url_as_pep440_direct_reference,
24+
dist_get_direct_url,
25+
)
2226
from pip._internal.utils.misc import (
2327
dist_is_editable,
2428
get_installed_distributions,
@@ -252,8 +256,20 @@ def __init__(self, name, req, editable, comments=()):
252256
@classmethod
253257
def from_dist(cls, dist):
254258
# type: (Distribution) -> FrozenRequirement
259+
# TODO `get_requirement_info` is taking care of editable requirements.
260+
# TODO This should be refactored when we will add detection of
261+
# TODO editable that provide .dist-info metadata.
255262
req, editable, comments = get_requirement_info(dist)
263+
if req is None and not editable:
264+
# if PEP 610 metadata is present, attempt to use it
265+
direct_url = dist_get_direct_url(dist)
266+
if direct_url:
267+
req = direct_url_as_pep440_direct_reference(
268+
direct_url, dist.project_name
269+
)
270+
comments = []
256271
if req is None:
272+
# name==version requirement
257273
req = dist.as_requirement()
258274

259275
return cls(dist.project_name, req, editable, comments=comments)

tests/functional/test_freeze.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,3 +782,11 @@ def test_freeze_path_multiple(tmpdir, script, data):
782782
simple2==3.0
783783
<BLANKLINE>""")
784784
_check_output(result.stdout, expected)
785+
786+
787+
def test_freeze_direct_url_archive(script, data, with_wheel):
788+
req = "simple @ " + path_to_url(data.packages / "simple-2.0.tar.gz")
789+
assert req.startswith("simple @ file://")
790+
script.pip("install", req)
791+
result = script.pip("freeze")
792+
assert req in result.stdout

0 commit comments

Comments
 (0)