llama.classes module

Primitive base classes used throughout the pipeline.

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

class llama.classes.FileHandlerTuple(eventid, rundir, clsname)

Bases: tuple

property clsname

Alias for field number 2

property eventid

Alias for field number 0

property rundir

Alias for field number 1

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

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 the fullpaths exists, unless err is True, in which case a FileNotFoundError will be raised.

write_json(outdict)

Write outdict to all the files in self.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

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 a TypeError 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 as str 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 the required_attributes class method of all of superclasses implementing it.

class llama.classes.RiderFile(eventdir, manifest_filehandlers)

Bases: llama.classes.ManifestTuple, abc.ABC

A rider class that specifies filenames and fullpaths for a given manifest and a given rider_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) → List[str]

Get environmental variables varnames from os.environ. Log and warn the user with an OptionalFeatureWarning if the environmental variable is not set and return None; otherwise, return the value of the environmental variable.

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. If defaults are not defined, return None for each variable.

Returns

values – The values of the environmental variables specified in varnames, with each replaced by None if it is not set.

Return type

List[str]

Raises

ValueError – If defaults is not None but has a different length than varnames.

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 for FileHandler classes that provides properties with the whose names are the kwargs keys and whose return values are RiderFile instances initialized to that specific FileHandler. This implies that the values of kwargs are RiderFile subclasses.