Skip to content

Commit 24d90e2

Browse files
committed
Script to update stubinfo.py
1 parent ac6151a commit 24d90e2

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

misc/update-stubinfo.py

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

0 commit comments

Comments
 (0)