From 78e2dee5ef9153e76cf7582d40c1cdccf944545c Mon Sep 17 00:00:00 2001 From: hauntsaninja <> Date: Fri, 17 Jun 2022 23:14:18 -0700 Subject: [PATCH 1/3] stubtest_third_party: use separate table in METADATA.toml --- 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 | 11 +++++++++-- tests/get_apt_packages.py | 2 +- tests/stubtest_third_party.py | 3 ++- 9 files changed, 32 insertions(+), 12 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 989a59665b03..29d274f06175 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 432cfba3b0a8..5e65c85ad252 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 058aec313428..67395fbe8bb2 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 0cd32aff1015..a259ccae9200 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 354f2a0fc08c..cdbaaf234ef8 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 0e0a8a353b36..e64b5bd8558f 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 a88a6909b796..d09cb835ef9b 100755 --- a/tests/check_consistent.py +++ b/tests/check_consistent.py @@ -25,8 +25,11 @@ "extra_description", "obsolete_since", "no_longer_updated", - "stubtest", - "stubtest_apt_dependencies", + "tool", +} +stubtest_keys = { + "skip", + "apt_dependencies", } allowed_files = {"README.md"} @@ -184,6 +187,10 @@ 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({"stubtest"}), f"Unrecognised tool for {distribution}" + for key in data.get("tool", {}).get("stubtest", {}): + assert key in stubtest_keys, f"Unrecognised stubtest key {key} for {distribution}" + if __name__ == "__main__": check_stdlib() diff --git a/tests/get_apt_packages.py b/tests/get_apt_packages.py index 20cbed8a848d..9a902ee99d1d 100755 --- a/tests/get_apt_packages.py +++ b/tests/get_apt_packages.py @@ -10,5 +10,5 @@ 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 aedbed8e4ed6..16a904c25cd2 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 From ef5aee16fa30516a4f6dd5d765ca27381a57c707 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 18 Jun 2022 06:43:40 +0000 Subject: [PATCH 2/3] [pre-commit.ci] auto fixes from pre-commit.com hooks --- tests/check_consistent.py | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/tests/check_consistent.py b/tests/check_consistent.py index d09cb835ef9b..29c9dd02c57b 100755 --- a/tests/check_consistent.py +++ b/tests/check_consistent.py @@ -19,18 +19,8 @@ import tomli consistent_files = [{"stdlib/@python2/builtins.pyi", "stdlib/@python2/__builtin__.pyi"}] -metadata_keys = { - "version", - "requires", - "extra_description", - "obsolete_since", - "no_longer_updated", - "tool", -} -stubtest_keys = { - "skip", - "apt_dependencies", -} +metadata_keys = {"version", "requires", "extra_description", "obsolete_since", "no_longer_updated", "tool"} +stubtest_keys = {"skip", "apt_dependencies"} allowed_files = {"README.md"} From d8b7176e0963433df4742280113def139ced8790 Mon Sep 17 00:00:00 2001 From: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Date: Sat, 18 Jun 2022 21:58:28 -0700 Subject: [PATCH 3/3] Apply suggestions from code review Co-authored-by: Sebastian Rittau --- tests/check_consistent.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/check_consistent.py b/tests/check_consistent.py index 29c9dd02c57b..3d006f9f382c 100755 --- a/tests/check_consistent.py +++ b/tests/check_consistent.py @@ -20,7 +20,7 @@ consistent_files = [{"stdlib/@python2/builtins.pyi", "stdlib/@python2/__builtin__.pyi"}] metadata_keys = {"version", "requires", "extra_description", "obsolete_since", "no_longer_updated", "tool"} -stubtest_keys = {"skip", "apt_dependencies"} +tool_keys = {"stubtest": {"skip", "apt_dependencies"}} allowed_files = {"README.md"} @@ -177,9 +177,10 @@ 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({"stubtest"}), f"Unrecognised tool for {distribution}" - for key in data.get("tool", {}).get("stubtest", {}): - assert key in stubtest_keys, f"Unrecognised stubtest key {key} for {distribution}" + 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__":