Skip to content

Commit 8cf4db2

Browse files
committed
Script to update stubinfo.py
1 parent ac6151a commit 8cf4db2

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

misc/update-stubinfo.py

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import argparse
2+
import tomllib
3+
from pathlib import Path
4+
5+
6+
def main() -> None:
7+
parser = argparse.ArgumentParser()
8+
parser.add_argument("--typeshed", type=Path, required=True)
9+
args = parser.parse_args()
10+
11+
typeshed_p_to_d = {}
12+
for stub in (args.typeshed / "stubs").iterdir():
13+
if not stub.is_dir():
14+
continue
15+
try:
16+
metadata = tomllib.loads((stub / "METADATA.toml").read_text())
17+
except FileNotFoundError:
18+
continue
19+
d = metadata.get("stub_distribution", f"types-{stub.name}")
20+
for p in stub.iterdir():
21+
if not p.stem.isidentifier():
22+
continue
23+
if p.is_dir() and not any(f.suffix == ".pyi" for f in p.iterdir()):
24+
# ignore namespace packages
25+
continue
26+
if p.is_file() and p.suffix != ".pyi":
27+
continue
28+
typeshed_p_to_d[p.stem] = d
29+
30+
import mypy.stubinfo
31+
32+
mypy_p = set(mypy.stubinfo.non_bundled_packages_flat) | set(mypy.stubinfo.legacy_bundled_packages)
33+
34+
for p in (typeshed_p_to_d.keys() & mypy_p):
35+
mypy_d = mypy.stubinfo.non_bundled_packages_flat.get(p)
36+
mypy_d = mypy_d or mypy.stubinfo.legacy_bundled_packages.get(p)
37+
assert mypy_d == typeshed_p_to_d[p], f"stub_distribution mismatch for {p}: {mypy_d} != {typeshed_p_to_d[p]}"
38+
39+
print("=" * 40)
40+
print("Add the following to non_bundled_packages_flat:")
41+
print("=" * 40)
42+
for p in sorted(typeshed_p_to_d.keys() - mypy_p):
43+
if p in {"pika"}: # see comment
44+
continue
45+
print(f'"{p}": "{typeshed_p_to_d[p]}",')
46+
print()
47+
48+
print("=" * 40)
49+
print("Consider removing the following packages no longer in typeshed:")
50+
print("=" * 40)
51+
for p in sorted(mypy_p - typeshed_p_to_d.keys()):
52+
if p in {"lxml", "pandas"}: # never in typeshed
53+
continue
54+
print(p)
55+
56+
57+
if __name__ == "__main__":
58+
main()

0 commit comments

Comments
 (0)