pyirk._core.context

Inspection-/context-/module-lifecycle helpers extracted from :mod:pyirk.core.

The symbols defined here are import-time safe: none of them needs any module-global of core while this module is being imported. Symbols that use core module-globals (ds, the uri-stacks _uri_stack / _search_uri_stack etc.) at call time access them module-qualified via the _core module object, whose attributes are only read once the functions are actually called. This keeps the import monodirectional: core imports this module (early), this module only binds the (partially loaded) core module object plus the already-loaded keymanager submodule.

Note: the module-level bindings _uri_stack = [] and _search_uri_stack = [] intentionally remain in :mod:pyirk.core (they are the single source of truth for the active/search uri stacks). They are accessed here lazily as _core._uri_stack / _core._search_uri_stack.

Module Contents

Classes

Context

Container class for context definitions

abstract_uri_context

uri_context

Context manager for creating entities with a given uri

search_uri_context

uri Context manager for searching for entities with a given key

Functions

get_caller_frame

get_key_str_by_inspection

Retrieve the name of an entity from a code line like cm.new_var(M=p.instance_of(I9904["matrix"]))

get_mod_name_by_inspection

:param upcount: int; how many frames to go up :return:

get_mod_id_list_by_inspection

:param upcount: int; how many frames to go up at beginning upcount=2 (default) means: start int the caller frame. Example: fnc1()->fnc2()->fnc3() where fnc3 is this function, called by fnc2, which itself is called by fnc1 (the caller) :return: list of mod_id-objects (type str)

get_active_mod_uri

register_mod

start_mod

Register the uri for the _uri_stack.

end_mod

Data

__all__

API

pyirk._core.context.__all__

[‘get_caller_frame’, ‘get_key_str_by_inspection’, ‘get_mod_name_by_inspection’, ‘get_mod_id_list_by_…

pyirk._core.context.get_caller_frame(upcount: int) types.FrameType
pyirk._core.context.get_key_str_by_inspection(upcount=1) str

Retrieve the name of an entity from a code line like cm.new_var(M=p.instance_of(I9904["matrix"]))

:param upcount: int; how many frames to go up :return:

pyirk._core.context.get_mod_name_by_inspection(upcount=1)

:param upcount: int; how many frames to go up :return:

pyirk._core.context.get_mod_id_list_by_inspection(upcount=2) list

:param upcount: int; how many frames to go up at beginning upcount=2 (default) means: start int the caller frame. Example: fnc1()->fnc2()->fnc3() where fnc3 is this function, called by fnc2, which itself is called by fnc1 (the caller) :return: list of mod_id-objects (type str)

class pyirk._core.context.Context(*args, **kwargs)

Container class for context definitions

Initialization

class pyirk._core.context.abstract_uri_context(uri_stack: list, uri: str, prefix: str = None)

Initialization

__enter__()

implicitly called in the head of the with statement :return:

__exit__(exc_type, exc_val, exc_tb)
class pyirk._core.context.uri_context(uri: str, prefix: str = None)

Bases: pyirk._core.context.abstract_uri_context

Context manager for creating entities with a given uri

Initialization

class pyirk._core.context.search_uri_context(uri: str, prefix: str = None)

Bases: pyirk._core.context.abstract_uri_context

uri Context manager for searching for entities with a given key

Initialization

pyirk._core.context.get_active_mod_uri(strict: bool = True) Union[str, None]
pyirk._core.context.register_mod(uri: str, keymanager: pyirk._core.keymanager.KeyManager = None, check_uri=True, prefix=None)
pyirk._core.context.start_mod(uri)

Register the uri for the _uri_stack.

Note: between start_mod and end_mod no it is not allowed to load other irk modules

:param uri: :return:

pyirk._core.context.end_mod()