Skip to content

Speed up setuptools imports on Python 3.15+ by adding __lazy_modules__ - #5257

Open
Avasam wants to merge 3 commits into
pypa:mainfrom
Avasam:Python-3.15-`__lazy_modules__`
Open

Avasam wants to merge 3 commits into
pypa:mainfrom
Avasam:Python-3.15-`__lazy_modules__`

Conversation

@Avasam

@Avasam Avasam commented Jul 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary of changes

Alternative dynamic mode: https://flake8-lazy.readthedocs.io/en/latest/cli/#dynamic-mode

Once pypa/distutils#414 is also merged, this will

Autofixed by running

import glob, os, subprocess, sys
skip = {'tests', '_distutils', '_vendor', '_validate_pyproject'}
files = [f for f in glob.glob('setuptools/**/*.py', recursive=True) if not skip & set(f.split(os.sep))]
subprocess.check_call([sys.executable, '-m', 'flake8_lazy', *files, '--apply=set', '--strict-typing'])

Note: Merging #5222 first should reduce import reification related errors found by test.

Pull Request Checklist

@mergify

mergify Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

@Avasam
Avasam force-pushed the Python-3.15-`__lazy_modules__` branch from 2cf37a2 to 356bcc8 Compare July 11, 2026 18:45
@Avasam Avasam changed the title Python 3.15 __lazy_modules__ (auto-applied w/ flake8-lazy --apply=set) Speed up setuptools imports on Python 3.15+ by adding __lazy_modules__ Jul 11, 2026
Comment thread pyproject.toml

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

@Avasam Avasam Jul 11, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread tox.ini Outdated
@Avasam
Avasam force-pushed the Python-3.15-`__lazy_modules__` branch 3 times, most recently from 41b2d76 to be82d65 Compare July 11, 2026 22:11
@Avasam
Avasam force-pushed the Python-3.15-`__lazy_modules__` branch from be82d65 to 63ad5a9 Compare August 3, 2026 22:53
@Avasam
Avasam force-pushed the Python-3.15-`__lazy_modules__` branch 3 times, most recently from 594bc78 to e7745f1 Compare September 10, 2026 19:16
@Avasam
Avasam force-pushed the Python-3.15-`__lazy_modules__` branch from e93a2de to 0903ea1 Compare October 22, 2026 17:36
@Avasam
Avasam force-pushed the Python-3.15-`__lazy_modules__` branch from 0903ea1 to c03bbe8 Compare October 22, 2026 17:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] SETUPTOOLS_USE_DISTUTILS=local makes any distutils import very slow [BUG] Importing setuptools is slow and takes nearly half a second

1 participant