From 7ad5cce54066f7ad20862f1cb379dceb7e440ce1 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Mon, 18 May 2026 20:10:51 -0700 Subject: [PATCH 1/7] chore: lazy imports Signed-off-by: Henry Schreiner --- .pre-commit-config.yaml | 8 +++++++ cibuildwheel/__main__.py | 24 +++++++++++++++++++ cibuildwheel/architecture.py | 2 ++ cibuildwheel/audit.py | 11 +++++++++ cibuildwheel/bashlex_eval.py | 2 ++ cibuildwheel/ci.py | 2 ++ cibuildwheel/environment.py | 2 ++ cibuildwheel/errors.py | 2 ++ cibuildwheel/extra.py | 2 ++ cibuildwheel/frontend.py | 2 ++ cibuildwheel/logger.py | 12 ++++++++++ cibuildwheel/oci_container.py | 18 ++++++++++++++ cibuildwheel/options.py | 24 +++++++++++++++++++ cibuildwheel/platforms/ios.py | 23 ++++++++++++++++++ cibuildwheel/platforms/linux.py | 17 +++++++++++++ cibuildwheel/platforms/macos.py | 22 +++++++++++++++++ cibuildwheel/platforms/pyodide.py | 21 ++++++++++++++++ cibuildwheel/platforms/windows.py | 21 ++++++++++++++++ cibuildwheel/projectfiles.py | 2 ++ cibuildwheel/resources/android/_cross_venv.py | 2 ++ cibuildwheel/resources/android/rust_shim.py | 2 ++ cibuildwheel/resources/install_certifi.py | 2 ++ .../resources/ios-support/_cross_venv.py | 2 ++ .../arm64-iphoneos/sitecustomize.py | 3 +++ .../arm64-iphonesimulator/sitecustomize.py | 3 +++ .../resources/ios-support/make_cross_venv.py | 2 ++ .../x86_64-iphonesimulator/sitecustomize.py | 3 +++ .../resources/testing_temp_dir_file.py | 2 ++ cibuildwheel/schema.py | 2 ++ cibuildwheel/selector.py | 2 ++ cibuildwheel/util/cmd.py | 2 ++ cibuildwheel/util/file.py | 14 +++++++++++ cibuildwheel/util/helpers.py | 2 ++ cibuildwheel/util/packaging.py | 8 +++++++ cibuildwheel/util/python_build_standalone.py | 9 +++++++ cibuildwheel/util/resources.py | 2 ++ cibuildwheel/venv.py | 15 ++++++++++++ 37 files changed, 294 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 164bfac10..b69655003 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -77,6 +77,14 @@ repos: files: '^(README\.md|docs/changelog\.md|docs/options\.md|bin/readme.*)$' additional_dependencies: [cogapp>=3.5] +- repo: https://github.com/PyCQA/flake8 + rev: c48217e1fc006c2dddd14df54e83b67da15de5cd # frozen: 7.3.0 + hooks: + - id: flake8 + args: ["--select=LZY"] + additional_dependencies: [flake8-lazy==0.7.0] + files: '^cibuildwheel' + - repo: https://github.com/codespell-project/codespell rev: 2ccb47ff45ad361a21071a7eedda4c37e6ae8c5a # frozen: v2.4.2 hooks: diff --git a/cibuildwheel/__main__.py b/cibuildwheel/__main__.py index 2a3287efb..16f4319e3 100644 --- a/cibuildwheel/__main__.py +++ b/cibuildwheel/__main__.py @@ -1,5 +1,29 @@ from __future__ import annotations +__lazy_modules__ = { + "argparse", + "cibuildwheel._compat", + "cibuildwheel._compat.tarfile", + "cibuildwheel.architecture", + "cibuildwheel.ci", + "cibuildwheel.logger", + "cibuildwheel.options", + "cibuildwheel.platforms", + "cibuildwheel.selector", + "cibuildwheel.typing", + "cibuildwheel.util", + "cibuildwheel.util.file", + "cibuildwheel.util.helpers", + "cibuildwheel.util.resources", + "contextlib", + "functools", + "pathlib", + "shutil", + "tempfile", + "textwrap", + "traceback", +} + import argparse import contextlib import dataclasses diff --git a/cibuildwheel/architecture.py b/cibuildwheel/architecture.py index 41d5ad863..4fe437410 100644 --- a/cibuildwheel/architecture.py +++ b/cibuildwheel/architecture.py @@ -1,5 +1,7 @@ from __future__ import annotations +__lazy_modules__ = {"platform", "re", "shutil", "subprocess"} + import platform as platform_module import re import shutil diff --git a/cibuildwheel/audit.py b/cibuildwheel/audit.py index 10f4c7cf1..dadaef04c 100644 --- a/cibuildwheel/audit.py +++ b/cibuildwheel/audit.py @@ -1,5 +1,16 @@ from __future__ import annotations +__lazy_modules__ = { + "cibuildwheel.logger", + "cibuildwheel.util", + "cibuildwheel.util.cmd", + "cibuildwheel.util.helpers", + "cibuildwheel.util.packaging", + "cibuildwheel.venv", + "pathlib", + "subprocess", +} + import subprocess import sys from pathlib import Path diff --git a/cibuildwheel/bashlex_eval.py b/cibuildwheel/bashlex_eval.py index 85cdcb1ad..5a327a662 100644 --- a/cibuildwheel/bashlex_eval.py +++ b/cibuildwheel/bashlex_eval.py @@ -1,5 +1,7 @@ from __future__ import annotations +__lazy_modules__ = {"bashlex", "subprocess"} + import dataclasses import subprocess diff --git a/cibuildwheel/ci.py b/cibuildwheel/ci.py index 648f29c2d..09619f127 100644 --- a/cibuildwheel/ci.py +++ b/cibuildwheel/ci.py @@ -1,3 +1,5 @@ +__lazy_modules__ = {"cibuildwheel.util", "cibuildwheel.util.helpers"} + import os import re from enum import Enum diff --git a/cibuildwheel/environment.py b/cibuildwheel/environment.py index bc5d13bf0..a38ad22a9 100644 --- a/cibuildwheel/environment.py +++ b/cibuildwheel/environment.py @@ -1,5 +1,7 @@ from __future__ import annotations +__lazy_modules__ = {"bashlex", "bashlex.errors"} + import dataclasses from typing import Protocol diff --git a/cibuildwheel/errors.py b/cibuildwheel/errors.py index dee96d97e..b3fd2a6ed 100644 --- a/cibuildwheel/errors.py +++ b/cibuildwheel/errors.py @@ -4,6 +4,8 @@ semantically clear and unique. """ +__lazy_modules__ = {"textwrap"} + import textwrap diff --git a/cibuildwheel/extra.py b/cibuildwheel/extra.py index 30f280cb7..9b1abcb1c 100644 --- a/cibuildwheel/extra.py +++ b/cibuildwheel/extra.py @@ -4,6 +4,8 @@ from __future__ import annotations +__lazy_modules__ = {"io", "json", "urllib", "urllib.error", "urllib.request"} + import json import time import typing diff --git a/cibuildwheel/frontend.py b/cibuildwheel/frontend.py index 14a8ede88..41c53b341 100644 --- a/cibuildwheel/frontend.py +++ b/cibuildwheel/frontend.py @@ -1,5 +1,7 @@ from __future__ import annotations +__lazy_modules__ = {"cibuildwheel.util", "cibuildwheel.util.helpers", "shlex"} + import dataclasses import shlex import typing diff --git a/cibuildwheel/logger.py b/cibuildwheel/logger.py index da33370e8..69314fac9 100644 --- a/cibuildwheel/logger.py +++ b/cibuildwheel/logger.py @@ -1,5 +1,17 @@ from __future__ import annotations +__lazy_modules__ = { + "cibuildwheel.ci", + "contextlib", + "functools", + "hashlib", + "humanize", + "io", + "pathlib", + "re", + "textwrap", +} + import codecs import contextlib import dataclasses diff --git a/cibuildwheel/oci_container.py b/cibuildwheel/oci_container.py index db9e1f039..49e14a93c 100644 --- a/cibuildwheel/oci_container.py +++ b/cibuildwheel/oci_container.py @@ -1,5 +1,23 @@ from __future__ import annotations +__lazy_modules__ = { + "cibuildwheel.ci", + "cibuildwheel.errors", + "cibuildwheel.logger", + "cibuildwheel.util", + "cibuildwheel.util.cmd", + "cibuildwheel.util.helpers", + "contextlib", + "io", + "json", + "platform", + "shlex", + "shutil", + "subprocess", + "textwrap", + "uuid", +} + import contextlib import dataclasses import io diff --git a/cibuildwheel/options.py b/cibuildwheel/options.py index ed39bf35e..2d3e32a33 100644 --- a/cibuildwheel/options.py +++ b/cibuildwheel/options.py @@ -1,5 +1,29 @@ from __future__ import annotations +__lazy_modules__ = { + "cibuildwheel.architecture", + "cibuildwheel.environment", + "cibuildwheel.frontend", + "cibuildwheel.logger", + "cibuildwheel.oci_container", + "cibuildwheel.projectfiles", + "cibuildwheel.selector", + "cibuildwheel.typing", + "cibuildwheel.util", + "cibuildwheel.util.helpers", + "cibuildwheel.util.packaging", + "collections", + "configparser", + "contextlib", + "difflib", + "packaging", + "packaging.specifiers", + "pathlib", + "shlex", + "textwrap", + "tomllib", +} + import collections import configparser import contextlib diff --git a/cibuildwheel/platforms/ios.py b/cibuildwheel/platforms/ios.py index 751f3616e..bf896d8f2 100644 --- a/cibuildwheel/platforms/ios.py +++ b/cibuildwheel/platforms/ios.py @@ -1,5 +1,28 @@ from __future__ import annotations +__lazy_modules__ = { + "cibuildwheel.audit", + "cibuildwheel.frontend", + "cibuildwheel.logger", + "cibuildwheel.platforms.macos", + "cibuildwheel.util", + "cibuildwheel.util.cmd", + "cibuildwheel.util.file", + "cibuildwheel.util.helpers", + "cibuildwheel.util.packaging", + "cibuildwheel.venv", + "filelock", + "packaging", + "packaging.version", + "pathlib", + "platform", + "shlex", + "shutil", + "subprocess", + "textwrap", + "typing", +} + import dataclasses import os import platform diff --git a/cibuildwheel/platforms/linux.py b/cibuildwheel/platforms/linux.py index f97f6a6a1..32fd841fb 100644 --- a/cibuildwheel/platforms/linux.py +++ b/cibuildwheel/platforms/linux.py @@ -1,5 +1,22 @@ from __future__ import annotations +__lazy_modules__ = { + "cibuildwheel.audit", + "cibuildwheel.frontend", + "cibuildwheel.logger", + "cibuildwheel.util", + "cibuildwheel.util.file", + "cibuildwheel.util.helpers", + "cibuildwheel.util.packaging", + "collections", + "contextlib", + "pathlib", + "shutil", + "subprocess", + "textwrap", + "typing", +} + import contextlib import dataclasses import shutil diff --git a/cibuildwheel/platforms/macos.py b/cibuildwheel/platforms/macos.py index c2aa23df2..00f347151 100644 --- a/cibuildwheel/platforms/macos.py +++ b/cibuildwheel/platforms/macos.py @@ -1,5 +1,27 @@ from __future__ import annotations +__lazy_modules__ = { + "cibuildwheel.audit", + "cibuildwheel.ci", + "cibuildwheel.frontend", + "cibuildwheel.logger", + "cibuildwheel.util", + "cibuildwheel.util.cmd", + "cibuildwheel.util.file", + "cibuildwheel.util.helpers", + "cibuildwheel.util.packaging", + "cibuildwheel.venv", + "filelock", + "inspect", + "packaging", + "packaging.version", + "pathlib", + "platform", + "re", + "shutil", + "subprocess", +} + import dataclasses import functools import inspect diff --git a/cibuildwheel/platforms/pyodide.py b/cibuildwheel/platforms/pyodide.py index b4f7cd1b7..6afe0a264 100644 --- a/cibuildwheel/platforms/pyodide.py +++ b/cibuildwheel/platforms/pyodide.py @@ -1,5 +1,26 @@ from __future__ import annotations +__lazy_modules__ = { + "cibuildwheel.architecture", + "cibuildwheel.audit", + "cibuildwheel.frontend", + "cibuildwheel.logger", + "cibuildwheel.util", + "cibuildwheel.util.cmd", + "cibuildwheel.util.file", + "cibuildwheel.util.helpers", + "cibuildwheel.util.packaging", + "cibuildwheel.util.python_build_standalone", + "cibuildwheel.venv", + "filelock", + "json", + "pathlib", + "shutil", + "subprocess", + "tempfile", + "tomllib", +} + import dataclasses import functools import json diff --git a/cibuildwheel/platforms/windows.py b/cibuildwheel/platforms/windows.py index dc0a2977b..8fac9de02 100644 --- a/cibuildwheel/platforms/windows.py +++ b/cibuildwheel/platforms/windows.py @@ -1,5 +1,26 @@ from __future__ import annotations +__lazy_modules__ = { + "cibuildwheel.architecture", + "cibuildwheel.audit", + "cibuildwheel.frontend", + "cibuildwheel.logger", + "cibuildwheel.util", + "cibuildwheel.util.cmd", + "cibuildwheel.util.file", + "cibuildwheel.util.helpers", + "cibuildwheel.util.packaging", + "cibuildwheel.venv", + "filelock", + "json", + "pathlib", + "platform", + "shutil", + "subprocess", + "textwrap", + "typing", +} + import dataclasses import os import platform as platform_module diff --git a/cibuildwheel/projectfiles.py b/cibuildwheel/projectfiles.py index 41af8b1f7..ecc6a2130 100644 --- a/cibuildwheel/projectfiles.py +++ b/cibuildwheel/projectfiles.py @@ -1,5 +1,7 @@ from __future__ import annotations +__lazy_modules__ = {"configparser", "contextlib", "dependency_groups"} + import ast import configparser import contextlib diff --git a/cibuildwheel/resources/android/_cross_venv.py b/cibuildwheel/resources/android/_cross_venv.py index 0c50dcce2..145df79d7 100644 --- a/cibuildwheel/resources/android/_cross_venv.py +++ b/cibuildwheel/resources/android/_cross_venv.py @@ -1,6 +1,8 @@ # This module is copied into the site-packages directory of an Android build environment, and # activated via a .pth file when we want the environment to simulate Android. +__lazy_modules__ = {"pathlib", "platform", "re", "sysconfig", "typing"} + import os import platform import re diff --git a/cibuildwheel/resources/android/rust_shim.py b/cibuildwheel/resources/android/rust_shim.py index d88087eaa..3820b9f1e 100755 --- a/cibuildwheel/resources/android/rust_shim.py +++ b/cibuildwheel/resources/android/rust_shim.py @@ -1,5 +1,7 @@ #!/usr/bin/env python3 +__lazy_modules__ = {"pathlib", "shutil", "subprocess"} + import os import shutil import subprocess diff --git a/cibuildwheel/resources/install_certifi.py b/cibuildwheel/resources/install_certifi.py index 47f528cbc..3bb3fe04a 100644 --- a/cibuildwheel/resources/install_certifi.py +++ b/cibuildwheel/resources/install_certifi.py @@ -6,6 +6,8 @@ # for the ssl module. Uses the certificates provided by the certifi package: # https://pypi.org/project/certifi/ +__lazy_modules__ = {"contextlib", "os", "os.path", "ssl", "subprocess"} + import contextlib import os import os.path diff --git a/cibuildwheel/resources/ios-support/_cross_venv.py b/cibuildwheel/resources/ios-support/_cross_venv.py index 1a1842b4b..5519c60c9 100644 --- a/cibuildwheel/resources/ios-support/_cross_venv.py +++ b/cibuildwheel/resources/ios-support/_cross_venv.py @@ -1,3 +1,5 @@ +__lazy_modules__ = {"shutil", "sysconfig"} + import shutil import sys import sysconfig diff --git a/cibuildwheel/resources/ios-support/arm64-iphoneos/sitecustomize.py b/cibuildwheel/resources/ios-support/arm64-iphoneos/sitecustomize.py index 6f02a9837..5cf884cad 100644 --- a/cibuildwheel/resources/ios-support/arm64-iphoneos/sitecustomize.py +++ b/cibuildwheel/resources/ios-support/arm64-iphoneos/sitecustomize.py @@ -2,6 +2,9 @@ # cross-platform. If the folder containing this file is on your PYTHONPATH when # you invoke python, the interpreter will behave as if it were running on # arm64 iphoneos. + +__lazy_modules__ = {"_cross_arm64_iphoneos", "_cross_venv", "sitecustomize"} + import sys import os diff --git a/cibuildwheel/resources/ios-support/arm64-iphonesimulator/sitecustomize.py b/cibuildwheel/resources/ios-support/arm64-iphonesimulator/sitecustomize.py index b76ad42ce..cc3ff8731 100644 --- a/cibuildwheel/resources/ios-support/arm64-iphonesimulator/sitecustomize.py +++ b/cibuildwheel/resources/ios-support/arm64-iphonesimulator/sitecustomize.py @@ -2,6 +2,9 @@ # cross-platform. If the folder containing this file is on your PYTHONPATH when # you invoke python, the interpreter will behave as if it were running on # arm64 iphonesimulator. + +__lazy_modules__ = {"_cross_arm64_iphonesimulator", "_cross_venv", "sitecustomize"} + import sys import os diff --git a/cibuildwheel/resources/ios-support/make_cross_venv.py b/cibuildwheel/resources/ios-support/make_cross_venv.py index 2226ffebd..11333330e 100644 --- a/cibuildwheel/resources/ios-support/make_cross_venv.py +++ b/cibuildwheel/resources/ios-support/make_cross_venv.py @@ -1,5 +1,7 @@ from __future__ import annotations +__lazy_modules__ = {"importlib", "json", "pprint", "shutil", "typing"} + import json import pprint import shutil diff --git a/cibuildwheel/resources/ios-support/x86_64-iphonesimulator/sitecustomize.py b/cibuildwheel/resources/ios-support/x86_64-iphonesimulator/sitecustomize.py index 7e6b8b2d9..d2f50c649 100644 --- a/cibuildwheel/resources/ios-support/x86_64-iphonesimulator/sitecustomize.py +++ b/cibuildwheel/resources/ios-support/x86_64-iphonesimulator/sitecustomize.py @@ -2,6 +2,9 @@ # cross-platform. If the folder containing this file is on your PYTHONPATH when # you invoke python, the interpreter will behave as if it were running on # x86_64 iphonesimulator. + +__lazy_modules__ = {"_cross_venv", "_cross_x86_64_iphonesimulator", "sitecustomize"} + import sys import os diff --git a/cibuildwheel/resources/testing_temp_dir_file.py b/cibuildwheel/resources/testing_temp_dir_file.py index cc3e15a2b..dc3c30f74 100644 --- a/cibuildwheel/resources/testing_temp_dir_file.py +++ b/cibuildwheel/resources/testing_temp_dir_file.py @@ -1,6 +1,8 @@ # this file is copied to the testing cwd, to raise the below error message if # pytest/unittest is run from there. +__lazy_modules__ = {"typing"} + import sys import unittest from typing import NoReturn diff --git a/cibuildwheel/schema.py b/cibuildwheel/schema.py index dde0efcc1..b48793fd8 100644 --- a/cibuildwheel/schema.py +++ b/cibuildwheel/schema.py @@ -1,5 +1,7 @@ from __future__ import annotations +__lazy_modules__ = {"cibuildwheel.util", "json"} + import json from cibuildwheel.util import resources diff --git a/cibuildwheel/selector.py b/cibuildwheel/selector.py index 579a18f53..9314fa1e1 100644 --- a/cibuildwheel/selector.py +++ b/cibuildwheel/selector.py @@ -1,5 +1,7 @@ from __future__ import annotations +__lazy_modules__ = {"bracex", "fnmatch", "itertools", "packaging", "packaging.version"} + import dataclasses import itertools from enum import StrEnum diff --git a/cibuildwheel/util/cmd.py b/cibuildwheel/util/cmd.py index ed864c275..1795eb8e2 100644 --- a/cibuildwheel/util/cmd.py +++ b/cibuildwheel/util/cmd.py @@ -1,5 +1,7 @@ from __future__ import annotations +__lazy_modules__ = {"cibuildwheel.errors", "shlex", "shutil", "subprocess"} + import os import shlex import shutil diff --git a/cibuildwheel/util/file.py b/cibuildwheel/util/file.py index b92727ac6..32a8601f6 100644 --- a/cibuildwheel/util/file.py +++ b/cibuildwheel/util/file.py @@ -1,6 +1,20 @@ from __future__ import annotations import hashlib + +__lazy_modules__ = { + "certifi", + "cibuildwheel.errors", + "shutil", + "ssl", + "tarfile", + "typing", + "urllib", + "urllib.request", + "zipfile", +} + + import os import shutil import ssl diff --git a/cibuildwheel/util/helpers.py b/cibuildwheel/util/helpers.py index a8a4df786..d6ed17971 100644 --- a/cibuildwheel/util/helpers.py +++ b/cibuildwheel/util/helpers.py @@ -1,5 +1,7 @@ from __future__ import annotations +__lazy_modules__ = {"collections", "itertools", "re", "shlex", "textwrap"} + import dataclasses import itertools import re diff --git a/cibuildwheel/util/packaging.py b/cibuildwheel/util/packaging.py index d8bb57c66..58d2a2818 100644 --- a/cibuildwheel/util/packaging.py +++ b/cibuildwheel/util/packaging.py @@ -1,5 +1,13 @@ from __future__ import annotations +__lazy_modules__ = { + "cibuildwheel.util.cmd", + "cibuildwheel.util.helpers", + "packaging", + "packaging.utils", + "shlex", +} + import shlex from dataclasses import dataclass, field from pathlib import Path, PurePath diff --git a/cibuildwheel/util/python_build_standalone.py b/cibuildwheel/util/python_build_standalone.py index 186569bbf..540733611 100644 --- a/cibuildwheel/util/python_build_standalone.py +++ b/cibuildwheel/util/python_build_standalone.py @@ -1,5 +1,14 @@ from __future__ import annotations +__lazy_modules__ = { + "cibuildwheel.util.file", + "cibuildwheel.util.resources", + "filelock", + "fnmatch", + "json", + "platform", +} + import fnmatch import functools import hashlib diff --git a/cibuildwheel/util/resources.py b/cibuildwheel/util/resources.py index dd3d151f0..3bbef7537 100644 --- a/cibuildwheel/util/resources.py +++ b/cibuildwheel/util/resources.py @@ -1,5 +1,7 @@ from __future__ import annotations +__lazy_modules__ = {"tomllib"} + import functools import tomllib from pathlib import Path diff --git a/cibuildwheel/venv.py b/cibuildwheel/venv.py index 174b2a1bb..2867edd7a 100644 --- a/cibuildwheel/venv.py +++ b/cibuildwheel/venv.py @@ -1,5 +1,20 @@ from __future__ import annotations +__lazy_modules__ = { + "cibuildwheel.util", + "cibuildwheel.util.cmd", + "cibuildwheel.util.file", + "contextlib", + "filelock", + "packaging", + "packaging.markers", + "packaging.requirements", + "packaging.version", + "pathlib", + "shutil", + "tomllib", +} + import contextlib import functools import os From d5fe3a300d804e6c77830222d2c8ba71c68b9cf2 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Thu, 28 May 2026 22:29:14 -0400 Subject: [PATCH 2/7] chore: bump flake8-lazy, rerun Signed-off-by: Henry Schreiner --- .pre-commit-config.yaml | 2 +- cibuildwheel/resources/install_certifi.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b69655003..2eceac613 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -82,7 +82,7 @@ repos: hooks: - id: flake8 args: ["--select=LZY"] - additional_dependencies: [flake8-lazy==0.7.0] + additional_dependencies: [flake8-lazy==0.7.1] files: '^cibuildwheel' - repo: https://github.com/codespell-project/codespell diff --git a/cibuildwheel/resources/install_certifi.py b/cibuildwheel/resources/install_certifi.py index 3bb3fe04a..1a7ade9a8 100644 --- a/cibuildwheel/resources/install_certifi.py +++ b/cibuildwheel/resources/install_certifi.py @@ -6,7 +6,7 @@ # for the ssl module. Uses the certificates provided by the certifi package: # https://pypi.org/project/certifi/ -__lazy_modules__ = {"contextlib", "os", "os.path", "ssl", "subprocess"} +__lazy_modules__ = {"contextlib", "ssl", "subprocess"} import contextlib import os From 4e17c388d1f0b100cf7dff7dc961b6b4f538dac5 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Fri, 29 May 2026 00:51:37 -0400 Subject: [PATCH 3/7] chore: include android Signed-off-by: Henry Schreiner --- .pre-commit-config.yaml | 1 + cibuildwheel/platforms/android.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2eceac613..0a97914d8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -84,6 +84,7 @@ repos: args: ["--select=LZY"] additional_dependencies: [flake8-lazy==0.7.1] files: '^cibuildwheel' + exclude: "^cibuildwheel/resources/android" - repo: https://github.com/codespell-project/codespell rev: 2ccb47ff45ad361a21071a7eedda4c37e6ae8c5a # frozen: v2.4.2 diff --git a/cibuildwheel/platforms/android.py b/cibuildwheel/platforms/android.py index 52773e058..4a3e11fef 100644 --- a/cibuildwheel/platforms/android.py +++ b/cibuildwheel/platforms/android.py @@ -1,5 +1,33 @@ from __future__ import annotations +__lazy_modules__ = { + "build", + "build.env", + "cibuildwheel.architecture", + "cibuildwheel.audit", + "cibuildwheel.frontend", + "cibuildwheel.logger", + "cibuildwheel.util.cmd", + "cibuildwheel.util.file", + "cibuildwheel.util.helpers", + "cibuildwheel.util.packaging", + "cibuildwheel.util.python_build_standalone", + "cibuildwheel.venv", + "filelock", + "packaging", + "packaging.utils", + "pathlib", + "platform", + "pprint", + "re", + "runpy", + "shlex", + "shutil", + "subprocess", + "textwrap", + "typing", +} + import os import platform import re From c5faa2c92a1f545496c137d75711a6b7d9d8b973 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Fri, 29 May 2026 15:06:32 -0400 Subject: [PATCH 4/7] fix: after rebase Assisted-by: ClaudeCode:claude-sonnet-4.6 Signed-off-by: Henry Schreiner --- cibuildwheel/util/file.py | 4 ++-- cibuildwheel/util/python_build_standalone.py | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/cibuildwheel/util/file.py b/cibuildwheel/util/file.py index 32a8601f6..111b7d909 100644 --- a/cibuildwheel/util/file.py +++ b/cibuildwheel/util/file.py @@ -1,10 +1,9 @@ from __future__ import annotations -import hashlib - __lazy_modules__ = { "certifi", "cibuildwheel.errors", + "hashlib", "shutil", "ssl", "tarfile", @@ -15,6 +14,7 @@ } +import hashlib import os import shutil import ssl diff --git a/cibuildwheel/util/python_build_standalone.py b/cibuildwheel/util/python_build_standalone.py index 540733611..8b811056a 100644 --- a/cibuildwheel/util/python_build_standalone.py +++ b/cibuildwheel/util/python_build_standalone.py @@ -5,6 +5,7 @@ "cibuildwheel.util.resources", "filelock", "fnmatch", + "hashlib", "json", "platform", } From 1f66980cb63f3e2c5653a74f99e58d71e6c84bad Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Sun, 31 May 2026 18:25:14 -0400 Subject: [PATCH 5/7] chore: autofix __lazy_modules__ Signed-off-by: Henry Schreiner --- .pre-commit-config.yaml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0a97914d8..6310b8c52 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -77,12 +77,11 @@ repos: files: '^(README\.md|docs/changelog\.md|docs/options\.md|bin/readme.*)$' additional_dependencies: [cogapp>=3.5] -- repo: https://github.com/PyCQA/flake8 - rev: c48217e1fc006c2dddd14df54e83b67da15de5cd # frozen: 7.3.0 +- repo: https://github.com/henryiii/flake8-lazy + rev: 6898c4b9b8817d021002b2beed6986621ad589ad # frozen: v0.8.0 hooks: - - id: flake8 - args: ["--select=LZY"] - additional_dependencies: [flake8-lazy==0.7.1] + - id: flake8-lazy + args: ["--apply=set"] files: '^cibuildwheel' exclude: "^cibuildwheel/resources/android" From 6d2e5024beac9cd5706255c3f5b5ee3101539f46 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Mon, 1 Jun 2026 09:54:25 -0400 Subject: [PATCH 6/7] chore: avoid touching resources Signed-off-by: Henry Schreiner --- .pre-commit-config.yaml | 2 +- cibuildwheel/resources/android/_cross_venv.py | 2 -- cibuildwheel/resources/android/rust_shim.py | 2 -- cibuildwheel/resources/install_certifi.py | 2 -- cibuildwheel/resources/ios-support/_cross_venv.py | 2 -- .../resources/ios-support/arm64-iphoneos/sitecustomize.py | 3 --- .../ios-support/arm64-iphonesimulator/sitecustomize.py | 3 --- cibuildwheel/resources/ios-support/make_cross_venv.py | 2 -- .../ios-support/x86_64-iphonesimulator/sitecustomize.py | 3 --- cibuildwheel/resources/testing_temp_dir_file.py | 2 -- 10 files changed, 1 insertion(+), 22 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6310b8c52..83fed66d0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -83,7 +83,7 @@ repos: - id: flake8-lazy args: ["--apply=set"] files: '^cibuildwheel' - exclude: "^cibuildwheel/resources/android" + exclude: "^cibuildwheel/resources/" - repo: https://github.com/codespell-project/codespell rev: 2ccb47ff45ad361a21071a7eedda4c37e6ae8c5a # frozen: v2.4.2 diff --git a/cibuildwheel/resources/android/_cross_venv.py b/cibuildwheel/resources/android/_cross_venv.py index 145df79d7..0c50dcce2 100644 --- a/cibuildwheel/resources/android/_cross_venv.py +++ b/cibuildwheel/resources/android/_cross_venv.py @@ -1,8 +1,6 @@ # This module is copied into the site-packages directory of an Android build environment, and # activated via a .pth file when we want the environment to simulate Android. -__lazy_modules__ = {"pathlib", "platform", "re", "sysconfig", "typing"} - import os import platform import re diff --git a/cibuildwheel/resources/android/rust_shim.py b/cibuildwheel/resources/android/rust_shim.py index 3820b9f1e..d88087eaa 100755 --- a/cibuildwheel/resources/android/rust_shim.py +++ b/cibuildwheel/resources/android/rust_shim.py @@ -1,7 +1,5 @@ #!/usr/bin/env python3 -__lazy_modules__ = {"pathlib", "shutil", "subprocess"} - import os import shutil import subprocess diff --git a/cibuildwheel/resources/install_certifi.py b/cibuildwheel/resources/install_certifi.py index 1a7ade9a8..47f528cbc 100644 --- a/cibuildwheel/resources/install_certifi.py +++ b/cibuildwheel/resources/install_certifi.py @@ -6,8 +6,6 @@ # for the ssl module. Uses the certificates provided by the certifi package: # https://pypi.org/project/certifi/ -__lazy_modules__ = {"contextlib", "ssl", "subprocess"} - import contextlib import os import os.path diff --git a/cibuildwheel/resources/ios-support/_cross_venv.py b/cibuildwheel/resources/ios-support/_cross_venv.py index 5519c60c9..1a1842b4b 100644 --- a/cibuildwheel/resources/ios-support/_cross_venv.py +++ b/cibuildwheel/resources/ios-support/_cross_venv.py @@ -1,5 +1,3 @@ -__lazy_modules__ = {"shutil", "sysconfig"} - import shutil import sys import sysconfig diff --git a/cibuildwheel/resources/ios-support/arm64-iphoneos/sitecustomize.py b/cibuildwheel/resources/ios-support/arm64-iphoneos/sitecustomize.py index 5cf884cad..6f02a9837 100644 --- a/cibuildwheel/resources/ios-support/arm64-iphoneos/sitecustomize.py +++ b/cibuildwheel/resources/ios-support/arm64-iphoneos/sitecustomize.py @@ -2,9 +2,6 @@ # cross-platform. If the folder containing this file is on your PYTHONPATH when # you invoke python, the interpreter will behave as if it were running on # arm64 iphoneos. - -__lazy_modules__ = {"_cross_arm64_iphoneos", "_cross_venv", "sitecustomize"} - import sys import os diff --git a/cibuildwheel/resources/ios-support/arm64-iphonesimulator/sitecustomize.py b/cibuildwheel/resources/ios-support/arm64-iphonesimulator/sitecustomize.py index cc3ff8731..b76ad42ce 100644 --- a/cibuildwheel/resources/ios-support/arm64-iphonesimulator/sitecustomize.py +++ b/cibuildwheel/resources/ios-support/arm64-iphonesimulator/sitecustomize.py @@ -2,9 +2,6 @@ # cross-platform. If the folder containing this file is on your PYTHONPATH when # you invoke python, the interpreter will behave as if it were running on # arm64 iphonesimulator. - -__lazy_modules__ = {"_cross_arm64_iphonesimulator", "_cross_venv", "sitecustomize"} - import sys import os diff --git a/cibuildwheel/resources/ios-support/make_cross_venv.py b/cibuildwheel/resources/ios-support/make_cross_venv.py index 11333330e..2226ffebd 100644 --- a/cibuildwheel/resources/ios-support/make_cross_venv.py +++ b/cibuildwheel/resources/ios-support/make_cross_venv.py @@ -1,7 +1,5 @@ from __future__ import annotations -__lazy_modules__ = {"importlib", "json", "pprint", "shutil", "typing"} - import json import pprint import shutil diff --git a/cibuildwheel/resources/ios-support/x86_64-iphonesimulator/sitecustomize.py b/cibuildwheel/resources/ios-support/x86_64-iphonesimulator/sitecustomize.py index d2f50c649..7e6b8b2d9 100644 --- a/cibuildwheel/resources/ios-support/x86_64-iphonesimulator/sitecustomize.py +++ b/cibuildwheel/resources/ios-support/x86_64-iphonesimulator/sitecustomize.py @@ -2,9 +2,6 @@ # cross-platform. If the folder containing this file is on your PYTHONPATH when # you invoke python, the interpreter will behave as if it were running on # x86_64 iphonesimulator. - -__lazy_modules__ = {"_cross_venv", "_cross_x86_64_iphonesimulator", "sitecustomize"} - import sys import os diff --git a/cibuildwheel/resources/testing_temp_dir_file.py b/cibuildwheel/resources/testing_temp_dir_file.py index dc3c30f74..cc3e15a2b 100644 --- a/cibuildwheel/resources/testing_temp_dir_file.py +++ b/cibuildwheel/resources/testing_temp_dir_file.py @@ -1,8 +1,6 @@ # this file is copied to the testing cwd, to raise the below error message if # pytest/unittest is run from there. -__lazy_modules__ = {"typing"} - import sys import unittest from typing import NoReturn From cd79b8618b54705f9ee88dad4f5623037eeea403 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Tue, 9 Jun 2026 21:41:46 -0400 Subject: [PATCH 7/7] chore: bump flake8-lazy to v0.8.2, rerun Assisted-by: ClaudeCode:claude-sonnet-4-6 --- .pre-commit-config.yaml | 2 +- cibuildwheel/__main__.py | 1 + cibuildwheel/platforms/windows.py | 1 - cibuildwheel/util/python_build_standalone.py | 1 + 4 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 83fed66d0..b3198cb36 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -78,7 +78,7 @@ repos: additional_dependencies: [cogapp>=3.5] - repo: https://github.com/henryiii/flake8-lazy - rev: 6898c4b9b8817d021002b2beed6986621ad589ad # frozen: v0.8.0 + rev: 65b94e97b1091634368592d98072160842265fe4 # frozen: v0.8.2 hooks: - id: flake8-lazy args: ["--apply=set"] diff --git a/cibuildwheel/__main__.py b/cibuildwheel/__main__.py index 16f4319e3..c5d5d7723 100644 --- a/cibuildwheel/__main__.py +++ b/cibuildwheel/__main__.py @@ -17,6 +17,7 @@ "cibuildwheel.util.resources", "contextlib", "functools", + "io", "pathlib", "shutil", "tempfile", diff --git a/cibuildwheel/platforms/windows.py b/cibuildwheel/platforms/windows.py index 8fac9de02..545847277 100644 --- a/cibuildwheel/platforms/windows.py +++ b/cibuildwheel/platforms/windows.py @@ -12,7 +12,6 @@ "cibuildwheel.util.packaging", "cibuildwheel.venv", "filelock", - "json", "pathlib", "platform", "shutil", diff --git a/cibuildwheel/util/python_build_standalone.py b/cibuildwheel/util/python_build_standalone.py index 8b811056a..2e8c7fb82 100644 --- a/cibuildwheel/util/python_build_standalone.py +++ b/cibuildwheel/util/python_build_standalone.py @@ -8,6 +8,7 @@ "hashlib", "json", "platform", + "subprocess", } import fnmatch