ImportFailed

class PlasmaCalcs.tools.imports.ImportFailed(modulename, additional_error_message='', *, err=None, locals=None, abbrv=None)

Bases: object

set modules which fail to import to be instances of this class;

initialize with modulename, additional_error_message.
when attempting to call or access any attribute of the ImportFailed object,
raises ImportFailedError(’. ‘.join(modulename, additional_error_message)).
Also, if DEFAULTS.IMPORT_FAILURE_WARNINGS, make warning immediately when initialized.
err: None, Exception, or str
if provided, include str(err) when raising ImportFailedError
locals: None or dict
if provided, set locals[‘__pdoc__’][modulename] = False
if abbrv provided, use abbrv instead of modulename.
Use this to tell pdoc to skip the ImportFailed instance when creating docs pages.
abbrv: None or str
if provided, set locals[‘__pdoc__’][abbrv] = False
Example:
try:
import h5netcdf
except ImportError as err:
h5netcdf = ImportFailed(‘h5netcdf’, ‘This module is required for compressing data.’, err=err)
h5netcdf.load(…) # << attempt to use h5netcdf
# if h5netcdf was imported successfully, it will work fine.
# if h5netcdf failed to import, this error will be raised:
ImportFailedError: h5netcdf. This module is required for compressing data.
The original ImportError error was: No module named ‘h5netcdf’

Methods

__call__(*args__None, **kw__None)

tells how to call self, e.g. self(...).

__getattr__(attr)

tells how to do self.attr when it would otherwise fail.

error_message()

__call__(*args__None, **kw__None)

tells how to call self, e.g. self(…). Here, raise ImportFailedError.

__getattr__(attr)

tells how to do self.attr when it would otherwise fail.

Here, raise ImportFailedError.