diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 164bfac10..b3198cb36 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/henryiii/flake8-lazy + rev: 65b94e97b1091634368592d98072160842265fe4 # frozen: v0.8.2 + hooks: + - id: flake8-lazy + args: ["--apply=set"] + files: '^cibuildwheel' + exclude: "^cibuildwheel/resources/" + - 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..c5d5d7723 100644 --- a/cibuildwheel/__main__.py +++ b/cibuildwheel/__main__.py @@ -1,5 +1,30 @@ 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", + "io", + "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/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 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..545847277 100644 --- a/cibuildwheel/platforms/windows.py +++ b/cibuildwheel/platforms/windows.py @@ -1,5 +1,25 @@ 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", + "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/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..111b7d909 100644 --- a/cibuildwheel/util/file.py +++ b/cibuildwheel/util/file.py @@ -1,5 +1,19 @@ from __future__ import annotations +__lazy_modules__ = { + "certifi", + "cibuildwheel.errors", + "hashlib", + "shutil", + "ssl", + "tarfile", + "typing", + "urllib", + "urllib.request", + "zipfile", +} + + import hashlib import os import shutil 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..2e8c7fb82 100644 --- a/cibuildwheel/util/python_build_standalone.py +++ b/cibuildwheel/util/python_build_standalone.py @@ -1,5 +1,16 @@ from __future__ import annotations +__lazy_modules__ = { + "cibuildwheel.util.file", + "cibuildwheel.util.resources", + "filelock", + "fnmatch", + "hashlib", + "json", + "platform", + "subprocess", +} + 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