Skip to content

Commit 7a81bd4

Browse files
authored
Re-introduce the 'stubtest' key for third-party packages (#7351)
Some distributions can't be tested with stubtest for a variety of reasons or because of bugs in stubtest. This key: * let's us keep metadata about a distribution in one place, * prevents us from modifying the scripts because of issues with a specific distribution, and * will trigger tests if only the key is changed.
1 parent 64af11c commit 7a81bd4

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed

CONTRIBUTING.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,9 @@ supported:
176176
[removing obsolete third-party libraries](#third-party-library-removal-policy).
177177
It contains the first version of the corresponding library that ships
178178
its own `py.typed` file.
179+
* `stubtest` (default: `true`): Whether stubtest should be run against this
180+
package. Please avoid setting this to `false`, and add a comment if you have
181+
to.
179182
* `stubtest_apt_dependencies` (default: `[]`): A list of Ubuntu APT packages
180183
that need to be installed for stubtest to run successfully. These are
181184
usually packages needed to pip install the implementation distribution.

stubs/SQLAlchemy/METADATA.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ extra_description = """\
33
The `sqlalchemy-stubs` package is an alternative to this package and also \
44
includes a mypy plugin for more precise types.\
55
"""
6+
stubtest = false # https://github.com/python/typeshed/issues/7307

tests/check_consistent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import tomli
1919

2020
consistent_files = [{"stdlib/@python2/builtins.pyi", "stdlib/@python2/__builtin__.pyi"}]
21-
metadata_keys = {"version", "python2", "requires", "extra_description", "obsolete_since", "stubtest_apt_dependencies"}
21+
metadata_keys = {"version", "python2", "requires", "extra_description", "obsolete_since", "stubtest", "stubtest_apt_dependencies"}
2222
allowed_files = {"README.md"}
2323

2424

tests/stubtest_third_party.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import venv
1212
from glob import glob
1313
from pathlib import Path
14-
from typing import NoReturn
14+
from typing import Any, NoReturn
1515

1616
import tomli
1717

@@ -32,7 +32,7 @@ def run_stubtest(dist: Path) -> bool:
3232
with open(dist / "METADATA.toml") as f:
3333
metadata = dict(tomli.loads(f.read()))
3434

35-
if not has_py3_stubs(dist):
35+
if not run_stubtest_for(metadata, dist):
3636
print(f"Skipping stubtest for {dist.name}\n\n")
3737
return True
3838

@@ -115,6 +115,10 @@ def run_stubtest(dist: Path) -> bool:
115115
return True
116116

117117

118+
def run_stubtest_for(metadata: dict[str, Any], dist: Path) -> bool:
119+
return has_py3_stubs(dist) and metadata.get("stubtest", True)
120+
121+
118122
# Keep this in sync with mypy_test.py
119123
def has_py3_stubs(dist: Path) -> bool:
120124
return len(glob(f"{dist}/*.pyi")) > 0 or len(glob(f"{dist}/[!@]*/__init__.pyi")) > 0
@@ -137,9 +141,6 @@ def main() -> NoReturn:
137141
for i, dist in enumerate(dists):
138142
if i % args.num_shards != args.shard_index:
139143
continue
140-
if dist.name == "SQLAlchemy":
141-
# See https://github.com/python/typeshed/issues/7307
142-
continue
143144
if not run_stubtest(dist):
144145
result = 1
145146
sys.exit(result)

0 commit comments

Comments
 (0)