Skip to content

Commit fab2fc4

Browse files
committed
Use editable project location in pip freeze
1 parent 7d05c4a commit fab2fc4

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/pip/_internal/operations/freeze.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@ def _get_editable_info(dist: BaseDistribution) -> _EditableInfo:
163163
"""
164164
if not dist.editable:
165165
return _EditableInfo(requirement=None, editable=False, comments=[])
166-
if dist.location is None:
166+
editable_project_location = dist.editable_project_location
167+
if editable_project_location is None:
167168
display = _format_as_name_version(dist)
168169
logger.warning("Editable requirement not found on disk: %s", display)
169170
return _EditableInfo(
@@ -172,7 +173,7 @@ def _get_editable_info(dist: BaseDistribution) -> _EditableInfo:
172173
comments=[f"# Editable install not found ({display})"],
173174
)
174175

175-
location = os.path.normcase(os.path.abspath(dist.location))
176+
location = os.path.normcase(os.path.abspath(editable_project_location))
176177

177178
from pip._internal.vcs import RemoteNotFoundError, RemoteNotValidError, vcs
178179

tests/functional/test_freeze.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import pytest
88
from pip._vendor.packaging.utils import canonicalize_name
99

10+
from pip._internal.models.direct_url import DirectUrl
1011
from tests.lib import (
1112
_create_test_package,
1213
_create_test_package_with_srcdir,
@@ -19,6 +20,7 @@
1920
path_to_url,
2021
wheel,
2122
)
23+
from tests.lib.direct_url import get_created_direct_url_path
2224

2325
distribute_re = re.compile('^distribute==[0-9.]+\n', re.MULTILINE)
2426

@@ -833,3 +835,22 @@ def test_freeze_include_work_dir_pkg(script):
833835
# when package directory is in PYTHONPATH
834836
result = script.pip('freeze', cwd=pkg_path)
835837
assert 'simple==1.0' in result.stdout
838+
839+
840+
def test_freeze_pep610_editable(script, with_wheel):
841+
"""
842+
Test that a package installed with a direct_url.json with editable=true
843+
is correctly frozeon as editable.
844+
"""
845+
pkg_path = _create_test_package(script, name="testpkg")
846+
result = script.pip("install", pkg_path)
847+
direct_url_path = get_created_direct_url_path(result, "testpkg")
848+
assert direct_url_path
849+
# patch direct_url.json to simulate an editable install
850+
with open(direct_url_path) as f:
851+
direct_url = DirectUrl.from_json(f.read())
852+
direct_url.info.editable = True
853+
with open(direct_url_path, "w") as f:
854+
f.write(direct_url.to_json())
855+
result = script.pip("freeze")
856+
assert "# Editable Git install with no remote (testpkg==0.1)" in result.stdout

0 commit comments

Comments
 (0)