Skip to content

Speed up distutils imports on Python 3.15+ by adding __lazy_modules__#414

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

Speed up distutils imports on Python 3.15+ by adding __lazy_modules__#414
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

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

Works towards:

The same changes would have to be done on setuptools side to close those issues. (pypa/setuptools#5257)

Autofixed by running

import glob, os, subprocess, sys;
files = [f for f in glob.glob('distutils/**/*.py', recursive=True) if 'tests' not in f.split(os.sep)];
subprocess.check_call([sys.executable, '-m', 'flake8_lazy', *files, '--apply=set'])

Comment thread .flake8
@@ -1,9 +0,0 @@
[flake8]

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.

Leftover unused flake8 file

Comment thread pyproject.toml
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__

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
# 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)]; \

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.

This could be massively simplified with recursive globing support: henryiii/flake8-lazy#92

@Avasam Avasam changed the title Python 3.15 __lazy_modules__ (auto-applied w/ flake8-lazy --apply=set) Speed up distutils imports on Python 3.15+ by adding __lazy_modules__ Jul 11, 2026
Avasam and others added 2 commits July 11, 2026 14:56
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>
@Avasam Avasam force-pushed the Python-3.15-`__lazy_modules__` branch from b2a0867 to 684b732 Compare July 11, 2026 18:58
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.

1 participant