-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Migrate sys.rs generation to stdlibs #11374
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 |
---|---|---|
@@ -1,18 +1,9 @@ | ||
"""Vendored from scripts/mkstdlibs.py in PyCQA/isort. | ||
|
||
Source: | ||
https://github.com/PyCQA/isort/blob/e321a670d0fefdea0e04ed9d8d696434cf49bdec/scripts/mkstdlibs.py | ||
|
||
Only the generation of the file has been modified for use in this project. | ||
""" | ||
|
||
from __future__ import annotations | ||
|
||
from pathlib import Path | ||
|
||
from sphinx.ext.intersphinx import fetch_inventory | ||
from stdlibs import stdlib_module_names | ||
|
||
URL = "https://docs.python.org/{}/objects.inv" | ||
PATH = Path("crates") / "ruff_python_stdlib" / "src" / "sys.rs" | ||
VERSIONS: list[tuple[int, int]] = [ | ||
(3, 7), | ||
|
@@ -23,34 +14,19 @@ | |
(3, 12), | ||
] | ||
|
||
|
||
class FakeConfig: | ||
intersphinx_timeout = None | ||
tls_verify = True | ||
user_agent = "" | ||
|
||
|
||
class FakeApp: | ||
srcdir = "" | ||
config = FakeConfig() | ||
|
||
|
||
with PATH.open("w") as f: | ||
f.write( | ||
"""\ | ||
//! This file is generated by `scripts/generate_known_standard_library.py` | ||
|
||
pub fn is_known_standard_library(minor_version: u32, module: &str) -> bool { | ||
pub fn is_known_standard_library(minor_version: u8, module: &str) -> bool { | ||
matches!((minor_version, module), | ||
""", | ||
) | ||
|
||
modules_by_version = {} | ||
|
||
for major_version, minor_version in VERSIONS: | ||
url = URL.format(f"{major_version}.{minor_version}") | ||
invdata = fetch_inventory(FakeApp(), "", url) | ||
|
||
modules = { | ||
"_ast", | ||
"posixpath", | ||
|
@@ -61,10 +37,9 @@ class FakeApp: | |
"sre", | ||
} | ||
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. These hardcoded ones should probably be removed and change to 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. |
||
|
||
for module in invdata["py:module"]: | ||
root, *_ = module.split(".") | ||
if root not in ["__future__", "__main__"]: | ||
modules.add(root) | ||
for module in stdlib_module_names(f"{major_version}.{minor_version}"): | ||
if module not in ["__future__", "__main__"]: | ||
modules.add(module) | ||
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. I don't think 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. |
||
|
||
modules_by_version[minor_version] = modules | ||
|
||
|
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.
stdlibs also supports 3.13 already, btw: https://gist.github.com/thatch/0c7015ef2e0b6c457eb52a558f14beb1