Wrapper :code:`__init__` function in algo.
(
algo, program_model, pyx_header, pyx_body, vd_type, md_type, pregel_combine
)
| 27 | |
| 28 | |
| 29 | def wrap_init( |
| 30 | algo, program_model, pyx_header, pyx_body, vd_type, md_type, pregel_combine |
| 31 | ): |
| 32 | """Wrapper :code:`__init__` function in algo.""" |
| 33 | algo_name = getattr(algo, "__name__") |
| 34 | module_name = algo_name + "_" + get_timestamp(with_milliseconds=False) |
| 35 | |
| 36 | pyx_code = "\n\n".join(pyx_header.dump() + pyx_body.dump()) |
| 37 | gs_config = { |
| 38 | "app": [ |
| 39 | { |
| 40 | "algo": module_name, |
| 41 | "context_type": "labeled_vertex_data", |
| 42 | "type": ( |
| 43 | "cython_pie" |
| 44 | if program_model == ProgramModel.PIE |
| 45 | else "cython_pregel" |
| 46 | ), |
| 47 | "class_name": "gs::PregelPropertyAppBase", |
| 48 | "compatible_graph": ["vineyard::ArrowFragment"], |
| 49 | "vd_type": vd_type, |
| 50 | "md_type": md_type, |
| 51 | "pregel_combine": pregel_combine, |
| 52 | } |
| 53 | ] |
| 54 | } |
| 55 | |
| 56 | garfile = InMemoryZip() |
| 57 | garfile.append("{}.pyx".format(module_name), pyx_code) |
| 58 | garfile.append(".gs_conf.yaml", yaml.dump(gs_config)) |
| 59 | |
| 60 | def init(self): |
| 61 | pass |
| 62 | |
| 63 | def call(self, graph, **kwargs): |
| 64 | app_assets = load_app(gar=garfile.read_bytes(), algo=module_name) |
| 65 | return app_assets(graph, **kwargs) |
| 66 | |
| 67 | setattr(algo, "__decorated__", True) # can't decorate on a decorated class |
| 68 | setattr(algo, "_gar", garfile.read_bytes().getvalue()) |
| 69 | setattr(algo, "__init__", init) |
| 70 | setattr(algo, "__call__", call) |
| 71 | |
| 72 | |
| 73 | def pyx_codegen( |
no test coverage detected