From 081757e3b5914c70c82230214caa71a08100235c Mon Sep 17 00:00:00 2001 From: Akuli Date: Sat, 10 Sep 2022 16:50:31 +0300 Subject: [PATCH 01/23] Run third-party stubtest under xvfb-run if specified in apt_dependencies Discussed in #8678 --- .github/workflows/daily.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/daily.yml b/.github/workflows/daily.yml index 964b1f72c01a..934f95a2f201 100644 --- a/.github/workflows/daily.yml +++ b/.github/workflows/daily.yml @@ -57,7 +57,8 @@ 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: | + $(which xvfb-run || echo python) tests/stubtest_third_party.py --num-shards 4 --shard-index ${{ matrix.shard-index }} # https://github.community/t/run-github-actions-job-only-if-previous-job-has-failed/174786/2 create-issue-on-failure: From 93ab7a13e6ebefbb489282aaba1fd31de20100bf Mon Sep 17 00:00:00 2001 From: Akuli Date: Sat, 10 Sep 2022 16:52:39 +0300 Subject: [PATCH 02/23] Update tests.yml --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a9adcfe398b7..081d3fb50d32 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -140,7 +140,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 + $(which xvfb-run || true) python tests/stubtest_third_party.py $STUBS else echo "Nothing to test" fi From 9a715d0182a4517bfa5fe084d6926c5e1b6116c8 Mon Sep 17 00:00:00 2001 From: Akuli Date: Sat, 10 Sep 2022 16:53:01 +0300 Subject: [PATCH 03/23] Update daily.yml --- .github/workflows/daily.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/daily.yml b/.github/workflows/daily.yml index 934f95a2f201..1fe05d5a312d 100644 --- a/.github/workflows/daily.yml +++ b/.github/workflows/daily.yml @@ -58,7 +58,7 @@ jobs: sudo apt install -y $(python tests/get_apt_packages.py) - name: Run stubtest run: | - $(which xvfb-run || echo python) tests/stubtest_third_party.py --num-shards 4 --shard-index ${{ matrix.shard-index }} + $(which xvfb-run || true) python tests/stubtest_third_party.py --num-shards 4 --shard-index ${{ matrix.shard-index }} # https://github.community/t/run-github-actions-job-only-if-previous-job-has-failed/174786/2 create-issue-on-failure: From f2817d7dc853cb6952be35e55fa4754dba0b7527 Mon Sep 17 00:00:00 2001 From: Akuli Date: Sat, 10 Sep 2022 16:56:04 +0300 Subject: [PATCH 04/23] Update METADATA.toml --- stubs/pynput/METADATA.toml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/stubs/pynput/METADATA.toml b/stubs/pynput/METADATA.toml index 0e0a8a353b36..dca103c564db 100644 --- a/stubs/pynput/METADATA.toml +++ b/stubs/pynput/METADATA.toml @@ -1,2 +1,4 @@ version = "1.7.*" -stubtest = false # A display server (e.g. X11) is required to import pynput + +[tool.stubtest] +apt_dependencies = ["xvfb"] From b39913cbebe9ccea9ff8686c86e226f1e56544f9 Mon Sep 17 00:00:00 2001 From: Akuli Date: Sat, 10 Sep 2022 17:02:29 +0300 Subject: [PATCH 05/23] Debug --- .github/workflows/tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d119766c0f15..6e5e1c232bff 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -140,6 +140,7 @@ jobs: run: pip install $(grep tomli== requirements-tests.txt) termcolor - name: Run stubtest run: | + set -x STUBS=$( git diff --name-only origin/${{ github.base_ref }} HEAD | # Uncomment the following to (very slowly) run on all third party stubs: From cc9b6757aae33964d268eee4f587d7cc2fe7dd76 Mon Sep 17 00:00:00 2001 From: Akuli Date: Sat, 10 Sep 2022 17:13:51 +0300 Subject: [PATCH 06/23] debug prints --- .github/workflows/tests.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 6e5e1c232bff..0b00bba07616 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -154,7 +154,9 @@ jobs: echo "Installing apt packages: $APT_PACKAGES" sudo apt update && sudo apt install -y $APT_PACKAGES fi - $(which xvfb-run || true) python tests/stubtest_third_party.py $STUBS + xvfb-run python -c 'import os; print(os.getenv("DISPLAY"))' + xvfb-run python -c 'import tkinter; tkinter.Tk()' + xvfb-run python tests/stubtest_third_party.py $STUBS else echo "Nothing to test" fi From f56b14cc50dac9fbfe7c0edfa195a1fa8285906b Mon Sep 17 00:00:00 2001 From: Akuli Date: Sat, 10 Sep 2022 17:14:19 +0300 Subject: [PATCH 07/23] Apparently xvfb is installed by default --- stubs/pynput/METADATA.toml | 3 --- 1 file changed, 3 deletions(-) diff --git a/stubs/pynput/METADATA.toml b/stubs/pynput/METADATA.toml index dca103c564db..ef796600725e 100644 --- a/stubs/pynput/METADATA.toml +++ b/stubs/pynput/METADATA.toml @@ -1,4 +1 @@ version = "1.7.*" - -[tool.stubtest] -apt_dependencies = ["xvfb"] From 5a2996b209d6ec8bc04e3ea3e83829489c680698 Mon Sep 17 00:00:00 2001 From: Akuli Date: Sat, 10 Sep 2022 17:16:42 +0300 Subject: [PATCH 08/23] Pass DISPLAY env var to subprocess --- tests/stubtest_third_party.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/stubtest_third_party.py b/tests/stubtest_third_party.py index cd4a33417c80..ca7003f7736f 100755 --- a/tests/stubtest_third_party.py +++ b/tests/stubtest_third_party.py @@ -5,6 +5,7 @@ import argparse import functools +import os import subprocess import sys import tempfile @@ -87,8 +88,12 @@ def run_stubtest(dist: Path, *, verbose: bool = False) -> bool: if allowlist_path.exists(): stubtest_cmd.extend(["--allowlist", str(allowlist_path)]) + stubtest_env = {"MYPYPATH": str(dist), "MYPY_FORCE_COLOR": "1"} + if "DISPLAY" in os.environ: + stubtest_env["DISPLAY"] = os.environ["DISPLAY"] + 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) From 2e4a711fcdd7f7e86d3f3452838f368fc6f8e8ad Mon Sep 17 00:00:00 2001 From: Akuli Date: Sat, 10 Sep 2022 17:18:04 +0300 Subject: [PATCH 09/23] comment --- tests/stubtest_third_party.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/stubtest_third_party.py b/tests/stubtest_third_party.py index ca7003f7736f..b20d1d70e9a7 100755 --- a/tests/stubtest_third_party.py +++ b/tests/stubtest_third_party.py @@ -90,6 +90,8 @@ def run_stubtest(dist: Path, *, verbose: bool = False) -> bool: stubtest_env = {"MYPYPATH": str(dist), "MYPY_FORCE_COLOR": "1"} if "DISPLAY" in os.environ: + # Set by xvfb-run. Needed for packages that fail to import when + # they think the system doesn't have a screen attached to it. stubtest_env["DISPLAY"] = os.environ["DISPLAY"] try: From 34f63c198a4311cf7dc5b6e205994e09fa4cdef8 Mon Sep 17 00:00:00 2001 From: Akuli Date: Sat, 10 Sep 2022 17:19:50 +0300 Subject: [PATCH 10/23] Stuff --- .github/workflows/daily.yml | 3 +-- .github/workflows/tests.yml | 3 --- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/daily.yml b/.github/workflows/daily.yml index bdf321027f6f..f1e0d00b9f8a 100644 --- a/.github/workflows/daily.yml +++ b/.github/workflows/daily.yml @@ -56,8 +56,7 @@ jobs: sudo apt update sudo apt install -y $(python tests/get_apt_packages.py) - name: Run stubtest - run: | - $(which xvfb-run || true) 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.community/t/run-github-actions-job-only-if-previous-job-has-failed/174786/2 create-issue-on-failure: diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 0b00bba07616..d33c36e638a2 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -140,7 +140,6 @@ jobs: run: pip install $(grep tomli== requirements-tests.txt) termcolor - name: Run stubtest run: | - set -x STUBS=$( git diff --name-only origin/${{ github.base_ref }} HEAD | # Uncomment the following to (very slowly) run on all third party stubs: @@ -154,8 +153,6 @@ jobs: echo "Installing apt packages: $APT_PACKAGES" sudo apt update && sudo apt install -y $APT_PACKAGES fi - xvfb-run python -c 'import os; print(os.getenv("DISPLAY"))' - xvfb-run python -c 'import tkinter; tkinter.Tk()' xvfb-run python tests/stubtest_third_party.py $STUBS else echo "Nothing to test" From e5e99bcbb45a6bc87bcc71f17698ea30d33bc92c Mon Sep 17 00:00:00 2001 From: Akuli Date: Sat, 10 Sep 2022 17:24:08 +0300 Subject: [PATCH 11/23] Let's try this --- .github/workflows/tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d33c36e638a2..72fffcd0b3b8 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -153,6 +153,7 @@ jobs: echo "Installing apt packages: $APT_PACKAGES" sudo apt update && sudo apt install -y $APT_PACKAGES fi + xhost + # Work around a bug in python-xlib https://stackoverflow.com/q/31902846 xvfb-run python tests/stubtest_third_party.py $STUBS else echo "Nothing to test" From 4803bd8015681ab2b3b51979c9663013bdc74486 Mon Sep 17 00:00:00 2001 From: Akuli Date: Sat, 10 Sep 2022 17:25:53 +0300 Subject: [PATCH 12/23] More temporary attempt --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 72fffcd0b3b8..d701525ed14c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -153,7 +153,7 @@ jobs: echo "Installing apt packages: $APT_PACKAGES" sudo apt update && sudo apt install -y $APT_PACKAGES fi - xhost + # Work around a bug in python-xlib https://stackoverflow.com/q/31902846 + sudo apt update && sudo apt install x11-xserver-utils && xhost + # Work around a bug in python-xlib https://stackoverflow.com/q/31902846 xvfb-run python tests/stubtest_third_party.py $STUBS else echo "Nothing to test" From 475b9ebcaa80242af79774a435332710ff1fc397 Mon Sep 17 00:00:00 2001 From: Akuli Date: Sat, 10 Sep 2022 17:26:16 +0300 Subject: [PATCH 13/23] oops --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d701525ed14c..a907917bade3 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -153,7 +153,7 @@ jobs: echo "Installing apt packages: $APT_PACKAGES" sudo apt update && sudo apt install -y $APT_PACKAGES fi - sudo apt update && sudo apt install x11-xserver-utils && xhost + # Work around a bug in python-xlib https://stackoverflow.com/q/31902846 + sudo apt update && sudo apt install -y x11-xserver-utils && xhost + # Work around a bug in python-xlib https://stackoverflow.com/q/31902846 xvfb-run python tests/stubtest_third_party.py $STUBS else echo "Nothing to test" From 4ea6fcb9450cdce2ba40cd3036a719980e3c3dc0 Mon Sep 17 00:00:00 2001 From: Akuli Date: Sat, 10 Sep 2022 17:28:10 +0300 Subject: [PATCH 14/23] s --- .github/workflows/tests.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a907917bade3..eaa60b3db624 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -153,8 +153,9 @@ jobs: echo "Installing apt packages: $APT_PACKAGES" sudo apt update && sudo apt install -y $APT_PACKAGES fi - sudo apt update && sudo apt install -y x11-xserver-utils && xhost + # Work around a bug in python-xlib https://stackoverflow.com/q/31902846 - xvfb-run python tests/stubtest_third_party.py $STUBS + # Work around a bug in python-xlib https://stackoverflow.com/q/31902846 + sudo apt update && sudo apt install -y x11-xserver-utils + xvfb-run bash -c "xhost + && python tests/stubtest_third_party.py $STUBS" else echo "Nothing to test" fi From d43786e792337ae6786566c7e9e9a212e7863c17 Mon Sep 17 00:00:00 2001 From: Akuli Date: Sat, 10 Sep 2022 17:28:51 +0300 Subject: [PATCH 15/23] TEMPORARILY comment out other things --- .github/workflows/tests.yml | 204 ++++++++++++++++++------------------ 1 file changed, 102 insertions(+), 102 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index eaa60b3db624..c42a3e9c3bd2 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -22,108 +22,108 @@ concurrency: cancel-in-progress: true jobs: - file-consistency: - name: Check file consistency - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 - with: - python-version: 3.x - - run: pip install -r requirements-tests.txt - - run: ./tests/check_consistent.py - - new-syntax: - name: Ensure new syntax usage - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 - with: - python-version: 3.x - - run: ./tests/check_new_syntax.py - - flake8: - name: Lint with flake8 - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 - with: - python-version: 3.x - - run: pip install -r requirements-tests.txt - - run: flake8 - - pytype: - name: Run pytype against the stubs - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 - with: - python-version: "3.10" - - run: pip install -r requirements-tests.txt - - run: ./tests/pytype_test.py --print-stderr - - mypy: - name: Run mypy against the stubs - runs-on: ubuntu-latest - strategy: - matrix: - platform: ["linux", "win32", "darwin"] - python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"] - fail-fast: false - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 - with: - python-version: 3.x - - run: pip install -r requirements-tests.txt - - run: ./tests/mypy_test.py --platform=${{ matrix.platform }} --python-version=${{ matrix.python-version }} - - regression-tests: - name: Run mypy on the test cases - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 - with: - python-version: "3.10" - - run: pip install -r requirements-tests.txt - - run: python ./tests/regr_test.py --all - - pyright: - name: Test the stubs with pyright - runs-on: ubuntu-latest - strategy: - matrix: - python-platform: ["Linux", "Windows", "Darwin"] - python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"] - fail-fast: false - env: - PYRIGHT_VERSION: 1.1.266 # Must match pyright_test.py. - steps: - - uses: actions/checkout@v3 - - uses: jakebailey/pyright-action@v1 - with: - version: ${{ env.PYRIGHT_VERSION }} - python-platform: ${{ matrix.python-platform }} - python-version: ${{ matrix.python-version }} - no-comments: ${{ matrix.python-version != '3.10' || matrix.python-platform != 'Linux' }} # Having each job create the same comment is too noisy. - project: ./pyrightconfig.stricter.json - - uses: jakebailey/pyright-action@v1 - with: - version: ${{ env.PYRIGHT_VERSION }} - python-platform: ${{ matrix.python-platform }} - python-version: ${{ matrix.python-version }} - no-comments: ${{ matrix.python-version != '3.10' || matrix.python-platform != 'Linux' }} # Having each job create the same comment is too noisy. - project: ./pyrightconfig.testcases.json - - uses: jakebailey/pyright-action@v1 - with: - version: ${{ env.PYRIGHT_VERSION }} - python-platform: ${{ matrix.python-platform }} - python-version: ${{ matrix.python-version }} - no-comments: ${{ matrix.python-version != '3.10' || matrix.python-platform != 'Linux' }} # Having each job create the same comment is too noisy. +# file-consistency: +# name: Check file consistency +# runs-on: ubuntu-latest +# steps: +# - uses: actions/checkout@v3 +# - uses: actions/setup-python@v4 +# with: +# python-version: 3.x +# - run: pip install -r requirements-tests.txt +# - run: ./tests/check_consistent.py +# +# new-syntax: +# name: Ensure new syntax usage +# runs-on: ubuntu-latest +# steps: +# - uses: actions/checkout@v3 +# - uses: actions/setup-python@v4 +# with: +# python-version: 3.x +# - run: ./tests/check_new_syntax.py +# +# flake8: +# name: Lint with flake8 +# runs-on: ubuntu-latest +# steps: +# - uses: actions/checkout@v3 +# - uses: actions/setup-python@v4 +# with: +# python-version: 3.x +# - run: pip install -r requirements-tests.txt +# - run: flake8 +# +# pytype: +# name: Run pytype against the stubs +# runs-on: ubuntu-latest +# steps: +# - uses: actions/checkout@v3 +# - uses: actions/setup-python@v4 +# with: +# python-version: "3.10" +# - run: pip install -r requirements-tests.txt +# - run: ./tests/pytype_test.py --print-stderr +# +# mypy: +# name: Run mypy against the stubs +# runs-on: ubuntu-latest +# strategy: +# matrix: +# platform: ["linux", "win32", "darwin"] +# python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"] +# fail-fast: false +# steps: +# - uses: actions/checkout@v3 +# - uses: actions/setup-python@v4 +# with: +# python-version: 3.x +# - run: pip install -r requirements-tests.txt +# - run: ./tests/mypy_test.py --platform=${{ matrix.platform }} --python-version=${{ matrix.python-version }} +# +# regression-tests: +# name: Run mypy on the test cases +# runs-on: ubuntu-latest +# steps: +# - uses: actions/checkout@v3 +# - uses: actions/setup-python@v4 +# with: +# python-version: "3.10" +# - run: pip install -r requirements-tests.txt +# - run: python ./tests/regr_test.py --all +# +# pyright: +# name: Test the stubs with pyright +# runs-on: ubuntu-latest +# strategy: +# matrix: +# python-platform: ["Linux", "Windows", "Darwin"] +# python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"] +# fail-fast: false +# env: +# PYRIGHT_VERSION: 1.1.266 # Must match pyright_test.py. +# steps: +# - uses: actions/checkout@v3 +# - uses: jakebailey/pyright-action@v1 +# with: +# version: ${{ env.PYRIGHT_VERSION }} +# python-platform: ${{ matrix.python-platform }} +# python-version: ${{ matrix.python-version }} +# no-comments: ${{ matrix.python-version != '3.10' || matrix.python-platform != 'Linux' }} # Having each job create the same comment is too noisy. +# project: ./pyrightconfig.stricter.json +# - uses: jakebailey/pyright-action@v1 +# with: +# version: ${{ env.PYRIGHT_VERSION }} +# python-platform: ${{ matrix.python-platform }} +# python-version: ${{ matrix.python-version }} +# no-comments: ${{ matrix.python-version != '3.10' || matrix.python-platform != 'Linux' }} # Having each job create the same comment is too noisy. +# project: ./pyrightconfig.testcases.json +# - uses: jakebailey/pyright-action@v1 +# with: +# version: ${{ env.PYRIGHT_VERSION }} +# python-platform: ${{ matrix.python-platform }} +# python-version: ${{ matrix.python-version }} +# no-comments: ${{ matrix.python-version != '3.10' || matrix.python-platform != 'Linux' }} # Having each job create the same comment is too noisy. stubtest-third-party: name: Check third party stubs with stubtest From b1f2389ac38e97c6510d70a32dfe4e048b12f887 Mon Sep 17 00:00:00 2001 From: Akuli Date: Sat, 10 Sep 2022 17:34:49 +0300 Subject: [PATCH 16/23] Just pass all env vars --- tests/stubtest_third_party.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/tests/stubtest_third_party.py b/tests/stubtest_third_party.py index b20d1d70e9a7..61a44fd2e54a 100755 --- a/tests/stubtest_third_party.py +++ b/tests/stubtest_third_party.py @@ -88,11 +88,9 @@ def run_stubtest(dist: Path, *, verbose: bool = False) -> bool: if allowlist_path.exists(): stubtest_cmd.extend(["--allowlist", str(allowlist_path)]) - stubtest_env = {"MYPYPATH": str(dist), "MYPY_FORCE_COLOR": "1"} - if "DISPLAY" in os.environ: - # Set by xvfb-run. Needed for packages that fail to import when - # they think the system doesn't have a screen attached to it. - stubtest_env["DISPLAY"] = os.environ["DISPLAY"] + stubtest_env = dict(os.environ) + stubtest_env["MYPYPATH"] = str(dist) + stubtest_env["MYPY_FORCE_COLOR"] = "1" try: subprocess.run(stubtest_cmd, env=stubtest_env, check=True, capture_output=True) From f5d0d15c1b68c0e28c32695434f93d61edc49c3e Mon Sep 17 00:00:00 2001 From: Akuli Date: Sat, 10 Sep 2022 17:36:56 +0300 Subject: [PATCH 17/23] do we still need this --- .github/workflows/tests.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c42a3e9c3bd2..298935e2748f 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -153,9 +153,7 @@ jobs: echo "Installing apt packages: $APT_PACKAGES" sudo apt update && sudo apt install -y $APT_PACKAGES fi - # Work around a bug in python-xlib https://stackoverflow.com/q/31902846 - sudo apt update && sudo apt install -y x11-xserver-utils - xvfb-run bash -c "xhost + && python tests/stubtest_third_party.py $STUBS" + xvfb-run python tests/stubtest_third_party.py $STUBS else echo "Nothing to test" fi From 7922080da78378c2e7748366ac53ef0204ff1f61 Mon Sep 17 00:00:00 2001 From: Akuli Date: Sat, 10 Sep 2022 17:38:19 +0300 Subject: [PATCH 18/23] Fix env on second run --- tests/stubtest_third_party.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/stubtest_third_party.py b/tests/stubtest_third_party.py index 61a44fd2e54a..a56aa8ded0dd 100755 --- a/tests/stubtest_third_party.py +++ b/tests/stubtest_third_party.py @@ -110,7 +110,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 From 46a4604090fad7d828376d608cd3c1058c142172 Mon Sep 17 00:00:00 2001 From: Akuli Date: Sat, 10 Sep 2022 17:41:44 +0300 Subject: [PATCH 19/23] Create allow list --- stubs/pynput/@tests/stubtest_allowlist.txt | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 stubs/pynput/@tests/stubtest_allowlist.txt diff --git a/stubs/pynput/@tests/stubtest_allowlist.txt b/stubs/pynput/@tests/stubtest_allowlist.txt new file mode 100644 index 000000000000..410c9faa2eb5 --- /dev/null +++ b/stubs/pynput/@tests/stubtest_allowlist.txt @@ -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__ From 01ef521a120446c22c1e153dabd57dc08db8e60c Mon Sep 17 00:00:00 2001 From: Akuli Date: Sat, 10 Sep 2022 17:41:53 +0300 Subject: [PATCH 20/23] Revert "TEMPORARILY comment out other things" This reverts commit d43786e792337ae6786566c7e9e9a212e7863c17. --- .github/workflows/tests.yml | 204 ++++++++++++++++++------------------ 1 file changed, 102 insertions(+), 102 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 298935e2748f..d33c36e638a2 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -22,108 +22,108 @@ concurrency: cancel-in-progress: true jobs: -# file-consistency: -# name: Check file consistency -# runs-on: ubuntu-latest -# steps: -# - uses: actions/checkout@v3 -# - uses: actions/setup-python@v4 -# with: -# python-version: 3.x -# - run: pip install -r requirements-tests.txt -# - run: ./tests/check_consistent.py -# -# new-syntax: -# name: Ensure new syntax usage -# runs-on: ubuntu-latest -# steps: -# - uses: actions/checkout@v3 -# - uses: actions/setup-python@v4 -# with: -# python-version: 3.x -# - run: ./tests/check_new_syntax.py -# -# flake8: -# name: Lint with flake8 -# runs-on: ubuntu-latest -# steps: -# - uses: actions/checkout@v3 -# - uses: actions/setup-python@v4 -# with: -# python-version: 3.x -# - run: pip install -r requirements-tests.txt -# - run: flake8 -# -# pytype: -# name: Run pytype against the stubs -# runs-on: ubuntu-latest -# steps: -# - uses: actions/checkout@v3 -# - uses: actions/setup-python@v4 -# with: -# python-version: "3.10" -# - run: pip install -r requirements-tests.txt -# - run: ./tests/pytype_test.py --print-stderr -# -# mypy: -# name: Run mypy against the stubs -# runs-on: ubuntu-latest -# strategy: -# matrix: -# platform: ["linux", "win32", "darwin"] -# python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"] -# fail-fast: false -# steps: -# - uses: actions/checkout@v3 -# - uses: actions/setup-python@v4 -# with: -# python-version: 3.x -# - run: pip install -r requirements-tests.txt -# - run: ./tests/mypy_test.py --platform=${{ matrix.platform }} --python-version=${{ matrix.python-version }} -# -# regression-tests: -# name: Run mypy on the test cases -# runs-on: ubuntu-latest -# steps: -# - uses: actions/checkout@v3 -# - uses: actions/setup-python@v4 -# with: -# python-version: "3.10" -# - run: pip install -r requirements-tests.txt -# - run: python ./tests/regr_test.py --all -# -# pyright: -# name: Test the stubs with pyright -# runs-on: ubuntu-latest -# strategy: -# matrix: -# python-platform: ["Linux", "Windows", "Darwin"] -# python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"] -# fail-fast: false -# env: -# PYRIGHT_VERSION: 1.1.266 # Must match pyright_test.py. -# steps: -# - uses: actions/checkout@v3 -# - uses: jakebailey/pyright-action@v1 -# with: -# version: ${{ env.PYRIGHT_VERSION }} -# python-platform: ${{ matrix.python-platform }} -# python-version: ${{ matrix.python-version }} -# no-comments: ${{ matrix.python-version != '3.10' || matrix.python-platform != 'Linux' }} # Having each job create the same comment is too noisy. -# project: ./pyrightconfig.stricter.json -# - uses: jakebailey/pyright-action@v1 -# with: -# version: ${{ env.PYRIGHT_VERSION }} -# python-platform: ${{ matrix.python-platform }} -# python-version: ${{ matrix.python-version }} -# no-comments: ${{ matrix.python-version != '3.10' || matrix.python-platform != 'Linux' }} # Having each job create the same comment is too noisy. -# project: ./pyrightconfig.testcases.json -# - uses: jakebailey/pyright-action@v1 -# with: -# version: ${{ env.PYRIGHT_VERSION }} -# python-platform: ${{ matrix.python-platform }} -# python-version: ${{ matrix.python-version }} -# no-comments: ${{ matrix.python-version != '3.10' || matrix.python-platform != 'Linux' }} # Having each job create the same comment is too noisy. + file-consistency: + name: Check file consistency + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: 3.x + - run: pip install -r requirements-tests.txt + - run: ./tests/check_consistent.py + + new-syntax: + name: Ensure new syntax usage + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: 3.x + - run: ./tests/check_new_syntax.py + + flake8: + name: Lint with flake8 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: 3.x + - run: pip install -r requirements-tests.txt + - run: flake8 + + pytype: + name: Run pytype against the stubs + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: "3.10" + - run: pip install -r requirements-tests.txt + - run: ./tests/pytype_test.py --print-stderr + + mypy: + name: Run mypy against the stubs + runs-on: ubuntu-latest + strategy: + matrix: + platform: ["linux", "win32", "darwin"] + python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"] + fail-fast: false + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: 3.x + - run: pip install -r requirements-tests.txt + - run: ./tests/mypy_test.py --platform=${{ matrix.platform }} --python-version=${{ matrix.python-version }} + + regression-tests: + name: Run mypy on the test cases + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: "3.10" + - run: pip install -r requirements-tests.txt + - run: python ./tests/regr_test.py --all + + pyright: + name: Test the stubs with pyright + runs-on: ubuntu-latest + strategy: + matrix: + python-platform: ["Linux", "Windows", "Darwin"] + python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"] + fail-fast: false + env: + PYRIGHT_VERSION: 1.1.266 # Must match pyright_test.py. + steps: + - uses: actions/checkout@v3 + - uses: jakebailey/pyright-action@v1 + with: + version: ${{ env.PYRIGHT_VERSION }} + python-platform: ${{ matrix.python-platform }} + python-version: ${{ matrix.python-version }} + no-comments: ${{ matrix.python-version != '3.10' || matrix.python-platform != 'Linux' }} # Having each job create the same comment is too noisy. + project: ./pyrightconfig.stricter.json + - uses: jakebailey/pyright-action@v1 + with: + version: ${{ env.PYRIGHT_VERSION }} + python-platform: ${{ matrix.python-platform }} + python-version: ${{ matrix.python-version }} + no-comments: ${{ matrix.python-version != '3.10' || matrix.python-platform != 'Linux' }} # Having each job create the same comment is too noisy. + project: ./pyrightconfig.testcases.json + - uses: jakebailey/pyright-action@v1 + with: + version: ${{ env.PYRIGHT_VERSION }} + python-platform: ${{ matrix.python-platform }} + python-version: ${{ matrix.python-version }} + no-comments: ${{ matrix.python-version != '3.10' || matrix.python-platform != 'Linux' }} # Having each job create the same comment is too noisy. stubtest-third-party: name: Check third party stubs with stubtest From 9d76491f257ec3f701f7ef63c429844727e1159a Mon Sep 17 00:00:00 2001 From: Akuli Date: Sat, 10 Sep 2022 17:43:07 +0300 Subject: [PATCH 21/23] Tweak --- tests/stubtest_third_party.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/stubtest_third_party.py b/tests/stubtest_third_party.py index a56aa8ded0dd..7216ab01545a 100755 --- a/tests/stubtest_third_party.py +++ b/tests/stubtest_third_party.py @@ -84,14 +84,12 @@ def run_stubtest(dist: Path, *, verbose: bool = False) -> bool: *packages_to_check, *modules_to_check, ] + 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)]) - stubtest_env = dict(os.environ) - stubtest_env["MYPYPATH"] = str(dist) - stubtest_env["MYPY_FORCE_COLOR"] = "1" - try: subprocess.run(stubtest_cmd, env=stubtest_env, check=True, capture_output=True) except subprocess.CalledProcessError as e: From fc793d55ff705ded1a0fe162efa0a508c1fe048a Mon Sep 17 00:00:00 2001 From: Akuli Date: Sat, 10 Sep 2022 17:44:24 +0300 Subject: [PATCH 22/23] do not skip pyautogui --- stubs/PyAutoGUI/METADATA.toml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/stubs/PyAutoGUI/METADATA.toml b/stubs/PyAutoGUI/METADATA.toml index 94211917e933..524068e98e8b 100644 --- a/stubs/PyAutoGUI/METADATA.toml +++ b/stubs/PyAutoGUI/METADATA.toml @@ -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 From d3b3bfcc417efc8e08da761d854231aff110a15a Mon Sep 17 00:00:00 2001 From: Akuli Date: Sat, 10 Sep 2022 17:49:43 +0300 Subject: [PATCH 23/23] Add comment --- tests/stubtest_third_party.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/stubtest_third_party.py b/tests/stubtest_third_party.py index 7216ab01545a..d2ea39350e36 100755 --- a/tests/stubtest_third_party.py +++ b/tests/stubtest_third_party.py @@ -84,6 +84,13 @@ 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"