Skip to content

Commit e7c5593

Browse files
committed
Fix stubtest_third_party.py on linux
Previously, when running it on Linux without the `--specified-platforms-only` flag, it printed spurious warnings and ran stubtest anyway for distributions that didn't include `linux` as a supported platform. Rearrange things: * The `--specified-platforms-only` now works consistently on all platforms. Previously, it was ignored on Linux. * Instead, in CI the flag is added only for non-Linux platforms. * The note about stubtest not running for a certain platform in CI is now printed only after stubtest tested a distribution successfully to avoid breaking the output. Closes: python#13641
1 parent d26a889 commit e7c5593

File tree

4 files changed

+31
-10
lines changed

4 files changed

+31
-10
lines changed

Diff for: .github/workflows/daily.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ jobs:
8484
fi
8585
8686
PYTHON_EXECUTABLE="xvfb-run python"
87+
EXTRA_ARGS=""
8788
else
8889
if [ "${{ runner.os }}" = "macOS" ] && [ -n "$PACKAGES" ]; then
8990
brew install -q $PACKAGES
@@ -94,9 +95,10 @@ jobs:
9495
fi
9596
9697
PYTHON_EXECUTABLE="python"
98+
EXTRA_ARGS="--specified-platforms-only"
9799
fi
98100
99-
$PYTHON_EXECUTABLE tests/stubtest_third_party.py --specified-platforms-only --num-shards 4 --shard-index ${{ matrix.shard-index }}
101+
$PYTHON_EXECUTABLE tests/stubtest_third_party.py $EXTRA_ARGS --num-shards 4 --shard-index ${{ matrix.shard-index }}
100102
101103
stub-uploader:
102104
name: stub_uploader tests

Diff for: .github/workflows/stubtest_third_party.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ jobs:
7171
fi
7272
7373
PYTHON_EXECUTABLE="xvfb-run python"
74+
EXTRA_ARGS=""
7475
else
7576
if [ "${{ runner.os }}" = "macOS" ] && [ -n "$PACKAGES" ]; then
7677
echo "Installing Homebrew packages: $PACKAGES"
@@ -83,9 +84,10 @@ jobs:
8384
fi
8485
8586
PYTHON_EXECUTABLE="python"
87+
EXTRA_ARGS="--specified-platforms-only"
8688
fi
8789
88-
$PYTHON_EXECUTABLE tests/stubtest_third_party.py --specified-platforms-only $STUBS
90+
$PYTHON_EXECUTABLE tests/stubtest_third_party.py $EXTRA_ARGS $STUBS
8991
else
9092
echo "Nothing to test"
9193
fi

Diff for: lib/ts_utils/metadata.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"read_stubtest_settings",
3333
]
3434

35+
DEFAULT_STUBTEST_PLATFORMS = ["linux"]
3536

3637
_STUBTEST_PLATFORM_MAPPING: Final = {"linux": "apt_dependencies", "darwin": "brew_dependencies", "win32": "choco_dependencies"}
3738
# Some older websites have a bad pattern of using query params for navigation.
@@ -91,7 +92,7 @@ def read_stubtest_settings(distribution: str) -> StubtestSettings:
9192
choco_dependencies: object = data.get("choco_dependencies", [])
9293
extras: object = data.get("extras", [])
9394
ignore_missing_stub: object = data.get("ignore_missing_stub", False)
94-
specified_platforms: object = data.get("platforms", ["linux"])
95+
specified_platforms: object = data.get("platforms", [])
9596
stubtest_requirements: object = data.get("stubtest_requirements", [])
9697

9798
assert type(skip) is bool
@@ -109,7 +110,7 @@ def read_stubtest_settings(distribution: str) -> StubtestSettings:
109110
assert not unrecognised_platforms, f"Unrecognised platforms specified for {distribution!r}: {unrecognised_platforms}"
110111

111112
for platform, dep_key in _STUBTEST_PLATFORM_MAPPING.items():
112-
if platform not in specified_platforms:
113+
if platform not in (specified_platforms or DEFAULT_STUBTEST_PLATFORMS):
113114
assert dep_key not in data, (
114115
f"Stubtest is not run on {platform} in CI for {distribution!r}, "
115116
f"but {dep_key!r} are specified in METADATA.toml"

Diff for: tests/stubtest_third_party.py

+22-6
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@
1515
from time import time
1616
from typing import NoReturn
1717

18-
from ts_utils.metadata import NoSuchStubError, get_recursive_requirements, read_metadata
18+
from ts_utils.metadata import (
19+
DEFAULT_STUBTEST_PLATFORMS,
20+
NoSuchStubError,
21+
StubtestSettings,
22+
get_recursive_requirements,
23+
read_metadata,
24+
)
1925
from ts_utils.paths import STUBS_PATH, allowlists_path, tests_path
2026
from ts_utils.utils import (
2127
PYTHON_VERSION,
@@ -46,11 +52,9 @@ def run_stubtest(
4652
print(colored("skipping", "yellow"))
4753
return True
4854

49-
if sys.platform not in stubtest_settings.platforms:
50-
if specified_platforms_only:
51-
print(colored("skipping (platform not specified in METADATA.toml)", "yellow"))
52-
return True
53-
print(colored(f"Note: {dist_name} is not currently tested on {sys.platform} in typeshed's CI.", "yellow"))
55+
if should_skip_dist(stubtest_settings, specified_platforms_only=specified_platforms_only):
56+
print(colored("skipping (platform not specified in METADATA.toml)", "yellow"))
57+
return True
5458

5559
if not metadata.requires_python.contains(PYTHON_VERSION):
5660
print(colored(f"skipping (requires Python {metadata.requires_python})", "yellow"))
@@ -176,6 +180,14 @@ def run_stubtest(
176180
else:
177181
print_time(time() - t)
178182
print_success_msg()
183+
184+
if (
185+
sys.platform not in stubtest_settings.platforms
186+
and sys.platform not in DEFAULT_STUBTEST_PLATFORMS
187+
and not specified_platforms_only
188+
):
189+
print(colored(f"Note: {dist_name} is not currently tested on {sys.platform} in typeshed's CI", "yellow"))
190+
179191
if keep_tmp_dir:
180192
print_info(f"Virtual environment kept at: {venv_dir}")
181193
finally:
@@ -188,6 +200,10 @@ def run_stubtest(
188200
return True
189201

190202

203+
def should_skip_dist(stubtest_settings: StubtestSettings, *, specified_platforms_only: bool) -> bool:
204+
return specified_platforms_only and sys.platform not in stubtest_settings.platforms
205+
206+
191207
def setup_gdb_stubtest_command(venv_dir: Path, stubtest_cmd: list[str]) -> bool:
192208
"""
193209
Use wrapper scripts to run stubtest inside gdb.

0 commit comments

Comments
 (0)