Skip to content

Commit e7745f1

Browse files
committed
Python 3.15 __lazy_modules__ (auto-applied w/ flake8-lazy --apply=set)
1 parent 4e612f9 commit e7745f1

63 files changed

Lines changed: 496 additions & 9 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎newsfragments/5257.feature.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Speed up setuptools imports on Python 3.15+ by adding ``__lazy_modules__`` -- by :user:`Avasam`

‎pyproject.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ check = [
116116

117117
# Deprecated rules must now be selected by exact rule code
118118
"ruff >= 0.13.0; sys_platform != 'cygwin'",
119+
"flake8-lazy", # Until Ruff gains support for automatically inserting and validating __lazy_modules__
119120
]
120121

121122
cover = [

‎ruff.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ exclude = [
55
]
66

77
[lint]
8+
external=["LZY"]
89
extend-select = [
910
# upstream
1011

‎setuptools/__init__.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@
77

88
from __future__ import annotations
99

10+
__lazy_modules__ = {
11+
"collections",
12+
"collections.abc",
13+
"functools",
14+
f"{__spec__.parent}.depends",
15+
f"{__spec__.parent}.dist",
16+
f"{__spec__.parent}.extension",
17+
f"{__spec__.parent}.version",
18+
f"{__spec__.parent}.warnings",
19+
}
20+
1021
import functools
1122
import os
1223
import sys

‎setuptools/_core_metadata.py‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,22 @@
66

77
from __future__ import annotations
88

9+
__lazy_modules__ = {
10+
"distutils",
11+
"distutils.util",
12+
"email",
13+
"email.message",
14+
"packaging",
15+
"packaging.markers",
16+
"packaging.requirements",
17+
"packaging.utils",
18+
"packaging.version",
19+
"tempfile",
20+
"textwrap",
21+
f"{__spec__.parent}._static",
22+
f"{__spec__.parent}.warnings",
23+
}
24+
925
import os
1026
import stat
1127
import textwrap

‎setuptools/_discovery.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
__lazy_modules__ = {"functools", "operator", "packaging", "packaging.requirements"}
2+
13
import functools
24
import operator
35

‎setuptools/_entry_points.py‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
__lazy_modules__ = {
2+
"itertools",
3+
"jaraco",
4+
"jaraco.text",
5+
"more_itertools",
6+
"operator",
7+
f"{__spec__.parent}._itertools",
8+
f"{__spec__.parent}.errors",
9+
}
10+
111
import functools
212
import itertools
313
import operator
@@ -6,7 +16,7 @@
616
from jaraco.text import yield_lines
717
from more_itertools import consume
818

9-
from ._importlib import metadata
19+
from ._importlib import metadata # noqa: LZY102
1020
from ._itertools import ensure_unique
1121
from .errors import OptionError
1222

‎setuptools/_imp.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from the deprecated imp module.
44
"""
55

6+
__lazy_modules__ = {"importlib", "importlib.machinery", "importlib.util", "tokenize"}
7+
68
import importlib.machinery
79
import importlib.util
810
import os

‎setuptools/_importlib.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
__lazy_modules__ = {"importlib"}
2+
13
from importlib import (
24
metadata, # noqa: F401
35
resources, # noqa: F401

‎setuptools/_itertools.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
__lazy_modules__ = {"more_itertools"}
2+
13
from more_itertools import consume # noqa: F401
24

35

0 commit comments

Comments
 (0)