diff options
author | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2017-11-06 18:15:33 +0900 |
---|---|---|
committer | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2017-11-06 18:15:33 +0900 |
commit | 27aac095bdb6b0025c989572789a1f98d8d89b3c (patch) | |
tree | 0ca7572b7db4b8b5fcb47e08fda41e22bbe41990 /buildstream | |
parent | 0defb35c0334d78e48bcf21ec6b106b67761e1bc (diff) | |
download | buildstream-27aac095bdb6b0025c989572789a1f98d8d89b3c.tar.gz |
Refactoring: Move exceptions module to be private
Hide all of buildstream's internal exceptions from the API surface.
Diffstat (limited to 'buildstream')
30 files changed, 92 insertions, 85 deletions
diff --git a/buildstream/__init__.py b/buildstream/__init__.py index 3d800610e..bb7a338a4 100644 --- a/buildstream/__init__.py +++ b/buildstream/__init__.py @@ -18,10 +18,6 @@ # Authors: # Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> -# Exceptions and utilities first -from .exceptions import PluginError, LoadError, LoadErrorReason, \ - ImplError, ProgramNotFoundError, PlatformError, SandboxError - # Core components from .context import Context from .project import Project diff --git a/buildstream/_artifactcache/artifactcache.py b/buildstream/_artifactcache/artifactcache.py index 246a7691d..66e6520c9 100644 --- a/buildstream/_artifactcache/artifactcache.py +++ b/buildstream/_artifactcache/artifactcache.py @@ -21,7 +21,8 @@ import os from collections import Mapping -from .. import utils, ImplError +from .._exceptions import ImplError +from .. import utils from .. import _yaml diff --git a/buildstream/_artifactcache/ostreecache.py b/buildstream/_artifactcache/ostreecache.py index 85ad3a4cf..d958c0bc5 100644 --- a/buildstream/_artifactcache/ostreecache.py +++ b/buildstream/_artifactcache/ostreecache.py @@ -24,7 +24,7 @@ import string import tempfile from .. import _ostree, utils -from ..exceptions import _ArtifactError +from .._exceptions import _ArtifactError from ..element import _KeyStrength from .._ostree import OSTreeError diff --git a/buildstream/_artifactcache/tarcache.py b/buildstream/_artifactcache/tarcache.py index 74ba0b3a0..5f28dcb41 100644 --- a/buildstream/_artifactcache/tarcache.py +++ b/buildstream/_artifactcache/tarcache.py @@ -26,7 +26,7 @@ import subprocess from .. import utils from ..element import _KeyStrength from .._message import Message, MessageType -from ..exceptions import _ArtifactError, ProgramNotFoundError +from .._exceptions import _ArtifactError, ProgramNotFoundError from . import ArtifactCache diff --git a/buildstream/exceptions.py b/buildstream/_exceptions.py index e896c0c20..c1deee786 100644 --- a/buildstream/exceptions.py +++ b/buildstream/_exceptions.py @@ -17,10 +17,6 @@ # # Authors: # Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> -""" -Exceptions -========== -""" from enum import Enum @@ -60,98 +56,115 @@ class _BstError(Exception): _last_exception = self +# PluginError +# +# Raised on plugin related errors. +# +# This exception is raised either by the plugin loading process, +# or by the base :class:`.Plugin` element itself. +# class PluginError(_BstError): - """Raised on plugin related errors. - - This exception is raised either by the plugin loading process, - or by the base :class:`.Plugin` element itself. - """ pass +# LoadErrorReason +# +# Describes the reason why a :class:`.LoadError` was raised. +# class LoadErrorReason(Enum): - """Describes the reason why a :class:`.LoadError` was raised. - """ + # A file was not found. MISSING_FILE = 1 - """A file was not found.""" + # The parsed data was not valid YAML. INVALID_YAML = 2 - """The parsed data was not valid YAML.""" + # Data was malformed, a value was not of the expected type, etc INVALID_DATA = 3 - """Data was malformed, a value was not of the expected type, etc""" + # An error occurred during YAML dictionary composition. + # + # This can happen by overriding a value with a new differently typed + # value, or by overwriting some named value when that was not allowed. ILLEGAL_COMPOSITE = 4 - """An error occurred during YAML dictionary composition. - - This can happen by overriding a value with a new differently typed - value, or by overwriting some named value when that was not allowed. - """ + # An circular dependency chain was detected CIRCULAR_DEPENDENCY = 5 - """An circular dependency chain was detected""" + # A variable could not be resolved. This can happen if your project + # has cyclic dependencies in variable declarations, or, when substituting + # a string which refers to an undefined variable. UNRESOLVED_VARIABLE = 6 - """A variable could not be resolved. This can happen if your project - has cyclic dependencies in variable declarations, or, when substituting - a string which refers to an undefined variable. - """ + # BuildStream does not support the required project format version UNSUPPORTED_PROJECT = 7 - """BuildStream does not support the required project format version""" + # A conditional expression failed to resolve EXPRESSION_FAILED = 8 - """A conditional expression failed to resolve""" + # An assertion was intentionally encoded into project YAML USER_ASSERTION = 9 - """An assertion was intentionally encoded into project YAML""" + # A list composition directive did not apply to any underlying list TRAILING_LIST_DIRECTIVE = 10 - """A list composition directive did not apply to any underlying list""" +# LoadError +# +# Raised while loading some YAML. +# +# This exception is raised when loading or parsing YAML, or when +# interpreting project YAML +# class LoadError(_BstError): - """Raised while loading some YAML. - - This exception is raised when loading or parsing YAML, or when - interpreting project YAML - """ def __init__(self, reason, message): super(LoadError, self).__init__(message) + # The :class:`.LoadErrorReason` for which this exception was raised + # self.reason = reason - """The :class:`.LoadErrorReason` for which this exception was raised - """ +# ImplError +# +# Raised when a :class:`.Source` or :class:`.Element` plugin fails to +# implement a mandatory method +# class ImplError(_BstError): - """Raised when a :class:`.Source` or :class:`.Element` plugin fails to - implement a mandatory method""" pass +# ProgramNotFoundError +# +# Raised if a required program is not found +# +# BuildStream requires various software to exist on the host for +# it to work correctly. This exception is thrown if that software +# can not be found. E.g. The :class:`.Sandbox` class expects that +# bubblewrap is installed for it to work. +# class ProgramNotFoundError(_BstError): - """Raised if a required program is not found - - BuildSource requires various software to exist on the host for - it to work correctly. This exception is thrown if that software - can not be found. E.g. The :class:`.Sandbox` class expects that - bubblewrap is installed for it to work. - """ pass +# PlatformError +# +# Raised if the current platform is not supported. class PlatformError(_BstError): - """Raised if the current platform is not supported. - """ pass +# SandboxError +# +# Raised when errors are encountered by the sandbox implementation +# class SandboxError(_BstError): - """Raised when errors are encountered by the sandbox implementation""" pass +# ArtifactError +# +# Raised when errors are encountered in the artifact caches +# class _ArtifactError(_BstError): pass diff --git a/buildstream/_frontend/main.py b/buildstream/_frontend/main.py index 12ed727ab..662f267cb 100644 --- a/buildstream/_frontend/main.py +++ b/buildstream/_frontend/main.py @@ -25,10 +25,10 @@ from contextlib import contextmanager from blessings import Terminal # Import buildstream public symbols -from .. import Context, Project, Scope, Consistency, LoadError +from .. import Context, Project, Scope, Consistency # Import various buildstream internals -from ..exceptions import _BstError +from .._exceptions import _BstError, LoadError from .._message import MessageType, unconditional_messages from .._pipeline import Pipeline, PipelineError from .._scheduler import Scheduler diff --git a/buildstream/_frontend/widget.py b/buildstream/_frontend/widget.py index e09f3d900..1d7a5ecc8 100644 --- a/buildstream/_frontend/widget.py +++ b/buildstream/_frontend/widget.py @@ -30,7 +30,7 @@ from mmap import mmap from .. import utils, _yaml from ..plugin import _plugin_lookup from .._message import MessageType -from .. import ImplError +from .._exceptions import ImplError from .. import Element, Scope, Consistency from . import Profile diff --git a/buildstream/_loader.py b/buildstream/_loader.py index 788a5c98e..9a3fd5eaa 100644 --- a/buildstream/_loader.py +++ b/buildstream/_loader.py @@ -23,7 +23,7 @@ import copy from functools import cmp_to_key from collections import Mapping, namedtuple -from . import LoadError, LoadErrorReason +from ._exceptions import LoadError, LoadErrorReason from . import _yaml from ._yaml import CompositeTypeError diff --git a/buildstream/_options/optionbool.py b/buildstream/_options/optionbool.py index a4619504d..db01340e4 100644 --- a/buildstream/_options/optionbool.py +++ b/buildstream/_options/optionbool.py @@ -19,7 +19,7 @@ # Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> from .. import _yaml -from .. import LoadError, LoadErrorReason +from .._exceptions import LoadError, LoadErrorReason from .option import Option, OPTION_SYMBOLS diff --git a/buildstream/_options/optionenum.py b/buildstream/_options/optionenum.py index 5c4db7ddf..2ba8552d7 100644 --- a/buildstream/_options/optionenum.py +++ b/buildstream/_options/optionenum.py @@ -19,7 +19,7 @@ # Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> from .. import _yaml -from .. import LoadError, LoadErrorReason +from .._exceptions import LoadError, LoadErrorReason from .option import Option, OPTION_SYMBOLS diff --git a/buildstream/_options/optionflags.py b/buildstream/_options/optionflags.py index 25d2d1c59..49ec70d85 100644 --- a/buildstream/_options/optionflags.py +++ b/buildstream/_options/optionflags.py @@ -19,7 +19,7 @@ # Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> from .. import _yaml -from .. import LoadError, LoadErrorReason +from .._exceptions import LoadError, LoadErrorReason from .option import Option, OPTION_SYMBOLS diff --git a/buildstream/_options/optionpool.py b/buildstream/_options/optionpool.py index c2374c542..adca24a2d 100644 --- a/buildstream/_options/optionpool.py +++ b/buildstream/_options/optionpool.py @@ -23,7 +23,7 @@ import jinja2 from collections import Mapping from .. import _yaml -from .. import LoadError, LoadErrorReason +from .._exceptions import LoadError, LoadErrorReason from .optionbool import OptionBool from .optionenum import OptionEnum from .optionflags import OptionFlags diff --git a/buildstream/_ostree.py b/buildstream/_ostree.py index a5029a690..8e390e94b 100644 --- a/buildstream/_ostree.py +++ b/buildstream/_ostree.py @@ -26,7 +26,7 @@ import os import subprocess from . import _site from . import utils -from .exceptions import _BstError +from ._exceptions import _BstError import gi gi.require_version('OSTree', '1.0') diff --git a/buildstream/_pipeline.py b/buildstream/_pipeline.py index edaf13318..1df57a9c1 100644 --- a/buildstream/_pipeline.py +++ b/buildstream/_pipeline.py @@ -29,12 +29,12 @@ from operator import itemgetter from tempfile import TemporaryDirectory from pluginbase import PluginBase -from .exceptions import _BstError, _ArtifactError +from ._exceptions import _BstError, _ArtifactError, ImplError, LoadError from ._message import Message, MessageType from ._elementfactory import ElementFactory from ._loader import Loader from ._sourcefactory import SourceFactory -from . import Consistency, ImplError, LoadError +from . import Consistency from . import Scope from . import _site from . import _yaml, utils diff --git a/buildstream/_platform/linux.py b/buildstream/_platform/linux.py index c94e3632d..cab9aa996 100644 --- a/buildstream/_platform/linux.py +++ b/buildstream/_platform/linux.py @@ -23,7 +23,7 @@ import sys import subprocess from .. import utils -from .. import PlatformError +from .._exceptions import PlatformError from .._message import Message, MessageType from ..sandbox import SandboxBwrap from .._artifactcache.ostreecache import OSTreeCache diff --git a/buildstream/_platform/platform.py b/buildstream/_platform/platform.py index 387abcb9a..0f3007cd9 100644 --- a/buildstream/_platform/platform.py +++ b/buildstream/_platform/platform.py @@ -23,7 +23,7 @@ import sys import platform from .. import utils -from .. import PlatformError, ProgramNotFoundError, ImplError +from .._exceptions import PlatformError, ProgramNotFoundError, ImplError class Platform(): diff --git a/buildstream/_platform/unix.py b/buildstream/_platform/unix.py index 752386bdf..8a9f6ea17 100644 --- a/buildstream/_platform/unix.py +++ b/buildstream/_platform/unix.py @@ -23,7 +23,7 @@ import sys import pathlib from .. import utils -from .. import PlatformError +from .._exceptions import PlatformError from ..sandbox import SandboxChroot from .._artifactcache.tarcache import TarCache diff --git a/buildstream/_plugincontext.py b/buildstream/_plugincontext.py index 0207136ef..3b82954ed 100644 --- a/buildstream/_plugincontext.py +++ b/buildstream/_plugincontext.py @@ -22,7 +22,7 @@ import os import inspect import pkg_resources -from .exceptions import PluginError +from ._exceptions import PluginError from . import utils diff --git a/buildstream/_scheduler/job.py b/buildstream/_scheduler/job.py index 90551b712..d8e720d9f 100644 --- a/buildstream/_scheduler/job.py +++ b/buildstream/_scheduler/job.py @@ -30,7 +30,7 @@ import multiprocessing from ruamel import yaml # BuildStream toplevel imports -from ..exceptions import _BstError +from .._exceptions import _BstError from .._message import Message, MessageType, unconditional_messages from ..plugin import _plugin_lookup from .. import _yaml, _signals, utils diff --git a/buildstream/_variables.py b/buildstream/_variables.py index dfbd8ff04..15e5ecac1 100644 --- a/buildstream/_variables.py +++ b/buildstream/_variables.py @@ -20,7 +20,7 @@ import re -from . import LoadError, LoadErrorReason +from ._exceptions import LoadError, LoadErrorReason from . import _yaml # Variables are allowed to have dashes here diff --git a/buildstream/_yaml.py b/buildstream/_yaml.py index 8aa2ec714..153e744f4 100644 --- a/buildstream/_yaml.py +++ b/buildstream/_yaml.py @@ -26,7 +26,7 @@ from contextlib import ExitStack from ruamel import yaml from ruamel.yaml.representer import SafeRepresenter, RoundTripRepresenter -from . import ImplError, LoadError, LoadErrorReason +from ._exceptions import LoadError, LoadErrorReason # We store information in the loaded yaml on a DictProvenance @@ -57,7 +57,7 @@ class Provenance(): # Abstract method def clone(self): - raise ImplError("Unimplemented clone() in Provenance") + pass # pragma: nocover # A Provenance for dictionaries, these are stored in the copy of the diff --git a/buildstream/context.py b/buildstream/context.py index a644da281..81929591a 100644 --- a/buildstream/context.py +++ b/buildstream/context.py @@ -39,7 +39,7 @@ from collections import deque, Mapping from . import _site from . import _yaml from . import utils -from . import LoadError, LoadErrorReason +from ._exceptions import LoadError, LoadErrorReason from ._profile import Topics, profile_start, profile_end diff --git a/buildstream/element.py b/buildstream/element.py index 0c121cd1c..054c75667 100644 --- a/buildstream/element.py +++ b/buildstream/element.py @@ -37,8 +37,7 @@ import shutil from . import _yaml from ._variables import Variables -from .exceptions import _BstError, _ArtifactError -from . import LoadError, LoadErrorReason, ImplError +from ._exceptions import _BstError, _ArtifactError, LoadError, LoadErrorReason, ImplError from . import Plugin, Consistency from .project import BST_ARTIFACT_VERSION as BST_CORE_ARTIFACT_VERSION from . import SandboxFlags diff --git a/buildstream/plugin.py b/buildstream/plugin.py index 93bac3465..23d34ab10 100644 --- a/buildstream/plugin.py +++ b/buildstream/plugin.py @@ -77,8 +77,7 @@ from weakref import WeakValueDictionary from . import _yaml, _signals from . import utils -from . import PluginError, ImplError -from .exceptions import _BstError +from ._exceptions import PluginError, ImplError, _BstError from ._message import Message, MessageType diff --git a/buildstream/project.py b/buildstream/project.py index 66561041e..d83159711 100644 --- a/buildstream/project.py +++ b/buildstream/project.py @@ -34,7 +34,7 @@ from . import utils from . import _site from . import _yaml from ._profile import Topics, profile_start, profile_end -from . import LoadError, LoadErrorReason +from ._exceptions import LoadError, LoadErrorReason from ._options import OptionPool BST_FORMAT_VERSION = 0 diff --git a/buildstream/sandbox/_mount.py b/buildstream/sandbox/_mount.py index 472534c9e..f78d3aa3d 100644 --- a/buildstream/sandbox/_mount.py +++ b/buildstream/sandbox/_mount.py @@ -1,7 +1,7 @@ import sys from contextlib import contextmanager -from .. import SandboxError +from .._exceptions import SandboxError from .. import utils, _signals diff --git a/buildstream/sandbox/_sandboxchroot.py b/buildstream/sandbox/_sandboxchroot.py index b1c5997fa..33f991b87 100644 --- a/buildstream/sandbox/_sandboxchroot.py +++ b/buildstream/sandbox/_sandboxchroot.py @@ -27,7 +27,7 @@ import signal import subprocess from contextlib import contextmanager, ExitStack -from .. import SandboxError +from .._exceptions import SandboxError from .. import utils from .. import _signals from ._mount import Mount diff --git a/buildstream/sandbox/sandbox.py b/buildstream/sandbox/sandbox.py index 1df094c39..0dc9aa2a5 100644 --- a/buildstream/sandbox/sandbox.py +++ b/buildstream/sandbox/sandbox.py @@ -33,7 +33,7 @@ from collections import OrderedDict from contextlib import contextmanager, ExitStack from .. import utils -from .. import ImplError +from .._exceptions import ImplError from .._fuse import SafeHardlinks diff --git a/buildstream/source.py b/buildstream/source.py index bab759989..aeae41220 100644 --- a/buildstream/source.py +++ b/buildstream/source.py @@ -28,8 +28,7 @@ import shutil from contextlib import contextmanager from . import _yaml, _signals, utils -from .exceptions import _BstError -from . import ImplError, LoadError, LoadErrorReason +from ._exceptions import _BstError, ImplError, LoadError, LoadErrorReason from . import Plugin diff --git a/buildstream/utils.py b/buildstream/utils.py index 7caf107a4..637d583b0 100644 --- a/buildstream/utils.py +++ b/buildstream/utils.py @@ -38,7 +38,7 @@ import re import tempfile import pkg_resources from contextlib import contextmanager -from . import ProgramNotFoundError +from ._exceptions import ProgramNotFoundError from . import _yaml from . import _signals |