Skip to content

Commit 3f08a4e

Browse files
srittauAvasampre-commit-ci[bot]
authored
Split tool.stubtest.platforms metadata key (#13746)
Co-authored-by: Avasam <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 07bbe5e commit 3f08a4e

File tree

27 files changed

+79
-51
lines changed

27 files changed

+79
-51
lines changed

.github/workflows/daily.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ jobs:
9696
PYTHON_EXECUTABLE="python"
9797
fi
9898
99-
$PYTHON_EXECUTABLE tests/stubtest_third_party.py --specified-platforms-only --num-shards 4 --shard-index ${{ matrix.shard-index }}
99+
$PYTHON_EXECUTABLE tests/stubtest_third_party.py --ci-platforms-only --num-shards 4 --shard-index ${{ matrix.shard-index }}
100100
101101
stub-uploader:
102102
name: stub_uploader tests

.github/workflows/stubtest_third_party.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ jobs:
8585
PYTHON_EXECUTABLE="python"
8686
fi
8787
88-
$PYTHON_EXECUTABLE tests/stubtest_third_party.py --specified-platforms-only $STUBS
88+
$PYTHON_EXECUTABLE tests/stubtest_third_party.py --ci-platforms-only $STUBS
8989
else
9090
echo "Nothing to test"
9191
fi

CONTRIBUTING.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -213,18 +213,22 @@ This has the following keys:
213213
that need to be installed for stubtest to run successfully
214214
* `choco_dependencies` (default: `[]`): A list of Windows Chocolatey packages
215215
that need to be installed for stubtest to run successfully
216-
* `platforms` (default: `["linux"]`): A list of OSes on which to run stubtest.
217-
Can contain `win32`, `linux`, and `darwin` values.
218-
If not specified, stubtest is run only on `linux`.
219-
Only add extra OSes to the test
220-
if there are platform-specific branches in a stubs package.
216+
* `supported_platforms` (default: all platforms): A list of OSes on which
217+
stubtest can be run. When a package is not platform-specific, this should
218+
not be set. If the package is platform-specific, this should usually be set
219+
to the supported platforms, unless stubtest is known to fail on a
220+
specific platform.
221+
* `ci_platforms` (default: `["linux"]`): A list of OSes on which to run
222+
stubtest as part of our continuous integration (CI) tests. Can contain
223+
`win32`, `linux`, and `darwin` values. If not specified, stubtest is run
224+
only on `linux`. Only add extra OSes to the test if there are
225+
platform-specific branches in a stubs package.
221226
* `mypy_plugins` (default: `[]`): A list of Python modules to use as mypy plugins
222227
when running stubtest. For example: `mypy_plugins = ["mypy_django_plugin.main"]`
223228
* `mypy_plugins_config` (default: `{}`): A dictionary mapping plugin names to their
224229
configuration dictionaries for use by mypy plugins. For example:
225230
`mypy_plugins_config = {"django-stubs" = {"django_settings_module" = "@tests.django_settings"}}`
226231

227-
228232
`*_dependencies` are usually packages needed to `pip install` the implementation
229233
distribution.
230234

lib/ts_utils/metadata.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"read_stubtest_settings",
4141
]
4242

43+
DEFAULT_STUBTEST_PLATFORMS = ["linux"]
4344

4445
_STUBTEST_PLATFORM_MAPPING: Final = {"linux": "apt_dependencies", "darwin": "brew_dependencies", "win32": "choco_dependencies"}
4546
# Some older websites have a bad pattern of using query params for navigation.
@@ -81,7 +82,8 @@ class StubtestSettings:
8182
choco_dependencies: list[str]
8283
extras: list[str]
8384
ignore_missing_stub: bool
84-
platforms: list[str]
85+
supported_platforms: list[str] | None # None means all platforms
86+
ci_platforms: list[str]
8587
stubtest_requirements: list[str]
8688
mypy_plugins: list[str]
8789
mypy_plugins_config: dict[str, dict[str, Any]]
@@ -105,7 +107,8 @@ def read_stubtest_settings(distribution: str) -> StubtestSettings:
105107
choco_dependencies: object = data.get("choco_dependencies", [])
106108
extras: object = data.get("extras", [])
107109
ignore_missing_stub: object = data.get("ignore_missing_stub", False)
108-
specified_platforms: object = data.get("platforms", ["linux"])
110+
supported_platforms: object = data.get("supported_platforms")
111+
ci_platforms: object = data.get("ci_platforms", DEFAULT_STUBTEST_PLATFORMS)
109112
stubtest_requirements: object = data.get("stubtest_requirements", [])
110113
mypy_plugins: object = data.get("mypy_plugins", [])
111114
mypy_plugins_config: object = data.get("mypy_plugins_config", {})
@@ -114,7 +117,8 @@ def read_stubtest_settings(distribution: str) -> StubtestSettings:
114117
assert type(ignore_missing_stub) is bool
115118

116119
# It doesn't work for type-narrowing if we use a for loop here...
117-
assert _is_list_of_strings(specified_platforms)
120+
assert supported_platforms is None or _is_list_of_strings(supported_platforms)
121+
assert _is_list_of_strings(ci_platforms)
118122
assert _is_list_of_strings(apt_dependencies)
119123
assert _is_list_of_strings(brew_dependencies)
120124
assert _is_list_of_strings(choco_dependencies)
@@ -123,11 +127,16 @@ def read_stubtest_settings(distribution: str) -> StubtestSettings:
123127
assert _is_list_of_strings(mypy_plugins)
124128
assert _is_nested_dict(mypy_plugins_config)
125129

126-
unrecognised_platforms = set(specified_platforms) - _STUBTEST_PLATFORM_MAPPING.keys()
127-
assert not unrecognised_platforms, f"Unrecognised platforms specified for {distribution!r}: {unrecognised_platforms}"
130+
unrecognised_platforms = set(ci_platforms) - _STUBTEST_PLATFORM_MAPPING.keys()
131+
assert not unrecognised_platforms, f"Unrecognised ci_platforms specified for {distribution!r}: {unrecognised_platforms}"
132+
133+
if supported_platforms is not None:
134+
assert set(ci_platforms).issubset(
135+
supported_platforms
136+
), f"ci_platforms must be a subset of supported_platforms for {distribution!r}"
128137

129138
for platform, dep_key in _STUBTEST_PLATFORM_MAPPING.items():
130-
if platform not in specified_platforms:
139+
if platform not in ci_platforms:
131140
assert dep_key not in data, (
132141
f"Stubtest is not run on {platform} in CI for {distribution!r}, "
133142
f"but {dep_key!r} are specified in METADATA.toml"
@@ -140,7 +149,8 @@ def read_stubtest_settings(distribution: str) -> StubtestSettings:
140149
choco_dependencies=choco_dependencies,
141150
extras=extras,
142151
ignore_missing_stub=ignore_missing_stub,
143-
platforms=specified_platforms,
152+
supported_platforms=supported_platforms,
153+
ci_platforms=ci_platforms,
144154
stubtest_requirements=stubtest_requirements,
145155
mypy_plugins=mypy_plugins,
146156
mypy_plugins_config=mypy_plugins_config,
@@ -204,7 +214,8 @@ def is_obsolete(self) -> bool:
204214
"choco_dependencies",
205215
"extras",
206216
"ignore_missing_stub",
207-
"platforms",
217+
"supported_platforms",
218+
"ci_platforms",
208219
"stubtest_requirements",
209220
"mypy_plugins",
210221
"mypy_plugins_config",

lib/ts_utils/utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ def print_info(message: str) -> None:
5050
print(colored(message, "blue"))
5151

5252

53+
def print_warning(message: str) -> None:
54+
print(colored(message, "yellow"))
55+
56+
5357
def print_error(error: str, end: str = "\n", fix_path: tuple[str, str] = ("", "")) -> None:
5458
error_split = error.split("\n")
5559
old, new = fix_path

stubs/JACK-Client/METADATA.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ requires = ["numpy>=1.20", "types-cffi"]
55

66
[tool.stubtest]
77
# darwin and win32 are equivalent
8-
platforms = ["darwin", "linux"]
8+
ci_platforms = ["darwin", "linux"]
99
apt_dependencies = ["libjack-dev"]
1010
brew_dependencies = ["jack"]
1111
# No need to install on the CI. Leaving here as information for Windows contributors.

stubs/PyScreeze/METADATA.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ requires = ["Pillow>=10.3.0"]
44

55
[tool.stubtest]
66
# Linux has extra constants, win32 has different definitions
7-
platforms = ["linux", "win32"]
7+
ci_platforms = ["linux", "win32"]
88
# PyScreeze has an odd setup.py file
99
# that doesn't list Pillow as a dependency for py312+ yet:
1010
# https://github.com/asweigart/pyscreeze/blob/eeca245a135cf171c163b3691300138518efa64e/setup.py#L38-L46

stubs/RPi.GPIO/METADATA.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ version = "0.7.*"
22
upstream_repository = "https://sourceforge.net/p/raspberry-gpio-python/code/"
33

44
[tool.stubtest]
5-
# When stubtest tries to import this module:
6-
# error: RPi.GPIO failed to import. RuntimeError: This module can only be run on a Raspberry Pi!
5+
# This package is only supported on Raspberry Pi hardware, which identifies
6+
# itself as 'linux'. When run on other hardware, it raises a RuntimeError:
7+
# RPi.GPIO failed to import. RuntimeError: This module can only be run on a Raspberry Pi!
78
# https://sourceforge.net/p/raspberry-gpio-python/code/ci/08048dd1894a6b09a104557b6eaa6bb68b6baac5/tree/source/py_gpio.c#l1008
8-
skip = true
9+
supported_platforms = []
10+
ci_platforms = []

stubs/aiofiles/METADATA.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ upstream_repository = "https://github.com/Tinche/aiofiles"
33

44
[tool.stubtest]
55
# linux and darwin are equivalent
6-
platforms = ["linux", "win32"]
6+
ci_platforms = ["linux", "win32"]

stubs/antlr4-python3-runtime/METADATA.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ version = "4.13.*"
22
upstream_repository = "https://github.com/antlr/antlr4"
33

44
[tool.stubtest]
5-
platforms = ["linux", "win32"]
5+
ci_platforms = ["linux", "win32"]

0 commit comments

Comments
 (0)