snapred.meta package

Subpackages

Submodules

snapred.meta.Callback module

class snapred.meta.Callback.Callback

Bases: object

Callback wrapper that defers access to a value until it’s populated.

This class uses a metaclass to automatically forward magic methods to the wrapped value, enabling transparent operations on primitive types and objects.

Attributes:

_wrapped_type: The type being wrapped (set by the factory function) _set: Whether the callback has been populated with a value _value: The wrapped value (None if not populated) _ignore: Set of attribute names that should not be forwarded

get() Any

Get the wrapped value, raising an error if not populated.

Returns:

The wrapped value

Raises:

AttributeError: If the callback has not been populated

update(value: Any) None

Populate the callback with a value.

Args:

value: The value to wrap

class snapred.meta.Callback.CallbackMeta(name: str, bases: tuple, namespace: dict, **_kwargs)

Bases: type

Metaclass that automatically generates forwarding magic methods for Callback classes.

This metaclass intercepts class creation and automatically adds magic methods that forward operations to the wrapped value. This eliminates the need for manually defining each magic method or dynamically adding them after class creation.

snapred.meta.Callback.callback(clazz: Type) Callback

Factory function that creates a new Callback instance for the given type.

This function uses a cached class creation mechanism to ensure that only one Callback class is created per wrapped type, but returns a new instance each time.

Args:

clazz: The type to wrap (e.g., int, str, Workspace)

Returns:

A new instance of a Callback class that wraps the given type

Example:
>>> count = callback(int)
>>> count.update(5)
>>> result = count + 10  # Works! Returns 15
>>> ws = callback(Workspace)
>>> ws.update(some_workspace)
>>> name = ws.name()  # Forwarded to underlying workspace
>>>
>>> # Each call returns a new instance, but same class
>>> cb1 = callback(int)
>>> cb2 = callback(int)
>>> cb1 is not cb2  # Different instances
>>> cb1.__class__ is cb2.__class__  # Same class

snapred.meta.Config module

class snapred.meta.Config.DeployEnvEnum(value)

Bases: StrEnum

NEXT = 'snapred_next'
PROD = 'snapred_prod'
QA = 'snapred_qa'
snapred.meta.Config.datasearch_directories(instrumentHome: Path) List[str]
snapred.meta.Config.deep_update(mapping: Dict[KeyType, Any], *updating_mappings: Dict[KeyType, Any]) Dict[KeyType, Any]
snapred.meta.Config.fromMantidLoggingLevel(level: str) int
snapred.meta.Config.fromPythonLoggingLevel(level: int | str) str
snapred.meta.Config.isTestEnv() bool

Check if the current environment is a test environment. This is determined by the presence of the “env” environment variable and whether it contains the string “test”.

snapred.meta.Config.merge_dicts(d1, d2)

d2 overwrites values in d1

snapred.meta.redantic module

snapred.meta.redantic.list_from_raw(type_: Any, src: str) List[BaseModel]
snapred.meta.redantic.list_to_raw(baseModelList: List[BaseModel])
snapred.meta.redantic.list_to_raw_pretty(baseModelList: List[BaseModel])
snapred.meta.redantic.parse_file_as(type_: Type[T], path: str | Path) T
snapred.meta.redantic.parse_obj_as(type_: Type[T], obj: Any) T
snapred.meta.redantic.parse_raw_as(type_: Type[T], b: str | bytes) T
snapred.meta.redantic.validate_call(func: callable)
snapred.meta.redantic.write_model(baseModel: BaseModel, path)
snapred.meta.redantic.write_model_list(baseModelList: List[BaseModel], path)
snapred.meta.redantic.write_model_list_pretty(baseModelList: List[BaseModel], path)
snapred.meta.redantic.write_model_pretty(baseModel: BaseModel, path)

Module contents