Speed up distutils imports on Python 3.15+ by adding __lazy_modules__#414
Open
Avasam wants to merge 3 commits into
Open
Speed up distutils imports on Python 3.15+ by adding __lazy_modules__#414Avasam wants to merge 3 commits into
__lazy_modules__#414Avasam wants to merge 3 commits into
Conversation
Avasam
commented
Jul 11, 2026
| @@ -1,9 +0,0 @@ | |||
| [flake8] | |||
Contributor
Author
There was a problem hiding this comment.
Leftover unused flake8 file
Avasam
commented
Jul 11, 2026
| check = [ | ||
| "pytest-checkdocs >= 2.14", | ||
| "pytest-ruff >= 0.2.1; 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
| # tox doesn't shell-glob, so expand the file list cross-platform via Python | ||
| # and drop test dirs (lazy-import hygiene is irrelevant there). | ||
| python -c "import glob, os, subprocess, sys; \ | ||
| files = [f for f in glob.glob('distutils/**/*.py', recursive=True) if 'tests' not in f.split(os.sep)]; \ |
Contributor
Author
There was a problem hiding this comment.
This could be massively simplified with recursive globing support: henryiii/flake8-lazy#92
2 tasks
__lazy_modules__ (auto-applied w/ flake8-lazy --apply=set)__lazy_modules__
…set --strict-typing`)
flake8-lazy ships no pytest plugin, so invoke its CLI from the primary testenv. tox does not shell-glob, so expand the file list cross-platform via Python and drop test dirs where lazy-import hygiene is irrelevant. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
b2a0867 to
684b732
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.
Alternative dynamic mode: https://flake8-lazy.readthedocs.io/en/latest/cli/#dynamic-mode
Works towards:
distutilsimport very slow setuptools#3585setuptoolsis slow and takes nearly half a second setuptools#3441The same changes would have to be done on setuptools side to close those issues. (pypa/setuptools#5257)
Autofixed by running