Example #1
0
def main() -> None:
    from handofcats.customize import logging_setup

    parser = argparse.ArgumentParser(
        prog="monogusa.cli",
        add_help=False,
        formatter_class=runtime._HelpFormatter,
    )
    parser.add_argument("file")
    parser.add_argument("--debug", action="store_true")
    parser.add_argument("--ignore-only", action="store_true")

    activate_logging = logging_setup(parser, debug=False)
    if "-" in sys.argv:
        i = sys.argv.index("-")
        raw_args, rest = sys.argv[1:i], sys.argv[i + 1:]
        args = parser.parse_args(raw_args)
    else:
        args, rest = parser.parse_known_args()
    activate_logging(vars(args).copy())

    m = import_module(args.file, cwd=True)

    run(
        m,
        filename=args.file,
        args=rest,
        debug=args.debug,
        ignore_only=args.ignore_only,
    )
Example #2
0
    q = m.open_writer_queue(uid)

    def _teardown2():
        q.__exit__(None, None, None)  # todo: cache exception

    atexit.register(_teardown2)
    return q.__enter__()


def consume(m: Manager, uid: str):
    with m.open_reader_queue(uid) as q:
        for item in q:
            print(os.getpid(), "<-", item)


def sample() -> None:
    """fake event stream"""
    from monogusa.cli.events import console_stream, run_stream

    examples = """\
Message, hello
Message, byebye
"""
    run_stream(console_stream(default=examples, sep=","))


if __name__ == "__main__":
    from monogusa.cli import run

    run()
Example #3
0
def hello(*, name: str) -> None:
    print(f"hello {name}")


if __name__ == "__main__":
    import sys
    from monogusa.cli import run

    run(sys.modules[__name__])
Example #4
0
import dataclasses
from monogusa import component


@dataclasses.dataclass
class Foo:
    name: str


@component
def foo() -> Foo:
    return Foo(name="foo")


def run(foo: Foo) -> None:
    print("!", foo)


if __name__ == "__main__":
    from monogusa import cli

    cli.run()