ekit package

Submodules

ekit.context module

ekit.context.setup_context(ctx_in=None, allowed=[], types=[], defaults=[], remove_unknowns=False, verbosity=3, verbose=None, logger=None)[source]

Sets up a context in the form a dictionary.

Parameters
  • ctx_in – If it is a directory containing keys corresponding to parameter names defined in allowed they will be used. If it is a valid path the file is assumed to be in YAML format and the parameters are read from it.

  • allowed – A list of the parameter names that are allowed in the context.

  • types – A list of the data types required for the parameters.

  • defaults – A list of the default values of the parameters (used if no other values found).

  • remove_unknowns – If True then parameters that are in ctx_in but not in allowed are not in the returned context.

  • verbosity – Verbosity level (0 - 4).

  • verbose – Only for backwards compatibility. Not used.

  • logger – Only for backwards compatibility. Not used.

Returns

A directory containing all the parameter names and their assigned values.

ekit.logger module

class ekit.logger.CustomFormatter(colorized=True)[source]

Bases: logging.Formatter

Class to handle customization of logger output format.

format(record)[source]

Format the specified record as text.

The record’s attribute dictionary is used as the operand to a string formatting operation which yields the returned string. Before formatting the dictionary, a couple of preparatory steps are carried out. The message attribute of the record is computed using LogRecord.getMessage(). If the formatting string uses the time (as determined by a call to usesTime(), formatTime() is called to format the event time. If there is exception information, it is formatted using formatException() and appended to the message.

ekit.logger.init_logger(name, logging_level=3, colorized=True)[source]

Initializes a logger instance for a file. :param name: The name of the file for which the logging is done. :param colorized: If True uses coloring of logger messages. :return: Logger instance

ekit.logger.set_logger_level(logger, level)[source]

Sets the global logging level. Meassages with a logging level below will not be logged.

Parameters
  • logger – A logger instance.

  • logging_level – The logger severity (critical, error, warning, info or debug)

ekit.logger.vprint(message, logger=None, verbose=False, level='info')[source]

DEPRECATED. Only for backward compatibility Prints a message if verbose is True. Can also redirect output to a logger instance.

Parameters
  • message – The message string to print.

  • logger – Either a logger instance or None

  • verbose – If True prints the message

  • level – The severity level of the message (either info, warning, error or debug)

ekit.paths module

ekit.paths.create_path(identity, out_folder=None, defined_parameters={}, undefined_parameters=[], suffix='', verbosity=3)[source]

Creates a standardised path for files. The meta data is encoded in the path and can be savely recovered using the get_parameters_from_path function. NOTE: Your variable names must not contain underscores or equal signs!

Parameters
  • identity – The prefix of the name.

  • out_folder – The directory of the file.

  • defined_parameters – A dictionary of key value pairs.

  • undefined_parameters – A list of parameters that do not have a name (be mindful about their order when reading them from the name again!).

  • suffix – What should go at the end of the name.

  • verbosity – Verbosity level (0 - 4).

Returns

A string which is the created path.

ekit.paths.get_parameters_from_path(paths, suffix=True, fmt=None, verbosity=3)[source]

Given a list of standardised paths, or a single path created with create_path() this function reads the parameters in the paths.

Parameters
  • paths – Either a single string or a list of strings. The strings should be paths in the create_path() format.

  • suffix – If True assumes that the given paths have suffixes

  • fmt – Format string in format: %s_%i_%b etc. The order is the same as the attributes that should be read from the path. Accepts: %s = string, %i = integer, %f = float, %b = boolean

  • verbosity – Verbosity level (0 - 4).

Returns

Returns a dictionary which contains the defined parameters and a list containing the undefined parameters.

ekit.paths.mkdir_on_demand(path, exist_ok=True, parents=True, verbosity=3)[source]

Creates a directory if it does not exist. Just a wrapper around pathlib but kept for backwards compatibility.

Parameters
  • path – The path to the directory that should be created.

  • exist_ok – If set to True ignores errors raised if

directory already exists. :param parents: If True creates full directory tree. :param verbosity: Verbosity level (0 - 4).

Module contents