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)
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)
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)
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)
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)
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)
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)
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)
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)
def noop() -> None: from egoist.generators.filekit import runtime with runtime.create_file() as wf: print("noop", file=wf)
def hello() -> None: from egoist.generators.filekit import runtime with runtime.create_file() as wf: print("hello world", file=wf)