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
2 changes: 2 additions & 0 deletions docs/changelog.d/+public-missing-extra-error.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Expose ``MissingExtraError`` from ``python_sbom`` so callers can catch a missing optional dependency without importing
the private errors module.
2 changes: 2 additions & 0 deletions docs/reference/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,5 @@ every key.
********

.. autoexception:: python_sbom.SbomError

.. autoexception:: python_sbom.MissingExtraError
3 changes: 2 additions & 1 deletion src/python_sbom/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import annotations

from ._errors import SbomError
from ._errors import MissingExtraError, SbomError
from ._model._content import BundledWheelInfo, ContentProvider, Contributions, ProviderContext
from ._model._identity import ProjectIdentity
from ._model._inputs import Settings
Expand Down Expand Up @@ -36,6 +36,7 @@
"IdentityMethod",
"License",
"LicenseInfo",
"MissingExtraError",
"OrganizationalEntity",
"ProjectIdentity",
"Property",
Expand Down
2 changes: 1 addition & 1 deletion src/python_sbom/_cli/_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import sys
from typing import TYPE_CHECKING

from python_sbom._errors import SbomError
from python_sbom import SbomError

from ._parser import build_parser

Expand Down
2 changes: 1 addition & 1 deletion src/python_sbom/_cli/_spdx.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from typing import TYPE_CHECKING, Protocol

from python_sbom._errors import SbomError
from python_sbom import SbomError
from python_sbom._formats._json import dumps, is_document, load_json
from python_sbom._formats._spdx import render_spdx
from python_sbom._validate._limits import MAX_COMPONENTS, byte_limit
Expand Down
2 changes: 1 addition & 1 deletion src/python_sbom/_collect/_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from typing import TYPE_CHECKING, Final

from python_sbom._errors import SbomError
from python_sbom import SbomError
from python_sbom._model._archive import bundled_members
from python_sbom._model._inputs import ArchiveTree, RecordRow
from python_sbom._model._metadata import parse_metadata
Expand Down
2 changes: 1 addition & 1 deletion src/python_sbom/_collect/_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from pathlib import Path, PurePosixPath
from typing import TYPE_CHECKING, Final

from python_sbom._errors import SbomError
from python_sbom import SbomError
from python_sbom._model._content import ContentProvider

if TYPE_CHECKING:
Expand Down
2 changes: 1 addition & 1 deletion src/python_sbom/_collect/_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from packaging.requirements import InvalidRequirement, Requirement
from packaging.utils import canonicalize_name

from python_sbom._errors import SbomError
from python_sbom import SbomError
from python_sbom._model._inputs import BuildFacts, InstalledDistribution, Interpreter, RecordRow
from python_sbom._model._metadata import parse_metadata
from python_sbom._model._record import record_rows
Expand Down
2 changes: 1 addition & 1 deletion src/python_sbom/_collect/_revision.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import warnings
from typing import TYPE_CHECKING, Final, Protocol

from python_sbom._errors import SbomError
from python_sbom import SbomError
from python_sbom._model._inputs import Revision

if TYPE_CHECKING:
Expand Down
2 changes: 1 addition & 1 deletion src/python_sbom/_collect/_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import tomllib
from typing import TYPE_CHECKING, TypeAlias

from python_sbom._errors import SbomError
from python_sbom import SbomError
from python_sbom._model._inputs import Settings

if TYPE_CHECKING:
Expand Down
2 changes: 1 addition & 1 deletion src/python_sbom/_collect/_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from pathlib import PurePath
from typing import TYPE_CHECKING, Final

from python_sbom._errors import SbomError
from python_sbom import SbomError
from python_sbom._model._inputs import BuildScript
from python_sbom._wheel._zip import sha256_hex

Expand Down
2 changes: 1 addition & 1 deletion src/python_sbom/_collect/_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from typing import TYPE_CHECKING, Final

from python_sbom._errors import SbomError
from python_sbom import SbomError
from python_sbom._model._inputs import WheelTree
from python_sbom._wheel._zip import read_wheel_metadata

Expand Down
3 changes: 2 additions & 1 deletion src/python_sbom/_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ class SbomError(Exception):


# validation reports every other error per document, and lets this one through, since it fails every document alike
class MissingExtraError(SbomError): ... # simplint: ignore[SMP704] # see above
class MissingExtraError(SbomError):
"""Raised when validation needs an optional dependency that is not installed."""


__all__ = [
Expand Down
2 changes: 1 addition & 1 deletion src/python_sbom/_formats/_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import json
from typing import TYPE_CHECKING, Any, TypeAlias

from python_sbom._errors import SbomError
from python_sbom import SbomError

if TYPE_CHECKING:
from typing import TypeIs # new in 3.13; annotations here are never evaluated
Expand Down
2 changes: 1 addition & 1 deletion src/python_sbom/_generate/_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

from typing import TYPE_CHECKING

from python_sbom import SbomError
from python_sbom._collect._archive import read_archive
from python_sbom._collect._content import resolve_provider
from python_sbom._collect._facts import collect_facts
from python_sbom._collect._revision import revision_reader
from python_sbom._collect._settings import settings_from_pyproject
from python_sbom._collect._source import copyright_notice, hash_build_scripts
from python_sbom._errors import SbomError
from python_sbom._formats._json import dumps
from python_sbom._model._archive import archive_artifact, bundled_paths
from python_sbom._model._bom import assemble, checked_contributions
Expand Down
2 changes: 1 addition & 1 deletion src/python_sbom/_model/_bom.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from typing import TYPE_CHECKING, Final
from urllib.parse import urlsplit

from python_sbom._errors import SbomError
from python_sbom import SbomError

from ._graph import reference_problems, walk_components
from ._names import SBOM_FILE, SBOM_REPOSITORY, sbom_property
Expand Down
2 changes: 1 addition & 1 deletion src/python_sbom/_model/_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from installer.records import RecordEntry

from python_sbom._errors import SbomError
from python_sbom import SbomError

from ._inputs import RecordRow

Expand Down
2 changes: 1 addition & 1 deletion src/python_sbom/_validate/_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from importlib.util import find_spec
from typing import TYPE_CHECKING, Final

from python_sbom._errors import MissingExtraError, SbomError
from python_sbom import MissingExtraError, SbomError
from python_sbom._formats._json import Json, has_path, is_document, load_json
from python_sbom._formats._spdx import render_spdx
from python_sbom._model._graph import artifact_contents, reference_problems, repeated, walk_components
Expand Down
2 changes: 1 addition & 1 deletion src/python_sbom/_wheel/_bundled.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from installer.sources import WheelFile
from packaging.requirements import InvalidRequirement, Requirement

from python_sbom._errors import SbomError
from python_sbom import SbomError
from python_sbom._model._inputs import BundledWheel, RecordRow
from python_sbom._model._metadata import CoreMetadata, parse_metadata
from python_sbom._model._record import record_rows
Expand Down
2 changes: 1 addition & 1 deletion src/python_sbom/_wheel/_sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from pathlib import Path
from typing import Final

from python_sbom._errors import SbomError
from python_sbom import SbomError


def add_to_sdist(sdist: Path, name: str, content: bytes) -> None:
Expand Down
2 changes: 1 addition & 1 deletion src/python_sbom/_wheel/_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from installer.records import Hash, RecordEntry
from installer.utils import copyfileobj_with_hashing

from python_sbom._errors import SbomError
from python_sbom import SbomError

from ._zip import open_archive, wheel_source

Expand Down
2 changes: 1 addition & 1 deletion src/python_sbom/_wheel/_zip.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from installer.sources import WheelFile

from python_sbom._errors import SbomError
from python_sbom import SbomError
from python_sbom._model._metadata import CoreMetadata, parse_metadata

if TYPE_CHECKING:
Expand Down
2 changes: 1 addition & 1 deletion src/python_sbom/hatch/_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
from hatchling.builders.utils import get_reproducible_timestamp
from hatchling.utils.constants import DEFAULT_BUILD_SCRIPT

from python_sbom import SbomError
from python_sbom._collect._content import resolve_provider
from python_sbom._collect._revision import REVISION_FILE, default_revision, revision_record
from python_sbom._collect._settings import settings_from_table
from python_sbom._errors import SbomError

if TYPE_CHECKING:
from collections.abc import Callable
Expand Down
3 changes: 1 addition & 2 deletions tests/_collect/test_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
import pytest

import python_sbom
from python_sbom import ContentProvider
from python_sbom import ContentProvider, SbomError
from python_sbom._collect._content import resolve_provider
from python_sbom._errors import SbomError

if TYPE_CHECKING:
from python_sbom import Settings
Expand Down
2 changes: 1 addition & 1 deletion tests/_collect/test_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

import pytest

from python_sbom import SbomError
from python_sbom._collect._facts import collect_facts
from python_sbom._errors import SbomError
from python_sbom._model._inputs import Interpreter, RecordRow, Revision

if TYPE_CHECKING:
Expand Down
2 changes: 1 addition & 1 deletion tests/_collect/test_revision.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

import pytest

from python_sbom import SbomError
from python_sbom._collect._revision import REVISION_FILE, default_revision, revision_reader
from python_sbom._errors import SbomError
from python_sbom._model._inputs import Revision

if TYPE_CHECKING:
Expand Down
2 changes: 1 addition & 1 deletion tests/_collect/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

import pytest

from python_sbom import SbomError
from python_sbom._collect._settings import settings_from_pyproject, settings_from_table
from python_sbom._errors import SbomError
from python_sbom._model._inputs import Settings

if TYPE_CHECKING:
Expand Down
2 changes: 1 addition & 1 deletion tests/_collect/test_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

import pytest

from python_sbom import SbomError
from python_sbom._collect._source import copyright_notice, hash_build_scripts, selected_wheels
from python_sbom._errors import SbomError
from python_sbom._model._inputs import BuildScript

if TYPE_CHECKING:
Expand Down
2 changes: 1 addition & 1 deletion tests/_collect/test_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

import pytest

from python_sbom import SbomError
from python_sbom._collect._wheel import read_wheel
from python_sbom._errors import SbomError
from python_sbom._model._inputs import BuildScript, WheelTree
from python_sbom._wheel._reader import open_artifact

Expand Down
3 changes: 1 addition & 2 deletions tests/_generate/test_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@

import pytest

from python_sbom import BundledWheelInfo, ContentProvider, Contributions, ProviderContext
from python_sbom import BundledWheelInfo, ContentProvider, Contributions, ProviderContext, SbomError
from python_sbom._collect._facts import collect_facts
from python_sbom._collect._revision import revision_reader
from python_sbom._errors import SbomError
from python_sbom._generate._archive import describe_archive
from python_sbom._model._inputs import Revision
from python_sbom._validate._artifact import validate
Expand Down
3 changes: 1 addition & 2 deletions tests/_model/test_bom.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@

import pytest

from python_sbom import BundledWheelInfo, ContentProvider, Contributions, ProviderContext
from python_sbom._errors import SbomError
from python_sbom import BundledWheelInfo, ContentProvider, Contributions, ProviderContext, SbomError
from python_sbom._model._bom import (
check_refs,
checked_contributions,
Expand Down
2 changes: 1 addition & 1 deletion tests/_model/test_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import pytest

from python_sbom._errors import SbomError
from python_sbom import SbomError
from python_sbom._model._inputs import RecordRow
from python_sbom._model._record import record_rows

Expand Down
2 changes: 1 addition & 1 deletion tests/_validate/test_artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import pytest

from python_sbom._errors import SbomError
from python_sbom import SbomError
from python_sbom._formats._json import dumps
from python_sbom._validate._artifact import validate

Expand Down
2 changes: 1 addition & 1 deletion tests/_validate/test_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from spdx_tools.spdx.parser.jsonlikedict.json_like_dict_parser import JsonLikeDictParser
from spdx_tools.spdx.validation.document_validator import validate_full_spdx_document

from python_sbom._errors import MissingExtraError
from python_sbom import MissingExtraError
from python_sbom._formats._json import dumps
from python_sbom._formats._spdx import render_spdx
from python_sbom._validate._document import validate_document
Expand Down
2 changes: 1 addition & 1 deletion tests/_wheel/test_bundled.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import pytest

from python_sbom._errors import SbomError
from python_sbom import SbomError
from python_sbom._model._inputs import BundledWheel, RecordRow
from python_sbom._wheel._bundled import read_bundled_wheels

Expand Down
2 changes: 1 addition & 1 deletion tests/_wheel/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import pytest

from python_sbom._errors import SbomError
from python_sbom import SbomError
from python_sbom._wheel._reader import open_artifact


Expand Down
2 changes: 1 addition & 1 deletion tests/_wheel/test_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import pytest

from python_sbom._errors import SbomError
from python_sbom import SbomError
from python_sbom._wheel._write import append_member, write_sbom

if TYPE_CHECKING:
Expand Down
2 changes: 1 addition & 1 deletion tests/_wheel/test_zip.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import pytest

from python_sbom._errors import SbomError
from python_sbom import SbomError
from python_sbom._wheel._zip import open_archive, read_member, sha256_hex

if TYPE_CHECKING:
Expand Down
2 changes: 1 addition & 1 deletion tests/hatch/test_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import pytest

from python_sbom._errors import SbomError
from python_sbom import SbomError
from python_sbom._validate._artifact import validate

if TYPE_CHECKING:
Expand Down
3 changes: 1 addition & 2 deletions tests/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
import flit_core.buildapi
import pytest

from python_sbom import backend
from python_sbom._errors import SbomError
from python_sbom import SbomError, backend
from python_sbom._validate._artifact import validate

if TYPE_CHECKING:
Expand Down
1 change: 1 addition & 0 deletions tests/test_public_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"IdentityMethod",
"License",
"LicenseInfo",
"MissingExtraError",
"OrganizationalEntity",
"ProjectIdentity",
"Property",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_setuptools.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from setuptools import build_meta
from setuptools.dist import Distribution

from python_sbom._errors import SbomError
from python_sbom import SbomError
from python_sbom._validate._artifact import validate
from python_sbom.setuptools import finalize_distribution_options

Expand Down
Loading