mirror of
https://github.com/astral-sh/ruff.git
synced 2025-11-01 12:25:45 +00:00
parent
7c824faa88
commit
6a28f3448e
3 changed files with 182 additions and 41 deletions
|
|
@ -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,24 +14,12 @@ VERSIONS: list[tuple[int, int]] = [
|
|||
(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),
|
||||
""",
|
||||
)
|
||||
|
|
@ -48,9 +27,6 @@ pub fn is_known_standard_library(minor_version: u32, module: &str) -> bool {
|
|||
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 @@ pub fn is_known_standard_library(minor_version: u32, module: &str) -> bool {
|
|||
"sre",
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
modules_by_version[minor_version] = modules
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue