-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Script to update stubinfo.py #18367
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Script to update stubinfo.py #18367
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reason to have the import inline and not at the top? |
||
|
||
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 in stubinfo.py | ||
"distutils", # don't recommend types-setuptools here | ||
}: | ||
continue | ||
print(f'"{p}": "{typeshed_p_to_d[p]}",') | ||
print() | ||
Comment on lines
+45
to
+55
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably personal preference, but if I were to run the script, I'd like it to print the whole dict contents in a sorted order so I just need to copy-paste it. Ideally it would only be outputted if there are any changes to begin with. |
||
|
||
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) | ||
Comment on lines
+57
to
+63
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. |
||
|
||
|
||
if __name__ == "__main__": | ||
main() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At some point we'll remove
tomli
from the requirements. Thesys.version_info
block will get flagged when we update the Python version.