Skip to content

Fix stubtest_third_party.py on linux #13643

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
4 changes: 3 additions & 1 deletion .github/workflows/daily.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ jobs:
fi

PYTHON_EXECUTABLE="xvfb-run python"
EXTRA_ARGS=""
else
if [ "${{ runner.os }}" = "macOS" ] && [ -n "$PACKAGES" ]; then
brew install -q $PACKAGES
Expand All @@ -94,9 +95,10 @@ jobs:
fi

PYTHON_EXECUTABLE="python"
EXTRA_ARGS="--specified-platforms-only"
fi

$PYTHON_EXECUTABLE tests/stubtest_third_party.py --specified-platforms-only --num-shards 4 --shard-index ${{ matrix.shard-index }}
$PYTHON_EXECUTABLE tests/stubtest_third_party.py $EXTRA_ARGS --num-shards 4 --shard-index ${{ matrix.shard-index }}

stub-uploader:
name: stub_uploader tests
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/stubtest_third_party.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ jobs:
fi

PYTHON_EXECUTABLE="xvfb-run python"
EXTRA_ARGS=""
else
if [ "${{ runner.os }}" = "macOS" ] && [ -n "$PACKAGES" ]; then
echo "Installing Homebrew packages: $PACKAGES"
Expand All @@ -83,9 +84,10 @@ jobs:
fi

PYTHON_EXECUTABLE="python"
EXTRA_ARGS="--specified-platforms-only"
fi

$PYTHON_EXECUTABLE tests/stubtest_third_party.py --specified-platforms-only $STUBS
$PYTHON_EXECUTABLE tests/stubtest_third_party.py $EXTRA_ARGS $STUBS
else
echo "Nothing to test"
fi
5 changes: 3 additions & 2 deletions lib/ts_utils/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"read_stubtest_settings",
]

DEFAULT_STUBTEST_PLATFORMS = ["linux"]

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

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

for platform, dep_key in _STUBTEST_PLATFORM_MAPPING.items():
if platform not in specified_platforms:
if platform not in (specified_platforms or DEFAULT_STUBTEST_PLATFORMS):
assert dep_key not in data, (
f"Stubtest is not run on {platform} in CI for {distribution!r}, "
f"but {dep_key!r} are specified in METADATA.toml"
Expand Down
28 changes: 22 additions & 6 deletions tests/stubtest_third_party.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@
from time import time
from typing import NoReturn

from ts_utils.metadata import NoSuchStubError, get_recursive_requirements, read_metadata
from ts_utils.metadata import (
DEFAULT_STUBTEST_PLATFORMS,
NoSuchStubError,
StubtestSettings,
get_recursive_requirements,
read_metadata,
)
from ts_utils.paths import STUBS_PATH, allowlists_path, tests_path
from ts_utils.utils import (
PYTHON_VERSION,
Expand Down Expand Up @@ -46,11 +52,9 @@ def run_stubtest(
print(colored("skipping", "yellow"))
return True

if sys.platform not in stubtest_settings.platforms:
if specified_platforms_only:
print(colored("skipping (platform not specified in METADATA.toml)", "yellow"))
return True
print(colored(f"Note: {dist_name} is not currently tested on {sys.platform} in typeshed's CI.", "yellow"))
if should_skip_dist(stubtest_settings, specified_platforms_only=specified_platforms_only):
print(colored("skipping (platform not specified in METADATA.toml)", "yellow"))
return True

if not metadata.requires_python.contains(PYTHON_VERSION):
print(colored(f"skipping (requires Python {metadata.requires_python})", "yellow"))
Expand Down Expand Up @@ -176,6 +180,14 @@ def run_stubtest(
else:
print_time(time() - t)
print_success_msg()

if (
sys.platform not in stubtest_settings.platforms
and sys.platform not in DEFAULT_STUBTEST_PLATFORMS
and not specified_platforms_only
):
print(colored(f"Note: {dist_name} is not currently tested on {sys.platform} in typeshed's CI", "yellow"))

if keep_tmp_dir:
print_info(f"Virtual environment kept at: {venv_dir}")
finally:
Expand All @@ -188,6 +200,10 @@ def run_stubtest(
return True


def should_skip_dist(stubtest_settings: StubtestSettings, *, specified_platforms_only: bool) -> bool:
return specified_platforms_only and sys.platform not in stubtest_settings.platforms


def setup_gdb_stubtest_command(venv_dir: Path, stubtest_cmd: list[str]) -> bool:
"""
Use wrapper scripts to run stubtest inside gdb.
Expand Down
Loading