silf.backend.commons.util package

Submodules

silf.backend.commons.util.abc_utils module

>>> import abc
>>> class A(metaclass = abc.ABCMeta):
...     @abc.abstractmethod
...     def foo(self): pass
>>> A()
Traceback (most recent call last):
TypeError: Can't instantiate abstract class A with abstract methods foo
>>> A.__abstractmethods__=set()
>>> A() 
<....A object at 0x...>
>>> class B(object): pass
>>> B() 
<....B object at 0x...>
>>> B.__abstractmethods__={"foo"}
>>> B()
Traceback (most recent call last):
TypeError: Can't instantiate abstract class B with abstract methods foo
>>> class A(metaclass = abc.ABCMeta):
...     @abc.abstractmethod
...     def foo(self): pass
>>> from unittest.mock import patch
>>> p = patch.multiple(A, __abstractmethods__=set())
>>> p.start()
{}
>>> A() 
<....A object at 0x...>
>>> p.stop()
>>> A()
Traceback (most recent call last):
TypeError: Can't instantiate abstract class A with abstract methods foo
silf.backend.commons.util.abc_utils.patch_abc(to_patch)

silf.backend.commons.util.config module

silf.backend.commons.util.config.prepend_current_dir_to_config_file(file_name, caller_frame_offset=1)

Todo

Use proper packaging tool, and get rid of assumption that files are laying on the fs directories.

Prepends directory name of caller file_name

Parameters:
  • file_name (str) – File name ot be appended
  • caller_frame_offset (int) – Frame from which to take the dirname :default:1
Returns:

Absolute path to file

silf.backend.commons.util.config.open_configfile(*config_files)

Opens configfile.

Parameters:config_file (str) – Absolute path to open
Returns::class:SilfConfigParser
class silf.backend.commons.util.config.SilfConfigParser(*args, **kwargs)

Bases: configparser.ConfigParser

validate_mandatory_config_keys(section, required_cofig_keys)
exception silf.backend.commons.util.config.ConfigValidationError(msg='')

Bases: configparser.Error

silf.backend.commons.util.mail module

class silf.backend.commons.util.mail.BorgSender

Bases: object

This is a borg class containing e-mail sender for currenly tunning expeirment we have to have global state containing e-mail sender because without it confguiring logging by ini file would be hard.

borg = {}
set_sender(sender)
class silf.backend.commons.util.mail.EmailSender(config)

Bases: object

Class that sends e-mails with errors to experiment admins.

email_throttling_dict = None

A dictionary that maps tracebak to time when exception with this traceback was sent last time.

install_error_function()
send_current_exception_to_admins(message=None, subject=None, excinfo=None)
send_email_to_admins(body, subject=None)
should_send_exception(traceback)
class silf.backend.commons.util.mail.ExceptionHandler(level=40)

Bases: logging.Handler

Sends e-mail with logging messahes

emit(record)
silf.backend.commons.util.mail.RESEND_EXCEPTION_TIMEOUT_SEC = 300.0

How long we weit between sending emails with exceptions with the same stacktrace.

silf.backend.commons.util.reflect_utils module

silf.backend.commons.util.reflect_utils.load_item_from_module(path)
silf.backend.commons.util.reflect_utils.pythonpath_entries(pythonpath_string)

silf.backend.commons.util.uniqueify module

silf.backend.commons.util.uniqueify.uniquefy_last(seq, idfun=None)
silf.backend.commons.util.uniqueify.uniqueify(seq, idfun=None)
>>> uniqueify([1, 2, 3, 1, 1, 4, 3 , 5])
[1, 2, 3, 4, 5]

Pasted from: www.peterbe.com/plog/uniqifiers-benchmark

Parameters:
  • seq (iterable) –
  • idfun
Returns:

Module contents