diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a32a71a..2ed0536 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -41,6 +41,13 @@ repos: - id: ruff-check priority: 3 args: ["--fix", "--unsafe-fixes", "--exit-non-zero-on-fix"] + - repo: https://github.com/henryiii/flake8-lazy + rev: 7f268b3b3aaf7feca756ca610e37971382976365 # frozen: v0.11.0 + hooks: + - id: flake8-lazy + priority: 2 + files: ^src/ + exclude: ^src/python_sbom/hatch/__init__\.py$ # importing the hook requires hatchling - repo: https://github.com/gaborbernat/simplint-pre-commit rev: "d14a8917a5f578a176baf72ab9ee76314558769f" # frozen: v0.12.3 hooks: diff --git a/docs/changelog.d/29.performance.rst b/docs/changelog.d/29.performance.rst new file mode 100644 index 0000000..addd74c --- /dev/null +++ b/docs/changelog.d/29.performance.rst @@ -0,0 +1 @@ +Reduce package import and CLI help startup time on Python 3.15 by deferring imports until needed. diff --git a/src/python_sbom/__init__.py b/src/python_sbom/__init__.py index b7c8343..8e24119 100644 --- a/src/python_sbom/__init__.py +++ b/src/python_sbom/__init__.py @@ -2,6 +2,12 @@ from __future__ import annotations +__lazy_modules__ = [ + f"{__spec__.parent}._errors", # ty: ignore[missing-union-attribute] # imported modules have a spec + f"{__spec__.parent}._model", # ty: ignore[missing-union-attribute] # imported modules have a spec + f"{__spec__.parent}.version", # ty: ignore[missing-union-attribute] # imported modules have a spec +] + from ._errors import MissingExtraError, SbomError from ._model import ( BundledWheelInfo, diff --git a/src/python_sbom/_cli/__init__.py b/src/python_sbom/_cli/__init__.py index 53c9d74..2fff01d 100644 --- a/src/python_sbom/_cli/__init__.py +++ b/src/python_sbom/_cli/__init__.py @@ -2,6 +2,8 @@ from __future__ import annotations +__lazy_modules__ = [f"{__spec__.parent}._main"] # ty: ignore[missing-union-attribute] # imported modules have a spec + from ._main import main __all__ = [ diff --git a/src/python_sbom/_cli/_archive.py b/src/python_sbom/_cli/_archive.py index 61259ea..8064172 100644 --- a/src/python_sbom/_cli/_archive.py +++ b/src/python_sbom/_cli/_archive.py @@ -2,6 +2,11 @@ from __future__ import annotations +__lazy_modules__ = [ + "pathlib", + "python_sbom._generate._archive", +] + import sys from pathlib import Path, PurePosixPath from typing import Protocol diff --git a/src/python_sbom/_cli/_embed.py b/src/python_sbom/_cli/_embed.py index b00479f..6a6465b 100644 --- a/src/python_sbom/_cli/_embed.py +++ b/src/python_sbom/_cli/_embed.py @@ -2,6 +2,11 @@ from __future__ import annotations +__lazy_modules__ = [ + "pathlib", + "python_sbom._generate._embed", +] + import sys from pathlib import Path from typing import Protocol diff --git a/src/python_sbom/_cli/_main.py b/src/python_sbom/_cli/_main.py index d3e3eb2..9aa0911 100644 --- a/src/python_sbom/_cli/_main.py +++ b/src/python_sbom/_cli/_main.py @@ -2,6 +2,12 @@ from __future__ import annotations +__lazy_modules__ = [ + "pkgutil", + "python_sbom", + f"{__spec__.parent}._parser", # ty: ignore[missing-union-attribute] # imported modules have a spec +] + import pkgutil import sys from typing import TYPE_CHECKING diff --git a/src/python_sbom/_cli/_parser.py b/src/python_sbom/_cli/_parser.py index 4c6d9a3..87471fa 100644 --- a/src/python_sbom/_cli/_parser.py +++ b/src/python_sbom/_cli/_parser.py @@ -2,6 +2,13 @@ from __future__ import annotations +__lazy_modules__ = [ + "argparse", + "pathlib", + "python_sbom._validate._limits", + "python_sbom.version", +] + from argparse import ( ArgumentParser, ArgumentTypeError, diff --git a/src/python_sbom/_cli/_spdx.py b/src/python_sbom/_cli/_spdx.py index f63a6d7..0a18116 100644 --- a/src/python_sbom/_cli/_spdx.py +++ b/src/python_sbom/_cli/_spdx.py @@ -2,6 +2,13 @@ from __future__ import annotations +__lazy_modules__ = [ + "python_sbom", + "python_sbom._formats._json", + "python_sbom._formats._spdx", + "python_sbom._validate._limits", +] + from typing import TYPE_CHECKING, Protocol from python_sbom import SbomError diff --git a/src/python_sbom/_cli/_validate.py b/src/python_sbom/_cli/_validate.py index 5267d46..ea29904 100644 --- a/src/python_sbom/_cli/_validate.py +++ b/src/python_sbom/_cli/_validate.py @@ -2,6 +2,8 @@ from __future__ import annotations +__lazy_modules__ = ["python_sbom._validate._artifact"] + import sys from typing import TYPE_CHECKING, Protocol diff --git a/src/python_sbom/_collect/__init__.py b/src/python_sbom/_collect/__init__.py index ec5d7a1..49b3727 100644 --- a/src/python_sbom/_collect/__init__.py +++ b/src/python_sbom/_collect/__init__.py @@ -2,6 +2,11 @@ from __future__ import annotations +__lazy_modules__ = [ + f"{__spec__.parent}._revision", # ty: ignore[missing-union-attribute] # imported modules have a spec + f"{__spec__.parent}._settings", # ty: ignore[missing-union-attribute] # imported modules have a spec +] + from ._revision import REVISION_FILE, default_revision, revision_record from ._settings import settings_from_pyproject diff --git a/src/python_sbom/_collect/_archive.py b/src/python_sbom/_collect/_archive.py index 363c42d..2b94140 100644 --- a/src/python_sbom/_collect/_archive.py +++ b/src/python_sbom/_collect/_archive.py @@ -2,6 +2,14 @@ from __future__ import annotations +__lazy_modules__ = [ + "python_sbom", + "python_sbom._model._archive", + "python_sbom._model._inputs", + "python_sbom._model._metadata", + "python_sbom._model._names", +] + from typing import TYPE_CHECKING, Final from python_sbom import SbomError diff --git a/src/python_sbom/_collect/_content.py b/src/python_sbom/_collect/_content.py index 501fb16..e32d4c8 100644 --- a/src/python_sbom/_collect/_content.py +++ b/src/python_sbom/_collect/_content.py @@ -2,6 +2,15 @@ from __future__ import annotations +__lazy_modules__ = [ + "importlib.machinery", + "inspect", + "pathlib", + "pkgutil", + "python_sbom", + "python_sbom._model._content", +] + import inspect import pkgutil import sys diff --git a/src/python_sbom/_collect/_facts.py b/src/python_sbom/_collect/_facts.py index 793803c..515c390 100644 --- a/src/python_sbom/_collect/_facts.py +++ b/src/python_sbom/_collect/_facts.py @@ -2,6 +2,22 @@ from __future__ import annotations +__lazy_modules__ = [ + "importlib.metadata", + "installer.records", + "itertools", + "json", + "packaging.direct_url", + "packaging.requirements", + "packaging.utils", + "platform", + "python_sbom", + "python_sbom._model._inputs", + "python_sbom._model._metadata", + "python_sbom._model._record", + "warnings", +] + import json import os import platform diff --git a/src/python_sbom/_collect/_revision.py b/src/python_sbom/_collect/_revision.py index f196f09..becbc73 100644 --- a/src/python_sbom/_collect/_revision.py +++ b/src/python_sbom/_collect/_revision.py @@ -2,6 +2,14 @@ from __future__ import annotations +__lazy_modules__ = [ + "python_sbom", + "python_sbom._model._inputs", + "shutil", + "subprocess", + "warnings", +] + import os import re import shutil diff --git a/src/python_sbom/_collect/_settings.py b/src/python_sbom/_collect/_settings.py index ca22b00..74531d9 100644 --- a/src/python_sbom/_collect/_settings.py +++ b/src/python_sbom/_collect/_settings.py @@ -2,6 +2,12 @@ from __future__ import annotations +__lazy_modules__ = [ + "python_sbom", + "python_sbom._model._inputs", + "tomllib", +] + import tomllib from typing import TYPE_CHECKING, TypeAlias diff --git a/src/python_sbom/_collect/_source.py b/src/python_sbom/_collect/_source.py index b584d57..e596450 100644 --- a/src/python_sbom/_collect/_source.py +++ b/src/python_sbom/_collect/_source.py @@ -2,6 +2,13 @@ from __future__ import annotations +__lazy_modules__ = [ + "pathlib", + "python_sbom", + "python_sbom._model._inputs", + "python_sbom._wheel._zip", +] + from pathlib import PurePath from typing import TYPE_CHECKING, Final diff --git a/src/python_sbom/_collect/_wheel.py b/src/python_sbom/_collect/_wheel.py index d46787a..ce0bc9f 100644 --- a/src/python_sbom/_collect/_wheel.py +++ b/src/python_sbom/_collect/_wheel.py @@ -2,6 +2,14 @@ from __future__ import annotations +__lazy_modules__ = [ + "python_sbom", + "python_sbom._model._inputs", + "python_sbom._model._names", + "python_sbom._wheel._zip", + f"{__spec__.parent}._source", # ty: ignore[missing-union-attribute] # imported modules have a spec +] + from typing import TYPE_CHECKING, Final from python_sbom import SbomError diff --git a/src/python_sbom/_formats/_json.py b/src/python_sbom/_formats/_json.py index 96fa8ab..5511ac4 100644 --- a/src/python_sbom/_formats/_json.py +++ b/src/python_sbom/_formats/_json.py @@ -2,6 +2,11 @@ from __future__ import annotations +__lazy_modules__ = [ + "json", + "python_sbom", +] + import json from typing import TYPE_CHECKING, Any, TypeAlias diff --git a/src/python_sbom/_formats/_spdx.py b/src/python_sbom/_formats/_spdx.py index bd76e27..05c87a2 100644 --- a/src/python_sbom/_formats/_spdx.py +++ b/src/python_sbom/_formats/_spdx.py @@ -2,6 +2,15 @@ from __future__ import annotations +__lazy_modules__ = [ + "datetime", + "hashlib", + "json", + "python_sbom._model._graph", + "python_sbom._model._names", + "python_sbom.version", +] + import hashlib import json import re diff --git a/src/python_sbom/_generate/__init__.py b/src/python_sbom/_generate/__init__.py index ef7d476..9311aa7 100644 --- a/src/python_sbom/_generate/__init__.py +++ b/src/python_sbom/_generate/__init__.py @@ -2,6 +2,8 @@ from __future__ import annotations +__lazy_modules__ = [f"{__spec__.parent}._embed"] # ty: ignore[missing-union-attribute] # imported modules have a spec + from ._embed import embed_built __all__ = [ diff --git a/src/python_sbom/_generate/_archive.py b/src/python_sbom/_generate/_archive.py index dd2be2b..f69bc97 100644 --- a/src/python_sbom/_generate/_archive.py +++ b/src/python_sbom/_generate/_archive.py @@ -2,6 +2,24 @@ from __future__ import annotations +__lazy_modules__ = [ + "python_sbom", + "python_sbom._collect._archive", + "python_sbom._collect._content", + "python_sbom._collect._facts", + "python_sbom._collect._revision", + "python_sbom._collect._settings", + "python_sbom._collect._source", + "python_sbom._formats._json", + "python_sbom._model._archive", + "python_sbom._model._bom", + "python_sbom._model._content", + "python_sbom._model._identity", + "python_sbom._model._names", + "python_sbom._wheel._reader", + "python_sbom._wheel._write", +] + from typing import TYPE_CHECKING from python_sbom import SbomError diff --git a/src/python_sbom/_generate/_embed.py b/src/python_sbom/_generate/_embed.py index d984665..871bcb4 100644 --- a/src/python_sbom/_generate/_embed.py +++ b/src/python_sbom/_generate/_embed.py @@ -2,6 +2,22 @@ from __future__ import annotations +__lazy_modules__ = [ + "pathlib", + "python_sbom._collect._content", + "python_sbom._collect._facts", + "python_sbom._collect._revision", + "python_sbom._collect._settings", + "python_sbom._collect._wheel", + "python_sbom._formats._json", + "python_sbom._model._bom", + "python_sbom._model._content", + "python_sbom._model._identity", + "python_sbom._model._wheel", + "python_sbom._wheel._reader", + "python_sbom._wheel._write", +] + from pathlib import PurePosixPath from typing import TYPE_CHECKING diff --git a/src/python_sbom/_model/__init__.py b/src/python_sbom/_model/__init__.py index ec5f8e7..e2644a5 100644 --- a/src/python_sbom/_model/__init__.py +++ b/src/python_sbom/_model/__init__.py @@ -2,6 +2,13 @@ from __future__ import annotations +__lazy_modules__ = [ + f"{__spec__.parent}._content", # ty: ignore[missing-union-attribute] # imported modules have a spec + f"{__spec__.parent}._identity", # ty: ignore[missing-union-attribute] # imported modules have a spec + f"{__spec__.parent}._inputs", # ty: ignore[missing-union-attribute] # imported modules have a spec + f"{__spec__.parent}._types", # ty: ignore[missing-union-attribute] # imported modules have a spec +] + from ._content import BundledWheelInfo, ContentProvider, Contributions, ProviderContext from ._identity import ProjectIdentity from ._inputs import Revision, Settings diff --git a/src/python_sbom/_model/_archive.py b/src/python_sbom/_model/_archive.py index 0a04c36..5f3bfe3 100644 --- a/src/python_sbom/_model/_archive.py +++ b/src/python_sbom/_model/_archive.py @@ -2,6 +2,15 @@ from __future__ import annotations +__lazy_modules__ = [ + "packageurl", + "pathlib", + f"{__spec__.parent}._components", # ty: ignore[missing-union-attribute] # imported modules have a spec + f"{__spec__.parent}._graph", # ty: ignore[missing-union-attribute] # imported modules have a spec + f"{__spec__.parent}._inputs", # ty: ignore[missing-union-attribute] # imported modules have a spec + f"{__spec__.parent}._names", # ty: ignore[missing-union-attribute] # imported modules have a spec +] + from dataclasses import dataclass from pathlib import PurePosixPath from typing import TYPE_CHECKING, Final diff --git a/src/python_sbom/_model/_bom.py b/src/python_sbom/_model/_bom.py index c19e0bc..49a011b 100644 --- a/src/python_sbom/_model/_bom.py +++ b/src/python_sbom/_model/_bom.py @@ -2,6 +2,18 @@ from __future__ import annotations +__lazy_modules__ = [ + "datetime", + "json", + "pathlib", + "python_sbom", + "urllib.parse", + "uuid", + f"{__spec__.parent}._graph", # ty: ignore[missing-union-attribute] # imported modules have a spec + f"{__spec__.parent}._names", # ty: ignore[missing-union-attribute] # imported modules have a spec + f"{__spec__.parent}._tools", # ty: ignore[missing-union-attribute] # imported modules have a spec +] + import json import uuid from datetime import UTC, datetime diff --git a/src/python_sbom/_model/_components.py b/src/python_sbom/_model/_components.py index c7f2926..e32bb55 100644 --- a/src/python_sbom/_model/_components.py +++ b/src/python_sbom/_model/_components.py @@ -2,6 +2,17 @@ from __future__ import annotations +__lazy_modules__ = [ + "email.utils", + "itertools", + "packaging.utils", + f"{__spec__.parent}._graph", # ty: ignore[missing-union-attribute] # imported modules have a spec + f"{__spec__.parent}._iri", # ty: ignore[missing-union-attribute] # imported modules have a spec + f"{__spec__.parent}._licenses", # ty: ignore[missing-union-attribute] # imported modules have a spec + f"{__spec__.parent}._names", # ty: ignore[missing-union-attribute] # imported modules have a spec + f"{__spec__.parent}._types", # ty: ignore[missing-union-attribute] # imported modules have a spec +] + import re from email.utils import getaddresses from itertools import starmap diff --git a/src/python_sbom/_model/_graph.py b/src/python_sbom/_model/_graph.py index 8374b9f..ff2f8e2 100644 --- a/src/python_sbom/_model/_graph.py +++ b/src/python_sbom/_model/_graph.py @@ -2,6 +2,8 @@ from __future__ import annotations +__lazy_modules__ = ["collections"] + from collections import Counter from typing import TYPE_CHECKING, Final diff --git a/src/python_sbom/_model/_identity.py b/src/python_sbom/_model/_identity.py index d59ed84..d598799 100644 --- a/src/python_sbom/_model/_identity.py +++ b/src/python_sbom/_model/_identity.py @@ -2,6 +2,12 @@ from __future__ import annotations +__lazy_modules__ = [ + "uuid", + f"{__spec__.parent}._iri", # ty: ignore[missing-union-attribute] # imported modules have a spec + f"{__spec__.parent}._names", # ty: ignore[missing-union-attribute] # imported modules have a spec +] + import uuid from dataclasses import dataclass from typing import TYPE_CHECKING diff --git a/src/python_sbom/_model/_iri.py b/src/python_sbom/_model/_iri.py index ca5dfda..f9f787f 100644 --- a/src/python_sbom/_model/_iri.py +++ b/src/python_sbom/_model/_iri.py @@ -2,6 +2,12 @@ from __future__ import annotations +__lazy_modules__ = [ + "ipaddress", + "typing", + "urllib.parse", +] + import ipaddress import re import string diff --git a/src/python_sbom/_model/_licenses.py b/src/python_sbom/_model/_licenses.py index 7cf6053..96f8aa9 100644 --- a/src/python_sbom/_model/_licenses.py +++ b/src/python_sbom/_model/_licenses.py @@ -2,6 +2,8 @@ from __future__ import annotations +__lazy_modules__ = ["packaging.licenses"] + import re from typing import TYPE_CHECKING, Final diff --git a/src/python_sbom/_model/_markers.py b/src/python_sbom/_model/_markers.py index a835895..c15ed75 100644 --- a/src/python_sbom/_model/_markers.py +++ b/src/python_sbom/_model/_markers.py @@ -2,6 +2,8 @@ from __future__ import annotations +__lazy_modules__ = ["packaging.markers"] + from typing import TYPE_CHECKING, Final from packaging.markers import Marker, UndefinedComparison diff --git a/src/python_sbom/_model/_metadata.py b/src/python_sbom/_model/_metadata.py index 0bf5cf1..ad9eb05 100644 --- a/src/python_sbom/_model/_metadata.py +++ b/src/python_sbom/_model/_metadata.py @@ -2,6 +2,12 @@ from __future__ import annotations +__lazy_modules__ = [ + "email.parser", + "email.policy", + "packaging.metadata", +] + import re from dataclasses import dataclass from email.parser import HeaderParser diff --git a/src/python_sbom/_model/_names.py b/src/python_sbom/_model/_names.py index bf43ac5..7b4c928 100644 --- a/src/python_sbom/_model/_names.py +++ b/src/python_sbom/_model/_names.py @@ -2,6 +2,12 @@ from __future__ import annotations +__lazy_modules__ = [ + "packageurl", + "packaging.utils", + "typing", +] + import re from types import MappingProxyType from typing import Final diff --git a/src/python_sbom/_model/_record.py b/src/python_sbom/_model/_record.py index ce5f918..f7db87f 100644 --- a/src/python_sbom/_model/_record.py +++ b/src/python_sbom/_model/_record.py @@ -2,6 +2,15 @@ from __future__ import annotations +__lazy_modules__ = [ + "base64", + "binascii", + "installer.records", + "itertools", + "python_sbom", + f"{__spec__.parent}._inputs", # ty: ignore[missing-union-attribute] # imported modules have a spec +] + import base64 import binascii from itertools import starmap diff --git a/src/python_sbom/_model/_tools.py b/src/python_sbom/_model/_tools.py index 6558580..1bbb4fc 100644 --- a/src/python_sbom/_model/_tools.py +++ b/src/python_sbom/_model/_tools.py @@ -2,6 +2,12 @@ from __future__ import annotations +__lazy_modules__ = [ + "packageurl", + f"{__spec__.parent}._components", # ty: ignore[missing-union-attribute] # imported modules have a spec + f"{__spec__.parent}._names", # ty: ignore[missing-union-attribute] # imported modules have a spec +] + from typing import TYPE_CHECKING, Final from packageurl import PackageURL diff --git a/src/python_sbom/_model/_wheel.py b/src/python_sbom/_model/_wheel.py index ecc8608..199047e 100644 --- a/src/python_sbom/_model/_wheel.py +++ b/src/python_sbom/_model/_wheel.py @@ -2,6 +2,17 @@ from __future__ import annotations +__lazy_modules__ = [ + "itertools", + "packaging.requirements", + "pathlib", + "urllib.parse", + f"{__spec__.parent}._components", # ty: ignore[missing-union-attribute] # imported modules have a spec + f"{__spec__.parent}._inputs", # ty: ignore[missing-union-attribute] # imported modules have a spec + f"{__spec__.parent}._markers", # ty: ignore[missing-union-attribute] # imported modules have a spec + f"{__spec__.parent}._names", # ty: ignore[missing-union-attribute] # imported modules have a spec +] + from itertools import starmap from pathlib import PurePosixPath from typing import TYPE_CHECKING, Final diff --git a/src/python_sbom/_validate/_artifact.py b/src/python_sbom/_validate/_artifact.py index dbaeb74..0a31fd2 100644 --- a/src/python_sbom/_validate/_artifact.py +++ b/src/python_sbom/_validate/_artifact.py @@ -2,6 +2,12 @@ from __future__ import annotations +__lazy_modules__ = [ + "python_sbom._wheel._zip", + "zipfile", + f"{__spec__.parent}._document", # ty: ignore[missing-union-attribute] # imported modules have a spec +] + import zipfile from typing import IO, TYPE_CHECKING, Final diff --git a/src/python_sbom/_validate/_document.py b/src/python_sbom/_validate/_document.py index aa97697..ceb51ab 100644 --- a/src/python_sbom/_validate/_document.py +++ b/src/python_sbom/_validate/_document.py @@ -2,6 +2,16 @@ from __future__ import annotations +__lazy_modules__ = [ + "importlib.util", + "math", + "python_sbom", + "python_sbom._formats._json", + "python_sbom._formats._spdx", + "python_sbom._model._graph", + "python_sbom._model._names", +] + import math import re from importlib.util import find_spec diff --git a/src/python_sbom/_validate/_licenses.py b/src/python_sbom/_validate/_licenses.py index e9a4969..d95a27c 100644 --- a/src/python_sbom/_validate/_licenses.py +++ b/src/python_sbom/_validate/_licenses.py @@ -2,6 +2,8 @@ from __future__ import annotations +__lazy_modules__ = ["python_sbom._model._graph"] + from typing import TYPE_CHECKING, Final from license_expression import ( diff --git a/src/python_sbom/_validate/_limits.py b/src/python_sbom/_validate/_limits.py index 4afd147..85f1004 100644 --- a/src/python_sbom/_validate/_limits.py +++ b/src/python_sbom/_validate/_limits.py @@ -2,6 +2,8 @@ from __future__ import annotations +__lazy_modules__ = ["typing"] + from typing import Final # every check takes time in proportion to the count, so the cap bounds the work an untrusted document can ask for, far diff --git a/src/python_sbom/_validate/_schemas.py b/src/python_sbom/_validate/_schemas.py index 7a6b4e7..0ac2b95 100644 --- a/src/python_sbom/_validate/_schemas.py +++ b/src/python_sbom/_validate/_schemas.py @@ -2,6 +2,19 @@ from __future__ import annotations +__lazy_modules__ = [ + "collections", + "license_expression", + "spdx_tools.common.spdx_licensing", + "spdx_tools.spdx.parser.error", + "spdx_tools.spdx.parser.jsonlikedict.json_like_dict_parser", + "spdx_tools.spdx.validation.creation_info_validator", + "spdx_tools.spdx.validation.extracted_licensing_info_validator", + "spdx_tools.spdx.validation.package_validator", + "spdx_tools.spdx.validation.spdx_id_validators", + f"{__spec__.parent}._limits", # ty: ignore[missing-union-attribute] # imported modules have a spec +] + import json from collections import Counter from importlib.resources import files diff --git a/src/python_sbom/_wheel/__init__.py b/src/python_sbom/_wheel/__init__.py index 5024da2..7b23e2b 100644 --- a/src/python_sbom/_wheel/__init__.py +++ b/src/python_sbom/_wheel/__init__.py @@ -2,6 +2,8 @@ from __future__ import annotations +__lazy_modules__ = [f"{__spec__.parent}._sdist"] # ty: ignore[missing-union-attribute] # imported modules have a spec + from ._sdist import add_to_sdist __all__ = [ diff --git a/src/python_sbom/_wheel/_bundled.py b/src/python_sbom/_wheel/_bundled.py index d31fcd1..9355bb5 100644 --- a/src/python_sbom/_wheel/_bundled.py +++ b/src/python_sbom/_wheel/_bundled.py @@ -2,6 +2,19 @@ from __future__ import annotations +__lazy_modules__ = [ + "collections", + "concurrent.futures", + "installer.records", + "installer.sources", + "packaging.requirements", + "python_sbom", + "python_sbom._model._inputs", + "python_sbom._model._metadata", + "python_sbom._model._record", + f"{__spec__.parent}._zip", # ty: ignore[missing-union-attribute] # imported modules have a spec +] + from collections import Counter from concurrent.futures import ThreadPoolExecutor from typing import TYPE_CHECKING, Final diff --git a/src/python_sbom/_wheel/_reader.py b/src/python_sbom/_wheel/_reader.py index cc47a42..7f93286 100644 --- a/src/python_sbom/_wheel/_reader.py +++ b/src/python_sbom/_wheel/_reader.py @@ -2,6 +2,12 @@ from __future__ import annotations +__lazy_modules__ = [ + "io", + f"{__spec__.parent}._bundled", # ty: ignore[missing-union-attribute] # imported modules have a spec + f"{__spec__.parent}._zip", # ty: ignore[missing-union-attribute] # imported modules have a spec +] + from contextlib import contextmanager from dataclasses import dataclass from io import BytesIO diff --git a/src/python_sbom/_wheel/_sdist.py b/src/python_sbom/_wheel/_sdist.py index cbcc2d3..a6ac330 100644 --- a/src/python_sbom/_wheel/_sdist.py +++ b/src/python_sbom/_wheel/_sdist.py @@ -2,6 +2,16 @@ from __future__ import annotations +__lazy_modules__ = [ + "gzip", + "io", + "pathlib", + "python_sbom", + "tarfile", + "tempfile", + "typing", +] + import gzip import io import os diff --git a/src/python_sbom/_wheel/_write.py b/src/python_sbom/_wheel/_write.py index d18b024..9f73613 100644 --- a/src/python_sbom/_wheel/_write.py +++ b/src/python_sbom/_wheel/_write.py @@ -2,6 +2,21 @@ from __future__ import annotations +__lazy_modules__ = [ + "csv", + "installer.records", + "installer.utils", + "io", + "pathlib", + "python_sbom", + "shutil", + "tempfile", + "typing", + "zipfile", + "zipremove", + f"{__spec__.parent}._zip", # ty: ignore[missing-union-attribute] # imported modules have a spec +] + import csv import os import shutil diff --git a/src/python_sbom/_wheel/_zip.py b/src/python_sbom/_wheel/_zip.py index 0130ed4..eeef4aa 100644 --- a/src/python_sbom/_wheel/_zip.py +++ b/src/python_sbom/_wheel/_zip.py @@ -2,6 +2,16 @@ from __future__ import annotations +__lazy_modules__ = [ + "collections", + "hashlib", + "installer.sources", + "python_sbom", + "python_sbom._model._metadata", + "zipfile", + "zlib", +] + import hashlib import zipfile import zlib diff --git a/src/python_sbom/backend.py b/src/python_sbom/backend.py index bb739b9..de6810f 100644 --- a/src/python_sbom/backend.py +++ b/src/python_sbom/backend.py @@ -2,6 +2,13 @@ from __future__ import annotations +__lazy_modules__ = [ + "importlib", + "pathlib", + f"{__spec__.parent}._collect", # ty: ignore[missing-union-attribute] # imported modules have a spec + f"{__spec__.parent}._errors", # ty: ignore[missing-union-attribute] # imported modules have a spec +] + import importlib from collections.abc import Mapping as _Mapping from functools import cache, reduce diff --git a/src/python_sbom/hatch/_hook.py b/src/python_sbom/hatch/_hook.py index 5d56140..0415be6 100644 --- a/src/python_sbom/hatch/_hook.py +++ b/src/python_sbom/hatch/_hook.py @@ -2,6 +2,19 @@ from __future__ import annotations +__lazy_modules__ = [ + "hatchling.builders.utils", + "hatchling.utils.constants", + "pathlib", + "python_sbom", + "python_sbom._collect._content", + "python_sbom._collect._revision", + "python_sbom._collect._settings", + "shutil", + "tempfile", + "weakref", +] + import shutil import tempfile import weakref diff --git a/src/python_sbom/hatch/hooks.py b/src/python_sbom/hatch/hooks.py index ed86134..921b0c1 100644 --- a/src/python_sbom/hatch/hooks.py +++ b/src/python_sbom/hatch/hooks.py @@ -2,6 +2,8 @@ from __future__ import annotations +__lazy_modules__ = [f"{__spec__.parent}._hook"] # ty: ignore[missing-union-attribute] # imported modules have a spec + from hatchling.plugin import hookimpl from ._hook import SbomBuildHook diff --git a/src/python_sbom/pdm.py b/src/python_sbom/pdm.py index bc48d18..ebc3abe 100644 --- a/src/python_sbom/pdm.py +++ b/src/python_sbom/pdm.py @@ -2,6 +2,13 @@ from __future__ import annotations +__lazy_modules__ = [ + "calendar", + "pathlib", + "tempfile", + f"{__spec__.parent}._collect", # ty: ignore[missing-union-attribute] # imported modules have a spec +] + import calendar import tempfile from pathlib import Path diff --git a/src/python_sbom/setuptools.py b/src/python_sbom/setuptools.py index 9a0b3bf..13e9aa1 100644 --- a/src/python_sbom/setuptools.py +++ b/src/python_sbom/setuptools.py @@ -2,6 +2,15 @@ from __future__ import annotations +__lazy_modules__ = [ + "pathlib", + "setuptools.command.bdist_wheel", + "setuptools.command.sdist", + "tomllib", + f"{__spec__.parent}._collect", # ty: ignore[missing-union-attribute] # imported modules have a spec + f"{__spec__.parent}._errors", # ty: ignore[missing-union-attribute] # imported modules have a spec +] + import tomllib from pathlib import Path from typing import TYPE_CHECKING