utils
Provides utility functions for use throughout the code.
ClassRegistry
Bases: ABC
, Generic[T]
A registry of Plugboard classes.
add
classmethod
Add a class to the registry.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
plugboard_class
|
type[T]
|
The class to register. |
required |
key
|
Optional[Hashable]
|
Optional; The key to register the class under. |
None
|
build
classmethod
Builds a Plugboard object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
plugboard_class
|
Hashable
|
The key corresponding to the required class. |
required |
*args
|
Any
|
Positional arguments to pass to the class constructor. |
()
|
**kwargs
|
Any
|
Keyword arguments to pass to the class constructor. |
{}
|
Returns:
Type | Description |
---|---|
T
|
An object of the required class. |
DI
Bases: BaseContainer
DI
is a dependency injection container for plugboard.
EntityIdGen
EntityIdGen generates entity ids.
id
classmethod
Returns a unique entity id.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
entity
|
Entity
|
The entity to generate an id for. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The generated id. |
is_job_id
classmethod
Checks if an id is a job id.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
id
|
str
|
The id to check. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the id is a job id. |
job_id
classmethod
Returns a unique job id.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The generated job id. |
parse
classmethod
Parses an entity id.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
id
|
str
|
The entity id to parse. |
required |
Returns:
Type | Description |
---|---|
tuple[Entity, str]
|
tuple[Entity, str]: The parsed entity and id. |
ExportMixin
AsDictMixin
provides functionality for converting objects to dict.
_convert_exportable_objs
staticmethod
Recursively converts Exportable
objects to their export
representation.
Exportable
build_actor_wrapper
Builds an actor wrapper around a class.
This is useful for handling classes that are modified at runtime, e.g. via wrapped methods, and
therefore not supported by the ray.remote
decorator.
The wrapper methods will have the same name as the original methods, but where nested in class
attributes the method names will be prefixed accordingly. The wrapper also provides a getattr
and setattr
method to access the wrapped object's properties.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cls
|
type[T]
|
The class to wrap. |
required |
Returns:
Type | Description |
---|---|
type[_ActorWrapper[T]]
|
A new class that wraps the original class and can be used as a Ray actor. |
depends_on_optional
Decorator to check for optional dependencies.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
module_name
|
str
|
The name of the module to check for. |
required |
extra
|
Optional[str]
|
Optional; The name of the extra that the module is associated with. Defaults to the module name. |
None
|
gather_except
async
Attempts to gather the given coroutines, raising any exceptions.
gen_rand_str
Generates a random string of a fixed length and character set.
With 16 chars in [a-zA-Z0-9], at 1000 ids/second it would take ~1000 years or 30T ids for >= 1% chance of at least one collision. See here for details: https://zelark.github.io/nano-id-cc/
Note: This function is not suitable for cryptographic purposes; it is intended to generate random strings for unique identifiers only.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Random fixed length string. |