示例#1
0
def ok() -> None:
    import pathlib
    from egoist.generators.filekit import runtime
    from egoist.internal.netutil import find_free_port
    from discovery import get_discovery
    import util

    sentinel = util.create_sentinel_file()
    server_py = pathlib.Path(__file__).absolute().with_name("server.py")
    port = find_free_port()

    get_discovery().register("HELLO", url=f"http://127.0.0.1:{port}")

    argv = [
        sys.executable,
        server_py,
        "--port",
        str(port),
        "--host",
        "127.0.0.1",
        "--sentinel",
        sentinel,
    ]

    with util.ConnectedProcess().spawn(argv, sentinel=sentinel):
        import requests

        url = get_discovery().lookup("HELLO")
        res = requests.get(url)
        res.raise_for_status()

        with runtime.create_file() as wf:
            print(res.json(), file=wf)
示例#2
0
def ok() -> None:
    import pathlib
    from egoist.generators.filekit import runtime
    from egoist.internal.netutil import find_free_port
    import util

    sentinel = util.create_sentinel_file()
    server_py = pathlib.Path(__file__).absolute().with_name("server.py")
    port = find_free_port()
    argv = [
        sys.executable,
        server_py,
        "--port",
        str(port),
        "--host",
        "127.0.0.1",
        "--sentinel",
        sentinel,
    ]

    p = util.create_service_process(argv=argv, sentinel=sentinel)
    with p:
        import requests

        res = requests.get(f"http://localhost:{port}")
        res.raise_for_status()
        p.terminate()  # need

        with runtime.create_file() as wf:
            print(res.json(), file=wf)
示例#3
0
def byebye() -> None:
    from egoist.generators.filekit import runtime

    with runtime.create_file() as wf:
        print("byebye world", file=wf)
        print(app.registry.settings.get("xxx", "-"), file=wf)
        print(app.registry.settings.get("yyy", "-"), file=wf)
        print(app.registry.settings.get("zzz", "-"), file=wf)
示例#4
0
def byebye() -> None:
    from egoist.generators.filekit import runtime
    from egoist.runtime import get_current_context

    registry = get_current_context().registry

    with runtime.create_file() as wf:
        print("byebye world", file=wf)
        print(registry.settings.get("xxx", "-"), file=wf)
        print(registry.settings.get("zzz", "-"), file=wf)
示例#5
0
def person(*, filename: str = "person.go") -> None:
    from egoist.generators.filekit import runtime
    from egoist.exprimental.gofmtrpc import gofmt

    with runtime.create_file() as wf:
        with open(filename) as rf:
            code = rf.read()

        formatted_code = gofmt(code)
        print(formatted_code, file=wf)
示例#6
0
def hello__hello(*, filename: str = "./hello/hello.go") -> None:
    from egoist.generators.filekit import runtime
    from egoist.ext.gofmtrpc import gofmt

    with runtime.create_file() as wf:
        with open(filename) as rf:
            code = rf.read()

        formatted_code = gofmt(code)
        print(formatted_code, file=wf)
示例#7
0
def ok2() -> None:
    import requests
    from egoist.generators.filekit import runtime
    from discovery import get_discovery

    with runtime.create_file() as wf:
        url = get_discovery().lookup("HELLO")
        res = requests.get(url)
        res.raise_for_status()
        print(res.json(), file=wf)
示例#8
0
def hello__hello(*, filename: str = "./hello/hello.go") -> None:
    from egoist.generators.filekit import runtime
    from discovery import get_discovery

    with runtime.create_file() as wf:
        with get_file_opener().open(filename) as rf:
            code = rf.read()

        url = get_discovery().lookup("gofmtrpc")
        res = get_http_client().post(
            url,
            json={
                "jsonrpc": "2.0",
                "id": 1,
                "method": "format",
                "params": {
                    "code": code
                },
            },
        )
        res.raise_for_status()
        print(res.json()["result"], file=wf)
示例#9
0
def season(*, source="input/season.csv") -> None:
    import csv
    import json
    from egoist.generators.filekit import runtime

    with runtime.create_file() as wf:
        name_list = []
        ja_list = []

        with open(source) as rf:
            for row in csv.DictReader(rf):
                name_list.append(row["name"])
                ja_list.append(row["ja"])

        data = {
            "definitions": {
                "season": {
                    "type": "string",
                    "enum": name_list,
                    "x-ja-enum": ja_list
                }
            }
        }
        json.dump(data, wf, indent=2, ensure_ascii=False)
示例#10
0
def noop() -> None:
    from egoist.generators.filekit import runtime

    with runtime.create_file() as wf:
        print("noop", file=wf)
示例#11
0
def hello() -> None:
    from egoist.generators.filekit import runtime

    with runtime.create_file() as wf:
        print("hello world", file=wf)