Skip to content

Re-introduce the 'stubtest' key for third-party packages #7351

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ supported:
[removing obsolete third-party libraries](#third-party-library-removal-policy).
It contains the first version of the corresponding library that ships
its own `py.typed` file.
* `stubtest` (default: `true`): Whether stubtest should be run against this
package. Please avoid setting this to `false`, and add a comment if you have
to.
* `stubtest_apt_dependencies` (default: `[]`): A list of Ubuntu APT packages
that need to be installed for stubtest to run successfully. These are
usually packages needed to pip install the implementation distribution.
Expand Down
1 change: 1 addition & 0 deletions stubs/SQLAlchemy/METADATA.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ extra_description = """\
The `sqlalchemy-stubs` package is an alternative to this package and also \
includes a mypy plugin for more precise types.\
"""
stubtest = false # https://github.com/python/typeshed/issues/7307
2 changes: 1 addition & 1 deletion tests/check_consistent.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import tomli

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


Expand Down
11 changes: 6 additions & 5 deletions tests/stubtest_third_party.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import venv
from glob import glob
from pathlib import Path
from typing import NoReturn
from typing import Any, NoReturn

import tomli

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

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

Expand Down Expand Up @@ -115,6 +115,10 @@ def run_stubtest(dist: Path) -> bool:
return True


def run_stubtest_for(metadata: dict[str, Any], dist: Path) -> bool:
return has_py3_stubs(dist) and metadata.get("stubtest", True)


# Keep this in sync with mypy_test.py
def has_py3_stubs(dist: Path) -> bool:
return len(glob(f"{dist}/*.pyi")) > 0 or len(glob(f"{dist}/[!@]*/__init__.pyi")) > 0
Expand All @@ -137,9 +141,6 @@ def main() -> NoReturn:
for i, dist in enumerate(dists):
if i % args.num_shards != args.shard_index:
continue
if dist.name == "SQLAlchemy":
# See https://github.com/python/typeshed/issues/7307
continue
if not run_stubtest(dist):
result = 1
sys.exit(result)
Expand Down