diff --git a/crates/ruff_python_stdlib/src/sys.rs b/crates/ruff_python_stdlib/src/sys.rs index 455c5446fff37..07743c2f4a69f 100644 --- a/crates/ruff_python_stdlib/src/sys.rs +++ b/crates/ruff_python_stdlib/src/sys.rs @@ -5,10 +5,96 @@ pub fn is_known_standard_library(minor_version: u8, module: &str) -> bool { (minor_version, module), ( _, - "_ast" + "__hello__" + | "__phello__" + | "_abc" + | "_ast" + | "_asyncio" + | "_bisect" + | "_blake2" + | "_bz2" + | "_codecs" + | "_codecs_cn" + | "_codecs_hk" + | "_codecs_iso2022" + | "_codecs_jp" + | "_codecs_kr" + | "_codecs_tw" + | "_collections" + | "_collections_abc" + | "_compat_pickle" + | "_compression" + | "_contextvars" + | "_crypt" + | "_csv" + | "_ctypes" + | "_ctypes_test" + | "_curses" + | "_curses_panel" + | "_datetime" + | "_dbm" + | "_decimal" + | "_elementtree" + | "_frozen_importlib" + | "_frozen_importlib_external" + | "_functools" + | "_gdbm" + | "_hashlib" + | "_heapq" + | "_imp" + | "_io" + | "_json" + | "_locale" + | "_lsprof" + | "_lzma" + | "_markupbase" + | "_md5" + | "_msi" + | "_multibytecodec" + | "_multiprocessing" + | "_opcode" + | "_operator" + | "_osx_support" + | "_overlapped" + | "_pickle" + | "_posixsubprocess" + | "_py_abc" + | "_pydecimal" + | "_pyio" + | "_queue" + | "_random" + | "_scproxy" + | "_sha1" + | "_sha3" + | "_signal" + | "_sitebuiltins" + | "_socket" + | "_sqlite3" + | "_sre" + | "_ssl" + | "_stat" + | "_string" + | "_strptime" + | "_struct" + | "_symtable" + | "_testbuffer" + | "_testcapi" + | "_testconsole" + | "_testimportmultiple" + | "_testmultiphase" | "_thread" + | "_threading_local" + | "_tkinter" + | "_tracemalloc" + | "_uuid" + | "_warnings" + | "_weakref" + | "_weakrefset" + | "_winapi" + | "_xxtestfuzz" | "abc" | "aifc" + | "antigravity" | "argparse" | "array" | "ast" @@ -65,6 +151,7 @@ pub fn is_known_standard_library(minor_version: u8, module: &str) -> bool { | "ftplib" | "functools" | "gc" + | "genericpath" | "getopt" | "getpass" | "gettext" @@ -76,6 +163,7 @@ pub fn is_known_standard_library(minor_version: u8, module: &str) -> bool { | "hmac" | "html" | "http" + | "idlelib" | "imaplib" | "imghdr" | "importlib" @@ -103,8 +191,11 @@ pub fn is_known_standard_library(minor_version: u8, module: &str) -> bool { | "netrc" | "nis" | "nntplib" + | "nt" | "ntpath" + | "nturl2path" | "numbers" + | "opcode" | "operator" | "optparse" | "os" @@ -128,6 +219,8 @@ pub fn is_known_standard_library(minor_version: u8, module: &str) -> bool { | "py_compile" | "pyclbr" | "pydoc" + | "pydoc_data" + | "pyexpat" | "queue" | "quopri" | "random" @@ -173,8 +266,8 @@ pub fn is_known_standard_library(minor_version: u8, module: &str) -> bool { | "telnetlib" | "tempfile" | "termios" - | "test" | "textwrap" + | "this" | "threading" | "time" | "timeit" @@ -205,13 +298,19 @@ pub fn is_known_standard_library(minor_version: u8, module: &str) -> bool { | "xdrlib" | "xml" | "xmlrpc" + | "xx" + | "xxlimited" + | "xxsubtype" | "zipapp" | "zipfile" | "zipimport" | "zlib" ) | ( 7, - "_dummy_thread" + "_bootlocale" + | "_dummy_thread" + | "_sha256" + | "_sha512" | "asynchat" | "asyncore" | "binhex" @@ -225,7 +324,14 @@ pub fn is_known_standard_library(minor_version: u8, module: &str) -> bool { | "symbol" ) | ( 8, - "_dummy_thread" + "_bootlocale" + | "_dummy_thread" + | "_posixshmem" + | "_sha256" + | "_sha512" + | "_statistics" + | "_testinternalcapi" + | "_xxsubinterpreters" | "asynchat" | "asyncore" | "binhex" @@ -238,7 +344,18 @@ pub fn is_known_standard_library(minor_version: u8, module: &str) -> bool { | "symbol" ) | ( 9, - "asynchat" + "_aix_support" + | "_bootlocale" + | "_bootsubprocess" + | "_peg_parser" + | "_posixshmem" + | "_sha256" + | "_sha512" + | "_statistics" + | "_testinternalcapi" + | "_xxsubinterpreters" + | "_zoneinfo" + | "asynchat" | "asyncore" | "binhex" | "distutils" @@ -246,31 +363,80 @@ pub fn is_known_standard_library(minor_version: u8, module: &str) -> bool { | "graphlib" | "imp" | "parser" + | "peg_parser" | "smtpd" | "symbol" | "zoneinfo" ) | ( 10, - "asynchat" + "_aix_support" + | "_bootsubprocess" + | "_posixshmem" + | "_sha256" + | "_sha512" + | "_statistics" + | "_testclinic" + | "_testinternalcapi" + | "_xxsubinterpreters" + | "_zoneinfo" + | "asynchat" | "asyncore" | "binhex" | "distutils" | "graphlib" - | "idlelib" | "imp" | "smtpd" + | "xxlimited_35" | "zoneinfo" ) | ( 11, - "asynchat" + "__hello_alias__" + | "__hello_only__" + | "__phello_alias__" + | "_aix_support" + | "_bootsubprocess" + | "_posixshmem" + | "_sha256" + | "_sha512" + | "_statistics" + | "_testclinic" + | "_testinternalcapi" + | "_tokenize" + | "_typing" + | "_xxsubinterpreters" + | "_zoneinfo" + | "asynchat" | "asyncore" | "distutils" | "graphlib" - | "idlelib" | "imp" | "smtpd" | "tomllib" + | "xxlimited_35" + | "zoneinfo" + ) | ( + 12, + "__hello_alias__" + | "__hello_only__" + | "__phello_alias__" + | "_aix_support" + | "_posixshmem" + | "_pydatetime" + | "_pylong" + | "_sha2" + | "_statistics" + | "_testclinic" + | "_testinternalcapi" + | "_testsinglephase" + | "_tokenize" + | "_typing" + | "_xxinterpchannels" + | "_xxsubinterpreters" + | "_zoneinfo" + | "graphlib" + | "tomllib" + | "xxlimited_35" | "zoneinfo" - ) | (12, "graphlib" | "idlelib" | "tomllib" | "zoneinfo") + ) ) } diff --git a/scripts/generate_known_standard_library.py b/scripts/generate_known_standard_library.py index 559663b16da88..cbcc1546593fb 100644 --- a/scripts/generate_known_standard_library.py +++ b/scripts/generate_known_standard_library.py @@ -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 @@ (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 @@ class FakeApp: 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", } - 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 diff --git a/scripts/pyproject.toml b/scripts/pyproject.toml index 33ea4c34b9c33..8c68f7a8dfbf3 100644 --- a/scripts/pyproject.toml +++ b/scripts/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "scripts" version = "0.0.1" -dependencies = ["sphinx"] +dependencies = ["stdlibs"] requires-python = ">=3.8" [tool.black]