Skip to content

Commit 998cd5a

Browse files
authored
Merge branch 'main' into rm-3.7
2 parents 720adbd + 5efa3e8 commit 998cd5a

File tree

13 files changed

+96
-45
lines changed

13 files changed

+96
-45
lines changed

.pre-commit-config.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ exclude: 'src/pip/_vendor/'
22

33
repos:
44
- repo: https://github.com/pre-commit/pre-commit-hooks
5-
rev: v4.4.0
5+
rev: v4.5.0
66
hooks:
77
- id: check-builtin-literals
88
- id: check-added-large-files
@@ -16,19 +16,19 @@ repos:
1616
- id: trailing-whitespace
1717
exclude: .patch
1818

19-
- repo: https://github.com/psf/black
20-
rev: 23.7.0
19+
- repo: https://github.com/psf/black-pre-commit-mirror
20+
rev: 23.12.1
2121
hooks:
2222
- id: black
2323

2424
- repo: https://github.com/astral-sh/ruff-pre-commit
25-
rev: v0.1.4
25+
rev: v0.1.9
2626
hooks:
2727
- id: ruff
2828
args: [--fix, --exit-non-zero-on-fix]
2929

3030
- repo: https://github.com/pre-commit/mirrors-mypy
31-
rev: v1.6.1
31+
rev: v1.8.0
3232
hooks:
3333
- id: mypy
3434
exclude: tests/data

news/12477.feature.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Make pip freeze and pip uninstall of legacy editable installs of packages whose name
2+
contains ``_`` compatible with ``setuptools>=69``.

src/pip/_internal/req/req_uninstall.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,7 @@ def compress_for_output_listing(paths: Iterable[str]) -> Tuple[Set[str], Set[str
172172
folders.add(os.path.dirname(path))
173173
files.add(path)
174174

175-
# probably this one https://github.com/python/mypy/issues/390
176-
_normcased_files = set(map(os.path.normcase, files)) # type: ignore
175+
_normcased_files = set(map(os.path.normcase, files))
177176

178177
folders = compact(folders)
179178

src/pip/_internal/utils/egg_link.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,31 @@
1515
]
1616

1717

18-
def _egg_link_name(raw_name: str) -> str:
18+
def _egg_link_names(raw_name: str) -> List[str]:
1919
"""
2020
Convert a Name metadata value to a .egg-link name, by applying
2121
the same substitution as pkg_resources's safe_name function.
2222
Note: we cannot use canonicalize_name because it has a different logic.
23+
24+
We also look for the raw name (without normalization) as setuptools 69 changed
25+
the way it names .egg-link files (https://github.com/pypa/setuptools/issues/4167).
2326
"""
24-
return re.sub("[^A-Za-z0-9.]+", "-", raw_name) + ".egg-link"
27+
return [
28+
re.sub("[^A-Za-z0-9.]+", "-", raw_name) + ".egg-link",
29+
f"{raw_name}.egg-link",
30+
]
2531

2632

2733
def egg_link_path_from_sys_path(raw_name: str) -> Optional[str]:
2834
"""
2935
Look for a .egg-link file for project name, by walking sys.path.
3036
"""
31-
egg_link_name = _egg_link_name(raw_name)
37+
egg_link_names = _egg_link_names(raw_name)
3238
for path_item in sys.path:
33-
egg_link = os.path.join(path_item, egg_link_name)
34-
if os.path.isfile(egg_link):
35-
return egg_link
39+
for egg_link_name in egg_link_names:
40+
egg_link = os.path.join(path_item, egg_link_name)
41+
if os.path.isfile(egg_link):
42+
return egg_link
3643
return None
3744

3845

@@ -64,9 +71,10 @@ def egg_link_path_from_location(raw_name: str) -> Optional[str]:
6471
sites.append(user_site)
6572
sites.append(site_packages)
6673

67-
egg_link_name = _egg_link_name(raw_name)
74+
egg_link_names = _egg_link_names(raw_name)
6875
for site in sites:
69-
egglink = os.path.join(site, egg_link_name)
70-
if os.path.isfile(egglink):
71-
return egglink
76+
for egg_link_name in egg_link_names:
77+
egglink = os.path.join(site, egg_link_name)
78+
if os.path.isfile(egglink):
79+
return egglink
7280
return None

tests/functional/test_check.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,10 @@ def test_check_complicated_name_missing(script: PipTestEnvironment) -> None:
119119

120120
# Without dependency
121121
result = script.pip("install", "--no-index", package_a_path, "--no-deps")
122-
assert "Successfully installed package-A-1.0" in result.stdout, str(result)
122+
assert (
123+
"Successfully installed package_A-1.0" in result.stdout
124+
or "Successfully installed package-A-1.0" in result.stdout
125+
), str(result)
123126

124127
result = script.pip("check", expect_error=True)
125128
expected_lines = ("package-a 1.0 requires dependency-b, which is not installed.",)
@@ -142,7 +145,10 @@ def test_check_complicated_name_broken(script: PipTestEnvironment) -> None:
142145

143146
# With broken dependency
144147
result = script.pip("install", "--no-index", package_a_path, "--no-deps")
145-
assert "Successfully installed package-A-1.0" in result.stdout, str(result)
148+
assert (
149+
"Successfully installed package_A-1.0" in result.stdout
150+
or "Successfully installed package-A-1.0" in result.stdout
151+
), str(result)
146152

147153
result = script.pip(
148154
"install",
@@ -175,7 +181,10 @@ def test_check_complicated_name_clean(script: PipTestEnvironment) -> None:
175181
)
176182

177183
result = script.pip("install", "--no-index", package_a_path, "--no-deps")
178-
assert "Successfully installed package-A-1.0" in result.stdout, str(result)
184+
assert (
185+
"Successfully installed package_A-1.0" in result.stdout
186+
or "Successfully installed package-A-1.0" in result.stdout
187+
), str(result)
179188

180189
result = script.pip(
181190
"install",
@@ -203,7 +212,10 @@ def test_check_considers_conditional_reqs(script: PipTestEnvironment) -> None:
203212
)
204213

205214
result = script.pip("install", "--no-index", package_a_path, "--no-deps")
206-
assert "Successfully installed package-A-1.0" in result.stdout, str(result)
215+
assert (
216+
"Successfully installed package_A-1.0" in result.stdout
217+
or "Successfully installed package-A-1.0" in result.stdout
218+
), str(result)
207219

208220
result = script.pip("check", expect_error=True)
209221
expected_lines = ("package-a 1.0 requires dependency-b, which is not installed.",)

tests/functional/test_freeze.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ def test_freeze_editable_not_vcs(script: PipTestEnvironment) -> None:
220220
# the freeze code does.
221221
expected = textwrap.dedent(
222222
f"""\
223-
...# Editable install with no version control (version-pkg==0.1)
223+
...# Editable install with no version control (version...pkg==0.1)
224224
-e {os.path.normcase(pkg_path)}
225225
..."""
226226
)
@@ -245,7 +245,7 @@ def test_freeze_editable_git_with_no_remote(
245245
# the freeze code does.
246246
expected = textwrap.dedent(
247247
f"""\
248-
...# Editable Git install with no remote (version-pkg==0.1)
248+
...# Editable Git install with no remote (version...pkg==0.1)
249249
-e {os.path.normcase(pkg_path)}
250250
..."""
251251
)
@@ -483,7 +483,7 @@ def test_freeze_git_remote(script: PipTestEnvironment) -> None:
483483
expected = os.path.normcase(
484484
textwrap.dedent(
485485
f"""
486-
...# Editable Git...(version-pkg...)...
486+
...# Editable Git...(version...pkg...)...
487487
# '{other_remote}'
488488
-e {repo_dir}...
489489
"""

tests/functional/test_install.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ def test_basic_install_editable_from_svn(script: PipTestEnvironment) -> None:
358358
checkout_path = _create_test_package(script.scratch_path)
359359
repo_url = _create_svn_repo(script.scratch_path, checkout_path)
360360
result = script.pip("install", "-e", "svn+" + repo_url + "#egg=version-pkg")
361-
result.assert_installed("version-pkg", with_files=[".svn"])
361+
result.assert_installed("version_pkg", with_files=[".svn"])
362362

363363

364364
def _test_install_editable_from_git(script: PipTestEnvironment) -> None:

tests/functional/test_install_reqs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ def test_install_local_editable_with_subdirectory(script: PipTestEnvironment) ->
295295
),
296296
)
297297

298-
result.assert_installed("version-subpkg", sub_dir="version_subdir")
298+
result.assert_installed("version_subpkg", sub_dir="version_subdir")
299299

300300

301301
@pytest.mark.network

tests/functional/test_install_vcs_git.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ def test_git_with_ambiguous_revs(script: PipTestEnvironment) -> None:
449449
assert "Could not find a tag or branch" not in result.stdout
450450
# it is 'version-pkg' instead of 'version_pkg' because
451451
# egg-link name is version-pkg.egg-link because it is a single .py module
452-
result.assert_installed("version-pkg", with_files=[".git"])
452+
result.assert_installed("version_pkg", with_files=[".git"])
453453

454454

455455
def test_editable__no_revision(script: PipTestEnvironment) -> None:

tests/functional/test_new_resolver.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from typing import TYPE_CHECKING, Callable, Dict, List, Protocol, Tuple
66

77
import pytest
8+
from packaging.utils import canonicalize_name
89

910
from tests.conftest import ScriptFactory
1011
from tests.lib import (
@@ -24,9 +25,13 @@ def assert_editable(script: PipTestEnvironment, *args: str) -> None:
2425
# This simply checks whether all of the listed packages have a
2526
# corresponding .egg-link file installed.
2627
# TODO: Implement a more rigorous way to test for editable installations.
27-
egg_links = {f"{arg}.egg-link" for arg in args}
28-
assert egg_links <= set(
29-
os.listdir(script.site_packages_path)
28+
egg_links = {f"{canonicalize_name(arg)}.egg-link" for arg in args}
29+
actual_egg_links = {
30+
f"{canonicalize_name(p.stem)}.egg-link"
31+
for p in script.site_packages_path.glob("*.egg-link")
32+
}
33+
assert (
34+
egg_links <= actual_egg_links
3035
), f"{args!r} not all found in {script.site_packages_path!r}"
3136

3237

@@ -1844,7 +1849,7 @@ def test_new_resolver_succeeds_on_matching_constraint_and_requirement(
18441849

18451850
script.assert_installed(test_pkg="0.1.0")
18461851
if editable:
1847-
assert_editable(script, "test-pkg")
1852+
assert_editable(script, "test_pkg")
18481853

18491854

18501855
def test_new_resolver_applies_url_constraint_to_dep(script: PipTestEnvironment) -> None:

0 commit comments

Comments
 (0)