From 64181e8dad950441be36cd40348cf161cb2c022f Mon Sep 17 00:00:00 2001 From: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Date: Sun, 19 Jun 2022 00:43:24 -0700 Subject: [PATCH] stubtest: use separate table in METADATA.toml (#8096) --- CONTRIBUTING.md | 9 ++++++--- stubs/JACK-Client/METADATA.toml | 4 +++- stubs/gdb/METADATA.toml | 3 ++- stubs/pyaudio/METADATA.toml | 4 +++- stubs/pycurl/METADATA.toml | 4 +++- stubs/pynput/METADATA.toml | 4 +++- tests/check_consistent.py | 16 +++++++--------- tests/get_apt_packages.py | 2 +- tests/stubtest_third_party.py | 3 ++- 9 files changed, 30 insertions(+), 19 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 989a59665..29d274f06 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -193,10 +193,13 @@ supported: * `no_longer_updated` (optional): This field is set to `true` before removing stubs for other reasons than the upstream library shipping with type information. -* `stubtest` (default: `true`): Whether stubtest should be run against this - package. Please avoid setting this to `false`, and add a comment if you have + +In addition, we specify configuration for stubtest in the `tool.stubtest` table. +This has the following keys: +* `skip` (default: `false`): Whether stubtest should be run against this + package. Please avoid setting this to `true`, and add a comment if you have to. -* `stubtest_apt_dependencies` (default: `[]`): A list of Ubuntu APT packages +* `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. diff --git a/stubs/JACK-Client/METADATA.toml b/stubs/JACK-Client/METADATA.toml index 432cfba3b..5e65c85ad 100644 --- a/stubs/JACK-Client/METADATA.toml +++ b/stubs/JACK-Client/METADATA.toml @@ -1,2 +1,4 @@ version = "0.5.*" -stubtest_apt_dependencies = ["libjack-dev"] + +[tool.stubtest] +apt_dependencies = ["libjack-dev"] diff --git a/stubs/gdb/METADATA.toml b/stubs/gdb/METADATA.toml index 058aec313..67395fbe8 100644 --- a/stubs/gdb/METADATA.toml +++ b/stubs/gdb/METADATA.toml @@ -7,6 +7,7 @@ extra_description = """\ using `pip`.\ """ +[tool.stubtest] # Since the "gdb" Python package is available only inside GDB, it is not # possible to install it through pip, so stub tests cannot install it. -stubtest = false +skip = true diff --git a/stubs/pyaudio/METADATA.toml b/stubs/pyaudio/METADATA.toml index 0cd32aff1..a259ccae9 100644 --- a/stubs/pyaudio/METADATA.toml +++ b/stubs/pyaudio/METADATA.toml @@ -1,2 +1,4 @@ version = "0.2.*" -stubtest_apt_dependencies = ["portaudio19-dev"] + +[tool.stubtest] +apt_dependencies = ["portaudio19-dev"] diff --git a/stubs/pycurl/METADATA.toml b/stubs/pycurl/METADATA.toml index 354f2a0fc..cdbaaf234 100644 --- a/stubs/pycurl/METADATA.toml +++ b/stubs/pycurl/METADATA.toml @@ -1,2 +1,4 @@ version = "7.44.*" -stubtest_apt_dependencies = ["libcurl4-openssl-dev"] + +[tool.stubtest] +apt_dependencies = ["libcurl4-openssl-dev"] diff --git a/stubs/pynput/METADATA.toml b/stubs/pynput/METADATA.toml index 0e0a8a353..e64b5bd85 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] +skip = true # A display server (e.g. X11) is required to import pynput diff --git a/tests/check_consistent.py b/tests/check_consistent.py index a88a6909b..3d006f9f3 100755 --- a/tests/check_consistent.py +++ b/tests/check_consistent.py @@ -19,15 +19,8 @@ import re import tomli consistent_files = [{"stdlib/@python2/builtins.pyi", "stdlib/@python2/__builtin__.pyi"}] -metadata_keys = { - "version", - "requires", - "extra_description", - "obsolete_since", - "no_longer_updated", - "stubtest", - "stubtest_apt_dependencies", -} +metadata_keys = {"version", "requires", "extra_description", "obsolete_since", "no_longer_updated", "tool"} +tool_keys = {"stubtest": {"skip", "apt_dependencies"}} allowed_files = {"README.md"} @@ -184,6 +177,11 @@ def check_metadata() -> None: for part in dep_version.split("."): assert part.isnumeric(), f"Bad version '{part}' in dependency {dep}" + assert set(data.get("tool", [])).issubset(tool_keys.keys()), f"Unrecognised tool for {distribution}" + for tool, tk in tool_keys.items(): + for key in data.get("tool", {}).get(tool, {}): + assert key in tk, f"Unrecognised {tool} key {key} for {distribution}" + if __name__ == "__main__": check_stdlib() diff --git a/tests/get_apt_packages.py b/tests/get_apt_packages.py index 20cbed8a8..9a902ee99 100755 --- a/tests/get_apt_packages.py +++ b/tests/get_apt_packages.py @@ -10,5 +10,5 @@ if not distributions: for distribution in distributions: with open(f"stubs/{distribution}/METADATA.toml", "rb") as file: - for apt_package in tomli.load(file).get("stubtest_apt_dependencies", []): + for apt_package in tomli.load(file).get("tool", {}).get("stubtest", {}).get("apt_dependencies", []): print(apt_package) diff --git a/tests/stubtest_third_party.py b/tests/stubtest_third_party.py index aedbed8e4..16a904c25 100755 --- a/tests/stubtest_third_party.py +++ b/tests/stubtest_third_party.py @@ -28,7 +28,8 @@ def run_stubtest(dist: Path, *, verbose: bool = False) -> bool: print(f"{dist.name}... ", end="") - if not metadata.get("stubtest", True): + stubtest_meta = metadata.get("tool", {}).get("stubtest", {}) + if stubtest_meta.get("skip", False): print(colored("skipping", "yellow")) return True