Utilities

Package-wide useful routines

class orion.core.utils.Factory(name, bases, namespace, **kwargs)[source]

Deprecated, will be removed in v0.3.0. See GenericFactory instead

Methods

__call__(of_type, *args, **kwargs)

Create an object, instance of cls.__base__, on first call.

__call__(of_type, *args, **kwargs)[source]

Create an object, instance of cls.__base__, on first call.

class orion.core.utils.GenericFactory(base: type[T])[source]

Factory to create instances of classes inheriting a given base class.

The factory can instantiate children of the base class at any level of inheritance. The children class must have different names (capitalization insensitive). To instantiate objects with the factory, use factory.create('name_of_the_children_class') passing the name of the children class to instantiate.

To support classes even when they are not imported, register them in the entry_points of the package’s setup.py. The factory will import all registered classes in the entry_points before looking for available children to create new objects.

Parameters
base: class

Base class of all children that the factory can instantiate.

Methods

create(of_type, *args, **kwargs)

Create an object, instance of self.base

get_class(of_type)

Get the class object (not instantiated)

get_classes()

Get children classes of self.base

create(of_type: str, *args, **kwargs)[source]

Create an object, instance of self.base

Parameters
of_type: str

Name of class, subclass of self.base. Capitalization insensitive

args: *

Positional arguments to construct the given class.

kwargs: **

Keyword arguments to construct the given class.

get_class(of_type: str) type[T][source]

Get the class object (not instantiated)

Parameters
of_type: str

Name of class, subclass of self.base. Capitalization insensitive

get_classes() dict[str, type[T]][source]

Get children classes of self.base

orion.core.utils.compute_identity(size: int = 16, **sample) str[source]

Compute a unique hash out of a dictionary

Parameters
size: int

size of the unique hash

**sample:

Dictionary to compute the hash from

orion.core.utils.float_to_digits_list(number)[source]

Convert a float into a list of digits, without conserving exponent

orion.core.utils.get_all_subclasses(parent)[source]

Get set of subclasses recursively

orion.core.utils.get_all_types(parent_cls, cls_name)[source]

Get all subclasses and lowercase subclass names

orion.core.utils.nesteddict()[source]

Define type of arbitrary nested defaultdicts Extend defaultdict to arbitrary nested levels.

orion.core.utils.sigterm_as_interrupt()[source]

Intercept SIGTERM signals and raise KeyboardInterrupt instead