Skip to content

Commit ab02255

Browse files
authored
Run third-party stubtest under xvfb-run (#8719)
1 parent 43d4174 commit ab02255

File tree

6 files changed

+23
-12
lines changed

6 files changed

+23
-12
lines changed

.github/workflows/daily.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
sudo apt update
5757
sudo apt install -y $(python tests/get_apt_packages.py)
5858
- name: Run stubtest
59-
run: python tests/stubtest_third_party.py --num-shards 4 --shard-index ${{ matrix.shard-index }}
59+
run: xvfb-run python tests/stubtest_third_party.py --num-shards 4 --shard-index ${{ matrix.shard-index }}
6060

6161
# https://github.community/t/run-github-actions-job-only-if-previous-job-has-failed/174786/2
6262
create-issue-on-failure:

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ jobs:
153153
echo "Installing apt packages: $APT_PACKAGES"
154154
sudo apt update && sudo apt install -y $APT_PACKAGES
155155
fi
156-
python tests/stubtest_third_party.py $STUBS
156+
xvfb-run python tests/stubtest_third_party.py $STUBS
157157
else
158158
echo "Nothing to test"
159159
fi

stubs/PyAutoGUI/METADATA.toml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,2 @@
11
version = "0.9.*"
22
requires = ["types-Pillow"]
3-
4-
[tool.stubtest]
5-
# pyautogui requires a display, resulting in the following error on the CI:
6-
# failed to import, KeyError: 'DISPLAY'
7-
skip = true
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# TODO: go through this allowlist, figure out which of them are false positives
2+
pynput.keyboard.Controller._Key
3+
pynput.keyboard.Controller._KeyCode
4+
pynput.keyboard.Controller.__init__
5+
pynput.keyboard._base.Controller._Key
6+
pynput.keyboard._base.Controller._KeyCode
7+
pynput.keyboard._dummy.Controller._Key
8+
pynput.keyboard._dummy.Controller._KeyCode
9+
pynput.mouse.Controller.__init__

stubs/pynput/METADATA.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
11
version = "1.7.*"
2-
3-
[tool.stubtest]
4-
skip = true # A display server (e.g. X11) is required to import pynput

tests/stubtest_third_party.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import argparse
77
import functools
8+
import os
89
import subprocess
910
import sys
1011
import tempfile
@@ -83,12 +84,21 @@ def run_stubtest(dist: Path, *, verbose: bool = False) -> bool:
8384
*packages_to_check,
8485
*modules_to_check,
8586
]
87+
88+
# For packages that need a display, we need to pass at least $DISPLAY
89+
# to stubtest. $DISPLAY is set by xvfb-run in CI.
90+
#
91+
# It seems that some other environment variables are needed too,
92+
# because the CI fails if we pass only os.environ["DISPLAY"]. I didn't
93+
# "bisect" to see which variables are actually needed.
94+
stubtest_env = os.environ | {"MYPYPATH": str(dist), "MYPY_FORCE_COLOR": "1"}
95+
8696
allowlist_path = dist / "@tests/stubtest_allowlist.txt"
8797
if allowlist_path.exists():
8898
stubtest_cmd.extend(["--allowlist", str(allowlist_path)])
8999

90100
try:
91-
subprocess.run(stubtest_cmd, env={"MYPYPATH": str(dist), "MYPY_FORCE_COLOR": "1"}, check=True, capture_output=True)
101+
subprocess.run(stubtest_cmd, env=stubtest_env, check=True, capture_output=True)
92102
except subprocess.CalledProcessError as e:
93103
print_error("fail")
94104
print_commands(dist, pip_cmd, stubtest_cmd)
@@ -105,7 +115,7 @@ def run_stubtest(dist: Path, *, verbose: bool = False) -> bool:
105115
print(file=sys.stderr)
106116
else:
107117
print(f"Re-running stubtest with --generate-allowlist.\nAdd the following to {allowlist_path}:", file=sys.stderr)
108-
ret = subprocess.run(stubtest_cmd + ["--generate-allowlist"], env={"MYPYPATH": str(dist)}, capture_output=True)
118+
ret = subprocess.run(stubtest_cmd + ["--generate-allowlist"], env=stubtest_env, capture_output=True)
109119
print_command_output(ret)
110120

111121
return False

0 commit comments

Comments
 (0)