llama.classes module¶
Primitive base classes used throughout the pipeline.
-
class
llama.classes.
AbstractFileHandler
¶ Bases:
llama.classes.FileHandlerTuple
,abc.ABC
An abstract
FileHandler
class defining a partialFileHandler
interface.-
abstract
generate
(*args, **kwargs)¶ Generate a file safely.
-
abstract
-
class
llama.classes.
Colors
(BLUE, RED, GREEN, MAGENTA, YELLOW, CLEAR, BOLD, UNDERLINE, blue, red, green, magenta, yellow, bold, underline)¶ Bases:
tuple
-
property
BLUE
¶ Alias for field number 0
-
property
BOLD
¶ Alias for field number 6
-
property
CLEAR
¶ Alias for field number 5
-
property
GREEN
¶ Alias for field number 2
-
property
MAGENTA
¶ Alias for field number 3
-
property
RED
¶ Alias for field number 1
-
property
UNDERLINE
¶ Alias for field number 7
-
property
YELLOW
¶ Alias for field number 4
-
property
blue
¶ Alias for field number 8
-
property
bold
¶ Alias for field number 13
-
property
green
¶ Alias for field number 10
-
property
magenta
¶ Alias for field number 11
-
property
red
¶ Alias for field number 9
-
property
underline
¶ Alias for field number 14
-
property
yellow
¶ Alias for field number 12
-
property
-
exception
llama.classes.
CoolDownException
¶ Bases:
llama.classes.GenerationError
A
FileHandler
is currently cooling down after a failed generation attempt and should be left alone for now.
-
class
llama.classes.
EnvVarRegistry
¶ Bases:
object
Register environmental variables used by the pipeline in a thread safe way for help documentation.
-
classmethod
print_and_quit
()¶ Print the list of registered environmental variables and exit.
-
classmethod
register
(varnames: List[str], errmsg: str, values: List[str], module: str, loaded: bool) → None¶ Register the result of a call to
optional_env_var
.
-
classmethod
-
class
llama.classes.
FileHandlerTuple
(eventid, rundir, parent, clsname)¶ Bases:
tuple
-
property
clsname
¶ Alias for field number 3
-
property
eventid
¶ Alias for field number 0
-
property
parent
¶ Alias for field number 2
-
property
rundir
¶ Alias for field number 1
-
property
-
exception
llama.classes.
GenerationError
¶ Bases:
OSError
An error meant to indicate that a given file could not be generated at the time its generate() method was called due to missing
DEPENDENCIES
(or some other benign failure mode). This error should be thrown when behavior is otherwise nominal as an indication that a particular file simply could not be generated at a particular moment in time.
-
class
llama.classes.
Hdf5Storage
(filename)¶ Bases:
object
A class for reading and writing to an HDF5 cache. Has a dictionary interface and abstracts away file opening and closing.
-
class
llama.classes.
ImmutableDict
¶ Bases:
frozenset
A hashable, immutable namespace inspired by
namedtuple
. Initialize by passing a dict or an iterable of(key, value)
tuples. Attributes are accessible using dot notation or the map interface.-
get
(k[, d]) → D[k] if k in D, else d. d defaults to None.¶
-
items
()¶ D.iteritems() -> an iterator over the (key, value) items of D
-
keys
()¶ D.iterkeys() -> an iterator over the keys of D
-
values
()¶ D.itervalues() -> an iterator over the values of D
-
-
exception
llama.classes.
IntentException
¶ Bases:
llama.classes.GenerationError
A
FileHandler
is currently being generated and should be left alone for now.
-
class
llama.classes.
JsonRiderMixin
¶ Bases:
object
Class for reading and writing JSON to multiple rider files in a manifest.
-
read_json
(err=False)¶ Returns
None
if none of thefullpaths
exists, unlesserr
isTrue
, in which case aFileNotFoundError
will be raised.
-
write_json
(outdict)¶ Write
outdict
to all the files inself.fullpaths
.
-
-
class
llama.classes.
ManifestTuple
(eventdir, manifest_filehandlers)¶ Bases:
tuple
-
property
eventdir
¶ Alias for field number 0
-
property
manifest_filehandlers
¶ Alias for field number 1
-
property
-
llama.classes.
MetaClassFactory
(function, meth_names=None)¶ Create a MetaClass that wraps all methods in
function
. Use it by setting__metaclass__ = <your new class
when declaring a class whose methods should be wrapped thus.- Parameters
function (func) – The function that should wrap each method of a class.
meth_names (list, optional) – If provided, only wrap these methods. Otherwise, wrap all methods.
- Raises
TypeError – If
meth_names
is provided, all of the specified strings must refer to functions in the class to be created, otherwise aTypeError
will be raised.
-
class
llama.classes.
NamespaceMappable
¶ Bases:
abc.ABC
A mappable class implementing a dot-notation for accessing members.
-
exception
llama.classes.
OptionalFeatureWarning
¶ Bases:
UserWarning
A warning indicating that an optional feature will not be available. You will usually want to suppress this (except when running tests, evaluating the status of a fresh install/upgrade, or debugging).
-
class
llama.classes.
RequiredAttributeMixin
¶ Bases:
object
Class with a
required_attributes
classmethod that finds all_REQUIRED
attributes for itself and all superclasses. Use this feature to check whether subclasses have implemented all required attributes from their abstract superclasses.To add new required attributes, specify a
_REQUIRED
tuple listing the names of those attributes asstr
instances. If your superclasses already define other required attributes thus, there is no need to reinclude them in the new class’s_REQUIRED
tuple.-
classmethod
required_attributes
()¶ Recursively fetch a set of required attributes for this class based on its
_REQUIRED
attribute as well as therequired_attributes
class method of all of superclasses implementing it.
-
classmethod
-
class
llama.classes.
RiderFile
(eventdir, manifest_filehandlers)¶ Bases:
llama.classes.ManifestTuple
,abc.ABC
A rider class that specifies
filenames
andfullpaths
for a given manifest and a givenrider_fmt
.-
delete
()¶ Delete all rider files associated with this manifest.
-
exists
()¶ Check whether any of the rider files in this manifest exist.
-
property
filenames
¶ Get the name of the file indicating the cooldown status of this file.
-
property
fullpaths
¶ Get the full path of the file indicating the cooldown status of this file.
-
abstract property
rider_fmt
¶ The format string for this rider file. Must be implemented by subclasses as a property or attribute.
-
-
llama.classes.
optional_env_var
(varnames: List[str], errmsg: str = '', defaults: List[str] = None, register: bool = True) → List[str]¶ Get environmental variables
varnames
fromos.environ
. Log and warn the user with anOptionalFeatureWarning
if the environmental variable is not set and returnNone
; otherwise, return the value of the environmental variable. Registers the list of environmental variables to a central list.- Parameters
varnames (List[str]) – A list of environmental variables to import.
errmsg (str, optional) – A descriptive message to display in logs and warnings if the user has not configured the specified environmental variable. This will be printed in addition to a default message explaining which environmental variables were not available and which module tried to define them.
defaults (List[str]) – A list of default values corresponding to
varnames
. If any of the variables are not defined, raise the warning and use defaults. Ifdefaults
are not defined, returnNone
for each variable.register (bool, optional) – Whether to register the environmental variable change with
EnvVarRegistry
(which will allow its use to be printed at the command line when requesting help).
- Returns
values – The values of the environmental variables specified in
varnames
, with each replaced byNone
if it is not set.- Return type
List[str]
- Raises
ValueError – If
defaults
is not None but has a different length thanvarnames
.
-
llama.classes.
placeholderclass
(name, modulename, bases=<class 'object'>)¶ Define and return a placeholder class that raises a
NotImplementedError
on instantiation.- Parameters
name (str) – The name of the new class.
modulename (str) – The name of the module you would like to import from.
bases (tuple) – The base classes of the new placeholder class.
- Returns
newclass – A placeholder class that immediately raises a
NotImplementedError
when you try to instantiate it.- Return type
type
-
llama.classes.
registerstub
(name, modulename, stub)¶ Register a stub object. Just a way to keep track of when partial implementations of objects have been defined as replacements for modules that cannot be imported for whatever reason (since these stub objects might not provide perfect/full functionality of the missing modules).
- Parameters
name (str) – The variable name of the stub object.
modulename (str) – The name of the module where it is defined; you should probably set this to
__name__
to get the name of the defining scope for the stub.stub (function or type) – The stub object itself.
-
llama.classes.
rider_mixin_factory
(classname, **kwargs)¶ Get a Mixin with name
classname
forFileHandler
classes that provides properties with the whose names are thekwargs
keys and whose return values areRiderFile
instances initialized to that specificFileHandler
. This implies that the values ofkwargs
areRiderFile
subclasses.