Source code for k1lib.bioinfo.cli._ctx

# AUTOGENERATED FILE! PLEASE DON'T EDIT
"""
All tools related to context variables. Expected to use behind the "ctx"
module name, like this::

    from k1lib.bioinfo.cli import *
    ctx.set("country", 3)

"""
from typing import Callable, Union, List, overload, Iterator, Any, Set
from k1lib.bioinfo.cli.init import BaseCli, settings, Table, T
import k1lib.bioinfo.cli as cli
import k1lib
from collections import deque
__all__ = ["Promise", "getC", "setC", "enum", "identity"]
context = dict()
[docs]class Promise: """Not intended to be used by the end user. Use :meth:`__call__` to get the actual value""" def __init__(self, ctx:str): self.ctx = ctx def __call__(self): return context[self.ctx]
[docs] @staticmethod def strip(o): """If is :class:`Promise`, then gets the value""" if isinstance(o, Promise): return o() else: return o
[docs]def setC(ctx:str, value): """Sets the context variable""" context[ctx] = value
[docs]def getC(ctx:str): """Gets the context variable""" return Promise(ctx)
[docs]class enum(BaseCli):
[docs] def __init__(self, ctx:str): """Saves the list index to context.""" super().__init__(); self.ctx = ctx
[docs] def __ror__(self, it): ctx = self.ctx for i, e in enumerate(it): context[ctx] = i; yield e
[docs]class identity(BaseCli):
[docs] def __init__(self, ctx:str): """Saves the list element to context.""" super().__init__(); self.ctx = ctx
[docs] def __ror__(self, it): ctx = self.ctx for e in it: context[ctx] = e; yield e