coma.hooks.base¶
Base of hook utilities implementation.
- class HookSentinels(value)[source]¶
Type for sentinels for hooks.
- DEFAULT¶
Replace a hook marked as this with a default hook.
- SHARED¶
Replace a command-specific hook marked as this with a shared hook.
See also
- DEFAULT = HookSentinels.DEFAULT¶
Sentinel for marking a hook to either
command()orwake()as being a default hook. The runtime value of the hook will be replaced by the correspondingcomadefault.Recall that a hook can also be defined as a (recursive) sequence. Each occurrence of
DEFAULTin said sequence will be replaced by thecomadefault.
- SHARED = HookSentinels.SHARED¶
Sentinel for marking that a hook to
command()ought be be replaced at runtime with the runtime value of the corresponding hook fromwake().Recall that a hook can also be defined as a (recursive) sequence. Each occurrence of
SHAREDin said sequence will be replaced by thewake()value.SHAREDis not a legal value forwake()hooks to avoid infinite regress.
- SENTINEL = GeneralSentinel.token¶
A convenient pre-defined sentinel for general use. Unlike other sentinels in
coma,SENTINELhas no special semantic value beyond its existence as a sentinel.
- Hook¶
Base definition of a “raw”
comahook. A valid hook is typically a procedural function (modifying its input parameter in place and returningNone). However, returning an instance of the same typeTis also permitted to account for cases whereTis an immutable type. A non-Nonereturn value takes precedence: it replaces the procedural parameter is all downstream hooks in a hook pipeline. Typically,Tis a subclass ofHookData.Alias:
alias of
Callable[[T],T|None]
- HookOrSentinels¶
A
Hookor one of the valid hook sentinels:DEFAULT,SHARED, orNone.Alias:
alias of
Callable[[T],T|None] |HookSentinels|None
- AugmentedHook¶
A
HookOrSentinels, or any (recursive)Sequencethereof.Example:
parser_hook=( DEFAULT, ( SHARED, ( add_argument_factory(...), None, ), ), add_argument_factory(...), )
Alias:
alias of
Callable[[T],T|None] |HookSentinels|None|Sequence[Callable[[T],T|None] |HookSentinels|None]
- CommandName¶
The name under which to register a command with
coma. The same value is used to invoke the command on the command line. Any value allowed byargparseis allowed.
- Command¶
Any function or any class with (by default) a no-argument
run()method. Configs are inferred from the command signature. Seecommand().alias of
Callable|type
- class HookData(name: str, command: Callable | type, parameters: ParamData, persistence_manager: PersistenceManager)[source]¶
Base class for typical
Hookarguments.- name¶
The command name.
- Type:
- persistence_manager¶
The manager for serializing configs in
parameters.- Type:
- class ParserData(name: str, command: Callable | type, parameters: ParamData, persistence_manager: PersistenceManager, parser: ArgumentParser)[source]¶
The
HookDatafor parser hooks.- parser¶
The sub-parser for this
command.- Type:
- class InvocationData(name: str, command: Callable | type, parameters: ParamData, persistence_manager: PersistenceManager, known_args: Any, unknown_args: list[str], result: Any | None = None)[source]¶
The
HookDatafor all invocation hooks.- known_args¶
The
namespaceof known command line arguments. Typically, this is the first return value of parse_known_args().- Type:
- unknown_args¶
The list of unknown command line arguments. Typically, this is the second return value of parse_known_args().