Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/daily.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
sudo apt update
sudo apt install -y $(python tests/get_apt_packages.py)
- name: Run stubtest
run: python tests/stubtest_third_party.py --num-shards 4 --shard-index ${{ matrix.shard-index }}
run: xvfb-run python tests/stubtest_third_party.py --num-shards 4 --shard-index ${{ matrix.shard-index }}

# https://github.bokerqi.topmunity/t/run-github-actions-job-only-if-previous-job-has-failed/174786/2
create-issue-on-failure:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ jobs:
echo "Installing apt packages: $APT_PACKAGES"
sudo apt update && sudo apt install -y $APT_PACKAGES
fi
python tests/stubtest_third_party.py $STUBS
xvfb-run python tests/stubtest_third_party.py $STUBS
else
echo "Nothing to test"
fi
5 changes: 0 additions & 5 deletions stubs/PyAutoGUI/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,2 @@
version = "0.9.*"
requires = ["types-Pillow"]

[tool.stubtest]
# pyautogui requires a display, resulting in the following error on the CI:
# failed to import, KeyError: 'DISPLAY'
skip = true
9 changes: 9 additions & 0 deletions stubs/pynput/@tests/stubtest_allowlist.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# TODO: go through this allowlist, figure out which of them are false positives
pynput.keyboard.Controller._Key
pynput.keyboard.Controller._KeyCode
pynput.keyboard.Controller.__init__
pynput.keyboard._base.Controller._Key
pynput.keyboard._base.Controller._KeyCode
pynput.keyboard._dummy.Controller._Key
pynput.keyboard._dummy.Controller._KeyCode
pynput.mouse.Controller.__init__
3 changes: 0 additions & 3 deletions stubs/pynput/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
version = "1.7.*"

[tool.stubtest]
skip = true # A display server (e.g. X11) is required to import pynput
14 changes: 12 additions & 2 deletions tests/stubtest_third_party.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import argparse
import functools
import os
import subprocess
import sys
import tempfile
Expand Down Expand Up @@ -83,12 +84,21 @@ def run_stubtest(dist: Path, *, verbose: bool = False) -> bool:
*packages_to_check,
*modules_to_check,
]

# For packages that need a display, we need to pass at least $DISPLAY
# to stubtest. $DISPLAY is set by xvfb-run in CI.
#
# It seems that some other environment variables are needed too,
# because the CI fails if we pass only os.environ["DISPLAY"]. I didn't
# "bisect" to see which variables are actually needed.
stubtest_env = os.environ | {"MYPYPATH": str(dist), "MYPY_FORCE_COLOR": "1"}

allowlist_path = dist / "@tests/stubtest_allowlist.txt"
if allowlist_path.exists():
stubtest_cmd.extend(["--allowlist", str(allowlist_path)])

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

return False
Expand Down