Source code for construe.exceptions

"""
Top-level exceptions for handling construe errors.
"""

import re

from click import ClickException


[docs] class ConstrueError(ClickException): pass
[docs] class DownloadError(ConstrueError): pass
[docs] class UploadError(ConstrueError): pass
[docs] class DatasetsError(ConstrueError): pass
[docs] class ModelsError(ConstrueError): pass
[docs] class InferenceError(ConstrueError): pass
[docs] class BenchmarkError(ConstrueError): pass
[docs] class DeviceError(ConstrueError): def __init__(self, e): """ Expects a runtime error to parse from PyTorch """ tre = re.compile(r"^Expected one of ([\w,\s]+) device type at start of device string: ([\w\d:]+)$", re.I) # noqa match = tre.match(str(e)) if match: unknown = match.groups()[1] devices = match.groups()[0] super(DeviceError, self).__init__(( f"Cannot set pytorch device (unknown device \"{unknown}\")\n" f"Device must be one of the following:\n{devices}" )) else: super(DeviceError, self).__init__(str(e))