From 24d90e283d9a837a49433c9a4bd354e9714d1a92 Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Sun, 29 Dec 2024 15:52:57 -0800 Subject: [PATCH 1/2] Script to update stubinfo.py --- misc/update-stubinfo.py | 64 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 misc/update-stubinfo.py diff --git a/misc/update-stubinfo.py b/misc/update-stubinfo.py new file mode 100644 index 000000000000..b12eb4a2857d --- /dev/null +++ b/misc/update-stubinfo.py @@ -0,0 +1,64 @@ +import argparse +from pathlib import Path + +import tomli as tomllib + + +def main() -> None: + parser = argparse.ArgumentParser() + parser.add_argument("--typeshed", type=Path, required=True) + args = parser.parse_args() + + typeshed_p_to_d = {} + for stub in (args.typeshed / "stubs").iterdir(): + if not stub.is_dir(): + continue + try: + metadata = tomllib.loads((stub / "METADATA.toml").read_text()) + except FileNotFoundError: + continue + d = metadata.get("stub_distribution", f"types-{stub.name}") + for p in stub.iterdir(): + if not p.stem.isidentifier(): + continue + if p.is_dir() and not any(f.suffix == ".pyi" for f in p.iterdir()): + # ignore namespace packages + continue + if p.is_file() and p.suffix != ".pyi": + continue + typeshed_p_to_d[p.stem] = d + + import mypy.stubinfo + + mypy_p = set(mypy.stubinfo.non_bundled_packages_flat) | set( + mypy.stubinfo.legacy_bundled_packages + ) + + for p in typeshed_p_to_d.keys() & mypy_p: + mypy_d = mypy.stubinfo.non_bundled_packages_flat.get(p) + mypy_d = mypy_d or mypy.stubinfo.legacy_bundled_packages.get(p) + if mypy_d != typeshed_p_to_d[p]: + raise ValueError( + f"stub_distribution mismatch for {p}: {mypy_d} != {typeshed_p_to_d[p]}" + ) + + print("=" * 40) + print("Add the following to non_bundled_packages_flat:") + print("=" * 40) + for p in sorted(typeshed_p_to_d.keys() - mypy_p): + if p in {"pika"}: # see comment + continue + print(f'"{p}": "{typeshed_p_to_d[p]}",') + print() + + print("=" * 40) + print("Consider removing the following packages no longer in typeshed:") + print("=" * 40) + for p in sorted(mypy_p - typeshed_p_to_d.keys()): + if p in {"lxml", "pandas"}: # never in typeshed + continue + print(p) + + +if __name__ == "__main__": + main() From b13105062bbf38b0ec5db7d366282efa2f1041b6 Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Sun, 29 Dec 2024 16:22:04 -0800 Subject: [PATCH 2/2] distutils --- misc/update-stubinfo.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/misc/update-stubinfo.py b/misc/update-stubinfo.py index b12eb4a2857d..beaed34a8a47 100644 --- a/misc/update-stubinfo.py +++ b/misc/update-stubinfo.py @@ -46,7 +46,10 @@ def main() -> None: print("Add the following to non_bundled_packages_flat:") print("=" * 40) for p in sorted(typeshed_p_to_d.keys() - mypy_p): - if p in {"pika"}: # see comment + if p in { + "pika", # see comment in stubinfo.py + "distutils", # don't recommend types-setuptools here + }: continue print(f'"{p}": "{typeshed_p_to_d[p]}",') print()