fleche.state

Attributes

_CACHE

_METADATA

Classes

BoundWrapper

Utility class that freezes global state for the cache and metadata config.

Functions

cache(…)

Manages the active cache for Fleche. If new_cache is provided, it returns a context manager

meta(*new_metadata[, stack])

tags(**kwargs)

A context manager to add arbitrary tags to results.

project(name)

A context manager to tag results with a project name.

Module Contents

fleche.state._CACHE: contextvars.ContextVar[fleche.caches.BaseCache][source]
fleche.state.cache(new_cache: None = None, stack: bool = False) fleche.caches.BaseCache[source]
fleche.state.cache(new_cache: fleche.caches.BaseCache | str, stack: bool = False) contextlib.AbstractContextManager[None]

Manages the active cache for Fleche. If new_cache is provided, it returns a context manager that sets the cache for the duration of the context. If new_cache is None, it returns the currently active cache.

Parameters:
  • new_cache (Optional[BaseCache]) – An optional Cache object to set as the active cache.

  • stack (bool, default False) – if True, construct a CacheStack, with new_cache at the bottom

Returns:

The current cache object if new_cache is None, otherwise a context manager to set a new cache.

Return type:

Union[BaseCache, AbstractContextManager[None]]

fleche.state._METADATA: contextvars.ContextVar[tuple[fleche.metadata.MetaData, Ellipsis]][source]
fleche.state.meta(*new_metadata: fleche.metadata.MetaData, stack=False)[source]
fleche.state.tags(**kwargs)[source]

A context manager to add arbitrary tags to results.

Parameters:

**kwargs – The tags to add to the results.

fleche.state.project(name)[source]

A context manager to tag results with a project name.

Parameters:

name (str) – The name of the project.

class fleche.state.BoundWrapper[source]

Utility class that freezes global state for the cache and metadata config.

Essentially acts like an early binding closure.

This is intended to enable passing around fleche-decorated functions in pickled form by baking in the state into the pickle on request.

func: Callable[source]
cache: fleche.caches.BaseCache[source]
meta: tuple[fleche.metadata.MetaData, Ellipsis][source]
classmethod bind(func)[source]

Bind cache and metadata state.

Returns a new callable that will behave always as if run under the context under which bind() was originally called.

Parameters:

func (callable) – any callable; plain functions that only call fleche-wrapped ones are explicitly allowed

Returns:

instance with the bound cache and metadata state

Return type:

BoundWrapper

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