diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 164bfac1..b3198cb3 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 2a3287ef..c5d5d772 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 41d5ad86..4fe43741 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 10f4c7cf..dadaef04 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 85cdcb1a..5a327a66 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 648f29c2..09619f12 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 bc5d13bf..a38ad22a 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 2a6ae594..6576fb90 100644 --- a/cibuildwheel/errors.py +++ b/cibuildwheel/errors.py @@ -4,6 +4,8 @@ a different return code, by defining them all here, we can ensure that they're semantically clear and unique. """ +__lazy_modules__ = {"textwrap"} + import textwrap diff --git a/cibuildwheel/extra.py b/cibuildwheel/extra.py index 30f280cb..9b1abcb1 100644 --- a/cibuildwheel/extra.py +++ b/cibuildwheel/extra.py @@ -4,6 +4,8 @@ These are utilities for the `/bin` scripts, not for the `cibuildwheel` program. 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 14a8ede8..41c53b34 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 da33370e..69314fac 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 db9e1f03..49e14a93 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 ed39bf35..2d3e32a3 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 d65de5ac..5e47196b 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 61e7574d..60ee0daa 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 606eacc4..54f29e4e 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 4a20012d..5ef4a3e7 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 eb2bc032..444c55a4 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 6d1eaa4a..fd4aa65b 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 41af8b1f..ecc6a213 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 dde0efcc..b48793fd 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 579a18f5..9314fa1e 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 ed864c27..1795eb8e 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 b92727ac..111b7d90 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 a8a4df78..d6ed1797 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 d8bb57c6..58d2a281 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 186569bb..2e8c7fb8 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 dd3d151f..3bbef753 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 174b2a1b..2867edd7 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