Skip to content

Commit 7871ed9

Browse files
committed
Switch PEP 561 tests to a different build backend (#15451)
Fixes #15446 setuptools has broken how editable installs work. It seems like most other build backends continue to use static pth files, so let's just switch to another one.
1 parent 87ddfee commit 7871ed9

File tree

12 files changed

+64
-97
lines changed

12 files changed

+64
-97
lines changed

Diff for: mypy/test/testpep561.py

+15-17
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,16 @@ def virtualenv(python_executable: str = sys.executable) -> Iterator[tuple[str, s
4747

4848

4949
def install_package(
50-
pkg: str, python_executable: str = sys.executable, use_pip: bool = True, editable: bool = False
50+
pkg: str, python_executable: str = sys.executable, editable: bool = False
5151
) -> None:
5252
"""Install a package from test-data/packages/pkg/"""
5353
working_dir = os.path.join(package_path, pkg)
5454
with tempfile.TemporaryDirectory() as dir:
55-
if use_pip:
56-
install_cmd = [python_executable, "-m", "pip", "install"]
57-
if editable:
58-
install_cmd.append("-e")
59-
install_cmd.append(".")
60-
else:
61-
install_cmd = [python_executable, "setup.py"]
62-
if editable:
63-
install_cmd.append("develop")
64-
else:
65-
install_cmd.append("install")
55+
install_cmd = [python_executable, "-m", "pip", "install"]
56+
if editable:
57+
install_cmd.append("-e")
58+
install_cmd.append(".")
59+
6660
# Note that newer versions of pip (21.3+) don't
6761
# follow this env variable, but this is for compatibility
6862
env = {"PIP_BUILD": dir}
@@ -82,21 +76,25 @@ def test_pep561(testcase: DataDrivenTestCase) -> None:
8276
assert testcase.old_cwd is not None, "test was not properly set up"
8377
python = sys.executable
8478

79+
if sys.version_info < (3, 8) and testcase.location[-1] == "testTypedPkgSimpleEditable":
80+
# Python 3.7 doesn't ship with new enough pip to support PEP 660
81+
# This is a quick hack to skip the test; we'll drop Python 3.7 support soon enough
82+
return
83+
8584
assert python is not None, "Should be impossible"
8685
pkgs, pip_args = parse_pkgs(testcase.input[0])
8786
mypy_args = parse_mypy_args(testcase.input[1])
88-
use_pip = True
8987
editable = False
9088
for arg in pip_args:
91-
if arg == "no-pip":
92-
use_pip = False
93-
elif arg == "editable":
89+
if arg == "editable":
9490
editable = True
91+
else:
92+
raise ValueError(f"Unknown pip argument: {arg}")
9593
assert pkgs, "No packages to install for PEP 561 test?"
9694
with virtualenv(python) as venv:
9795
venv_dir, python_executable = venv
9896
for pkg in pkgs:
99-
install_package(pkg, python_executable, use_pip, editable)
97+
install_package(pkg, python_executable, editable)
10098

10199
cmd_line = list(mypy_args)
102100
has_program = not ("-p" in cmd_line or "--package" in cmd_line)

Diff for: test-data/packages/typedpkg-stubs/pyproject.toml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[project]
2+
name = 'typedpkg-stubs'
3+
version = '0.1'
4+
description = 'test'
5+
6+
[tool.hatch.build]
7+
include = ["**/*.pyi"]
8+
9+
[build-system]
10+
requires = ["hatchling"]
11+
build-backend = "hatchling.build"

Diff for: test-data/packages/typedpkg-stubs/setup.py

-13
This file was deleted.

Diff for: test-data/packages/typedpkg/pyproject.toml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[project]
2+
name = 'typedpkg'
3+
version = '0.1'
4+
description = 'test'
5+
6+
[build-system]
7+
requires = ["hatchling"]
8+
build-backend = "hatchling.build"

Diff for: test-data/packages/typedpkg/setup.py

-15
This file was deleted.

Diff for: test-data/packages/typedpkg_ns_a/pyproject.toml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[project]
2+
name = 'typedpkg_namespace.alpha'
3+
version = '0.1'
4+
description = 'test'
5+
6+
[tool.hatch.build]
7+
include = ["**/*.py", "**/*.pyi", "**/py.typed"]
8+
9+
[build-system]
10+
requires = ["hatchling"]
11+
build-backend = "hatchling.build"

Diff for: test-data/packages/typedpkg_ns_a/setup.py

-10
This file was deleted.
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[project]
2+
name = 'typedpkg_ns-stubs'
3+
version = '0.1'
4+
description = 'test'
5+
6+
[tool.hatch.build]
7+
include = ["**/*.pyi"]
8+
9+
[build-system]
10+
requires = ["hatchling"]
11+
build-backend = "hatchling.build"

Diff for: test-data/packages/typedpkg_ns_b-stubs/setup.py

-14
This file was deleted.

Diff for: test-data/packages/typedpkg_ns_b/pyproject.toml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[project]
2+
name = 'typedpkg_namespace.beta'
3+
version = '0.1'
4+
description = 'test'
5+
6+
[build-system]
7+
requires = ["hatchling"]
8+
build-backend = "hatchling.build"

Diff for: test-data/packages/typedpkg_ns_b/setup.py

-10
This file was deleted.

Diff for: test-data/unit/pep561.test

-18
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,6 @@ reveal_type(a)
7272
[out]
7373
testStubPrecedence.py:5: note: Revealed type is "builtins.list[builtins.str]"
7474

75-
[case testTypedPkgSimpleEgg]
76-
# pkgs: typedpkg; no-pip
77-
from typedpkg.sample import ex
78-
from typedpkg import dne
79-
a = ex([''])
80-
reveal_type(a)
81-
[out]
82-
testTypedPkgSimpleEgg.py:5: note: Revealed type is "builtins.tuple[builtins.str, ...]"
83-
8475
[case testTypedPkgSimpleEditable]
8576
# pkgs: typedpkg; editable
8677
from typedpkg.sample import ex
@@ -90,15 +81,6 @@ reveal_type(a)
9081
[out]
9182
testTypedPkgSimpleEditable.py:5: note: Revealed type is "builtins.tuple[builtins.str, ...]"
9283

93-
[case testTypedPkgSimpleEditableEgg]
94-
# pkgs: typedpkg; editable; no-pip
95-
from typedpkg.sample import ex
96-
from typedpkg import dne
97-
a = ex([''])
98-
reveal_type(a)
99-
[out]
100-
testTypedPkgSimpleEditableEgg.py:5: note: Revealed type is "builtins.tuple[builtins.str, ...]"
101-
10284
[case testTypedPkgNamespaceImportFrom]
10385
# pkgs: typedpkg, typedpkg_ns_a
10486
from typedpkg.pkg.aaa import af

0 commit comments

Comments
 (0)