Skip to content

globalconfig

Module dealing with the lifecycle of the global RootConfig object

check_can_modify(cfg)

Check if this root config object can be modified.

As specified, the global root config object can only be modified by the thread that first created it.

Source code in gamma/config/globalconfig.py
def check_can_modify(cfg: RootConfig) -> None:
    """Check if this root config object can be modified.

    As specified, the **global** root config object can only be modified by the thread
    that first created it.
    """

    if _global_store.root is cfg:
        _global_store.check_can_modify()

get_config(initialize=True)

Get the global config root object, loading if needed and initialize is True.

This global object is cached and safe to call multiple times, from multiple threads.

Source code in gamma/config/globalconfig.py
def get_config(initialize: bool = True) -> Optional[RootConfig]:
    """Get the global config root object, loading if needed and `initialize` is `True`.

    This global object is cached and safe to call multiple times, from multiple
    threads.
    """
    if _global_store.empty() and not initialize:
        return None
    elif _global_store.empty() and initialize:
        meta = load_meta()
        entries = sorted(get_entries())
        root = RootConfig(meta=meta)
        for entry_key, entry in entries:
            node = load_node(entry)
            if node:
                push_entry(root, entry_key, node)

        _global_store.set(root)
    return _global_store.get()

reset_config(force=False)

Clear the global store and cache.

This is not meant to be used extensively by applications, but can be useful for writing tests.

Parameters:

Name Type Description Default
force bool

if True, will reset the global store regardless of the current thread/process.

False
Source code in gamma/config/globalconfig.py
def reset_config(force: bool = False) -> None:
    """Clear the global store and cache.

    This is not meant to be used extensively by applications, but can be useful for
    writing tests.

    Args:
        force: if True, will reset the global store regardless of the current
            thread/process.
    """

    _global_store.reset(force=force)
    cache.clear()

set_config(cfg)

Forces a root config.

Call reset_config.

NOTE: This is not meant to be used regularly by applications, but can be useful when writing tests.

Source code in gamma/config/globalconfig.py
def set_config(cfg: RootConfig) -> None:
    """Forces a root config.

    Call `reset_config`.

    NOTE: This is not meant to be used regularly by applications, but can be useful
    when writing tests.
    """
    reset_config()
    _global_store.set(cfg)