Skip to content
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

Run stubtest on stubs on different platforms #8923

Merged
merged 31 commits into from
Nov 11, 2022
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
61deba6
Run stubtest on stubs on different platforms
sobolevn Oct 18, 2022
0a96d99
Fix CI
sobolevn Oct 18, 2022
8149e3c
Fix CI
sobolevn Oct 18, 2022
7d364f7
Fix CI
sobolevn Oct 18, 2022
1a9af3a
Address review
sobolevn Oct 19, 2022
f00714a
Run daily on differeny platforms
sobolevn Oct 19, 2022
3f31bed
Fix daily run
sobolevn Oct 19, 2022
8eb0c83
Merge branch 'master' into run-stubs-on-different-platforms
AlexWaygood Oct 19, 2022
c8650b3
Rename `stubtest` files
sobolevn Oct 19, 2022
770c5aa
Merge branch 'run-stubs-on-different-platforms' of https://github.com…
sobolevn Oct 19, 2022
fdf13bb
Add platform-specific allowlists for stubs
sobolevn Oct 19, 2022
c84fe27
Fix CI
sobolevn Oct 19, 2022
40a4c50
Fix CI
sobolevn Oct 19, 2022
025568b
Try `Pillow~=7.1.2`
sobolevn Oct 19, 2022
c8b6472
Skip `D3DShot`
sobolevn Oct 19, 2022
21eb994
Revert `win32` change
sobolevn Oct 19, 2022
ac06a7c
Fix CI
sobolevn Oct 24, 2022
081ebba
Merge branch 'master' into run-stubs-on-different-platforms
sobolevn Oct 24, 2022
0be8c9b
Address review
sobolevn Oct 25, 2022
ec000eb
Merge branch 'run-stubs-on-different-platforms' of https://github.com…
sobolevn Oct 25, 2022
3bb8296
Update CONTRIBUTING.md
sobolevn Oct 26, 2022
870daa6
Merge main
sobolevn Nov 9, 2022
c4f86da
Fix allowlist of win32
sobolevn Nov 9, 2022
183ea56
Merge branch 'main' into run-stubs-on-different-platforms
AlexWaygood Nov 9, 2022
a6b1cab
Update stubtest_allowlist_win32.txt
sobolevn Nov 9, 2022
bf2f10e
Update tests/get_packages.py
sobolevn Nov 9, 2022
578f619
Merge remote-tracking branch 'origin/main' into run-stubs-on-differen…
AlexWaygood Nov 11, 2022
7df5a1f
Delete unused allowlist entries
AlexWaygood Nov 11, 2022
949bf46
Update CONTRIBUTING.md
sobolevn Nov 11, 2022
faac1be
Apply suggestions from code review
sobolevn Nov 11, 2022
9464335
Add TODO comment back
AlexWaygood Nov 11, 2022
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
18 changes: 12 additions & 6 deletions .github/workflows/daily.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ jobs:
stubtest-third-party:
name: Check third party stubs with stubtest
if: ${{ github.repository == 'python/typeshed' || github.event_name == 'workflow_dispatch' }}
runs-on: ubuntu-20.04
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: ["ubuntu-latest", "windows-latest", "macos-latest"]
shard-index: [0, 1, 2, 3]
fail-fast: false
steps:
Expand All @@ -56,12 +57,17 @@ jobs:
python-version: "3.9"
- name: Install dependencies
run: pip install -r requirements-tests.txt
- name: Install apt packages
run: |
sudo apt update
sudo apt install -y $(python tests/get_apt_packages.py)
- name: Run stubtest
run: xvfb-run python tests/stubtest_third_party.py --num-shards 4 --shard-index ${{ matrix.shard-index }}
shell: bash
run: |
if [ "${{ matrix.os }}" = "ubuntu-latest" ]; then
sudo apt update
sudo apt install -y $(python tests/get_packages.py)

xvfb-run python tests/stubtest_third_party.py --num-shards 4 --shard-index ${{ matrix.shard-index }}
else
python tests/stubtest_third_party.py --num-shards 4 --shard-index ${{ matrix.shard-index }}
fi

stub-uploader:
name: Run the stub_uploader tests
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/stubtest_stdlib.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Run stubtest
name: Stdlib stubtest

on:
workflow_dispatch:
Expand Down
70 changes: 70 additions & 0 deletions .github/workflows/stubtest_third_party.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: Third-party stubtest

on:
pull_request:
paths-ignore:
- '**/*.md'
- 'scripts/**'

permissions:
contents: read

env:
PIP_DISABLE_PIP_VERSION_CHECK: 1

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
stubtest-third-party:
name: Check third party stubs with stubtest

runs-on: ${{ matrix.os }}
strategy:
matrix:
os: ["ubuntu-latest", "windows-latest", "macos-latest"]
fail-fast: false

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-python@v4
with:
python-version: "3.9"
- name: Install dependencies
run: pip install -r requirements-tests.txt
- name: Run stubtest
shell: bash
run: |
STUBS=$(
git diff --name-only origin/${{ github.base_ref }} HEAD |
# Uncomment the following to (very slowly) run on all third party stubs:
# git ls-files |
sobolevn marked this conversation as resolved.
Show resolved Hide resolved
egrep ^stubs/ | cut -d "/" -f 2 | sort -u | (while read stub; do [ -d stubs/$stub ] && echo $stub || true; done)
)

if [ -n "$STUBS" ]; then
echo "Testing $STUBS..."
PACKAGES=$(python tests/get_packages.py $STUBS)

if [ "${{ matrix.os }}" = "ubuntu-latest" ]; then
if [ -n "$PACKAGES" ]; then
echo "Installing apt packages: $PACKAGES"
sudo apt update && sudo apt install -y $PACKAGES
fi
xvfb-run python tests/stubtest_third_party.py $STUBS
fi

if [ "${{ matrix.os }}" = "macos-latest" ]; then
# TODO: install brew packages
sobolevn marked this conversation as resolved.
Show resolved Hide resolved
python tests/stubtest_third_party.py $STUBS
fi

if [ "${{ matrix.os }}" = "windows-latest" ]; then
python tests/stubtest_third_party.py $STUBS
sobolevn marked this conversation as resolved.
Show resolved Hide resolved
fi
else
echo "Nothing to test"
fi
33 changes: 0 additions & 33 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,36 +146,3 @@ jobs:
cd stub_uploader
pip install -r requirements.txt
python -m pytest tests

stubtest-third-party:
name: Check third party stubs with stubtest
runs-on: ubuntu-20.04
if: github.event_name == 'pull_request'
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-python@v4
with:
python-version: "3.9"
- name: Install dependencies
run: pip install -r requirements-tests.txt
- name: Run stubtest
run: |
STUBS=$(
git diff --name-only origin/${{ github.base_ref }} HEAD |
# Uncomment the following to (very slowly) run on all third party stubs:
# git ls-files |
egrep ^stubs/ | cut -d "/" -f 2 | sort -u | (while read stub; do [ -d stubs/$stub ] && echo $stub || true; done)
)
if test -n "$STUBS"; then
echo "Testing $STUBS..."
APT_PACKAGES=$(python tests/get_apt_packages.py $STUBS)
if test -n "$APT_PACKAGES"; then
echo "Installing apt packages: $APT_PACKAGES"
sudo apt update && sudo apt install -y $APT_PACKAGES
fi
xvfb-run python tests/stubtest_third_party.py $STUBS
else
echo "Nothing to test"
fi
5 changes: 5 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ This has the following keys:
* `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.
* `platforms` (default: `["linux"]`): A list of OSes on which to run stubtest.
Can contain `win32`, `linux`, and `darwin` values.
If not specified, tests are run only on `linux`.
sobolevn marked this conversation as resolved.
Show resolved Hide resolved
Only add extra OSes to the test
if there are platform-specific branches in a stubs package.

The format of all `METADATA.toml` files can be checked by running
`python3 ./tests/check_consistent.py`.
Expand Down
4 changes: 2 additions & 2 deletions stubs/D3DShot/METADATA.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ version = "0.1.*"
requires = ["types-Pillow"]

[tool.stubtest]
# The library only works on Windows; we currently only run stubtest on Ubuntu for third-party stubs in CI.
# See #8660
# TODO: re-enable
Copy link
Member Author

@sobolevn sobolevn Nov 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# TODO: re-enable

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, this TODO comment I did like -- it would be good if we could figure out how to enable stubtest for this package!

skip = true
AlexWaygood marked this conversation as resolved.
Show resolved Hide resolved
platforms = ["win32"]
1 change: 1 addition & 0 deletions stubs/JACK-Client/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
version = "0.5.*"

[tool.stubtest]
platforms = ["linux"]
apt_dependencies = ["libjack-dev"]
1 change: 1 addition & 0 deletions stubs/pyaudio/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
version = "0.2.*"

[tool.stubtest]
platforms = ["linux"]
apt_dependencies = ["portaudio19-dev"]
1 change: 1 addition & 0 deletions stubs/pycurl/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
version = "7.45.*"

[tool.stubtest]
platforms = ["linux"]
apt_dependencies = ["libcurl4-openssl-dev"]
5 changes: 2 additions & 3 deletions stubs/pywin32/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
version = "305.*"

[tool.stubtest]
platforms = ["win32"]
ignore_missing_stub = false
# The library only works on Windows; we currently only run stubtest on Ubuntu for third-party stubs in CI.
# See #8660
skip = true
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 @@
from utils import VERSIONS_RE, get_all_testcase_directories, get_gitignore_spec, spec_matches_path, strip_comments

metadata_keys = {"version", "requires", "extra_description", "obsolete_since", "no_longer_updated", "tool"}
tool_keys = {"stubtest": {"skip", "apt_dependencies", "extras", "ignore_missing_stub"}}
tool_keys = {"stubtest": {"skip", "apt_dependencies", "extras", "ignore_missing_stub", "platforms"}}
extension_descriptions = {".pyi": "stub", ".py": ".py"}


Expand Down
14 changes: 0 additions & 14 deletions tests/get_apt_packages.py

This file was deleted.

23 changes: 23 additions & 0 deletions tests/get_packages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env python3
import os
import sys

import tomli

platform = sys.platform
distributions = sys.argv[1:]
if not distributions:
distributions = os.listdir("stubs")

metadata_mapping = {
"linux": "apt_dependencies",
# We could add others here if we run into stubs that need it:
# "darwin": "brew_dependencies",
# "win32": "choco_dependencies",
}

if platform in metadata_mapping:
for distribution in distributions:
with open(f"stubs/{distribution}/METADATA.toml", "rb") as file:
for package in tomli.load(file).get("tool", {}).get("stubtest", {}).get(metadata_mapping[platform], []):
print(package)
10 changes: 9 additions & 1 deletion tests/stubtest_third_party.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ def run_stubtest(dist: Path, *, verbose: bool = False) -> bool:
print(colored("skipping", "yellow"))
return True

platforms_to_test = stubtest_meta.get("platforms", ["linux"])
if sys.platform not in platforms_to_test:
print(colored(f"skipping, unsupported platform: {sys.platform}, supported: {platforms_to_test}", "yellow"))
return True

with tempfile.TemporaryDirectory() as tmp:
venv_dir = Path(tmp)
venv.create(venv_dir, with_pip=True, clear=True)
Expand All @@ -57,8 +62,8 @@ def run_stubtest(dist: Path, *, verbose: bool = False) -> bool:
# If @tests/requirements-stubtest.txt exists, run "pip install" on it.
req_path = dist / "@tests" / "requirements-stubtest.txt"
if req_path.exists():
pip_cmd = [pip_exe, "install", "-r", str(req_path)]
try:
pip_cmd = [pip_exe, "install", "-r", str(req_path)]
subprocess.run(pip_cmd, check=True, capture_output=True)
except subprocess.CalledProcessError as e:
print_command_failure("Failed to install requirements", e)
Expand Down Expand Up @@ -102,6 +107,9 @@ def run_stubtest(dist: Path, *, verbose: bool = False) -> bool:
allowlist_path = dist / "@tests/stubtest_allowlist.txt"
if allowlist_path.exists():
stubtest_cmd.extend(["--allowlist", str(allowlist_path)])
platform_allowlist = dist / f"@tests/stubtest_allowlist_{sys.platform}.txt"
if platform_allowlist.exists():
stubtest_cmd.extend(["--allowlist", str(platform_allowlist)])

try:
subprocess.run(stubtest_cmd, env=stubtest_env, check=True, capture_output=True)
Expand Down