Speed up setuptools imports on Python 3.15+ by adding __lazy_modules__#5257
Open
Avasam wants to merge 2 commits into
Open
Speed up setuptools imports on Python 3.15+ by adding __lazy_modules__#5257Avasam wants to merge 2 commits into
__lazy_modules__#5257Avasam wants to merge 2 commits into
Conversation
Contributor
|
Tick the box to add this pull request to the merge queue (same as
|
2cf37a2 to
356bcc8
Compare
__lazy_modules__ (auto-applied w/ flake8-lazy --apply=set)__lazy_modules__
Avasam
commented
Jul 11, 2026
|
|
||
| # 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__ |
Contributor
Author
There was a problem hiding this comment.
Avasam
commented
Jul 11, 2026
Comment on lines
+10
to
+17
| # flake8-lazy has no pytest plugin; run its CLI over the package sources. | ||
| # tox doesn't shell-glob, so expand the file list cross-platform via Python | ||
| # and drop test dirs (lazy-import hygiene is irrelevant there) plus the | ||
| # vendored/distutils trees (maintained upstream, not our lazy-import concern). | ||
| python -c "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])" |
Contributor
Author
There was a problem hiding this comment.
This could be massively simplified with recursive globing support: henryiii/flake8-lazy#92
356bcc8 to
3d3bbc0
Compare
3d3bbc0 to
a17d55e
Compare
41b2d76 to
be82d65
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
distutilsimport very slow #3585setuptoolsis slow and takes nearly half a second #3441Autofixed by running
Note: Merging #5222 first should reduce import reification related errors found by test.
Pull Request Checklist
newsfragments/.(See documentation for details)