Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions docs/changelog.d/29.performance.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Reduce package import and CLI help startup time on Python 3.15 by deferring imports until needed.
6 changes: 6 additions & 0 deletions src/python_sbom/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions src/python_sbom/_cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__ = [
Expand Down
5 changes: 5 additions & 0 deletions src/python_sbom/_cli/_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/python_sbom/_cli/_embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions src/python_sbom/_cli/_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions src/python_sbom/_cli/_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

from __future__ import annotations

__lazy_modules__ = [
"argparse",
"pathlib",
"python_sbom._validate._limits",
"python_sbom.version",
]

from argparse import (
ArgumentParser,
ArgumentTypeError,
Expand Down
7 changes: 7 additions & 0 deletions src/python_sbom/_cli/_spdx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/python_sbom/_cli/_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from __future__ import annotations

__lazy_modules__ = ["python_sbom._validate._artifact"]

import sys
from typing import TYPE_CHECKING, Protocol

Expand Down
5 changes: 5 additions & 0 deletions src/python_sbom/_collect/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 8 additions & 0 deletions src/python_sbom/_collect/_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions src/python_sbom/_collect/_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions src/python_sbom/_collect/_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions src/python_sbom/_collect/_revision.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions src/python_sbom/_collect/_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 7 additions & 0 deletions src/python_sbom/_collect/_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 8 additions & 0 deletions src/python_sbom/_collect/_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/python_sbom/_formats/_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

from __future__ import annotations

__lazy_modules__ = [
"json",
"python_sbom",
]

import json
from typing import TYPE_CHECKING, Any, TypeAlias

Expand Down
9 changes: 9 additions & 0 deletions src/python_sbom/_formats/_spdx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/python_sbom/_generate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__ = [
Expand Down
18 changes: 18 additions & 0 deletions src/python_sbom/_generate/_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions src/python_sbom/_generate/_embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 7 additions & 0 deletions src/python_sbom/_model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions src/python_sbom/_model/_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions src/python_sbom/_model/_bom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions src/python_sbom/_model/_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/python_sbom/_model/_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from __future__ import annotations

__lazy_modules__ = ["collections"]

from collections import Counter
from typing import TYPE_CHECKING, Final

Expand Down
Loading
Loading