diff --git a/polyapi/cli.py b/polyapi/cli.py index 14f21a2..ef2a2a9 100644 --- a/polyapi/cli.py +++ b/polyapi/cli.py @@ -3,8 +3,9 @@ from polyapi.utils import print_green from .config import clear_config, set_api_key_and_url -from .generate import generate, clear, save_rendered_specs +from .generate import generate, clear from .function_cli import function_add_or_update +from .rendered_spec import save_rendered_specs CLI_COMMANDS = ["setup", "generate", "function", "clear", "help", "save_rendered_specs"] diff --git a/polyapi/function_cli.py b/polyapi/function_cli.py index 0cbbb7a..9e461c3 100644 --- a/polyapi/function_cli.py +++ b/polyapi/function_cli.py @@ -13,6 +13,7 @@ from polyapi.generate import get_functions_and_parse, generate_functions from polyapi.config import get_api_key_and_url from polyapi.constants import PYTHON_TO_JSONSCHEMA_TYPE_MAP +# from polyapi.rendered_spec import update_rendered_spec from polyapi.utils import get_auth_headers, print_green, print_red, print_yellow import importlib @@ -270,6 +271,7 @@ def function_add_or_update( print(f"Function ID: {function_id}") print("Generating new custom function...", end="") functions = get_functions_and_parse(limit_ids=[function_id]) + # update_rendered_spec(functions[0]) generate_functions(functions) print_green("DONE") else: diff --git a/polyapi/generate.py b/polyapi/generate.py index de518e0..a4f429e 100644 --- a/polyapi/generate.py +++ b/polyapi/generate.py @@ -6,7 +6,6 @@ from polyapi.auth import render_auth_function from polyapi.client import render_client_function -from polyapi.execute import execute_post from polyapi.webhook import render_webhook_handle from .typedefs import PropertySpecification, SpecificationDto, VariableSpecDto @@ -157,24 +156,6 @@ def clear() -> None: print("Cleared!") -def save_rendered_specs() -> None: - specs = read_cached_specs() - # right now we just support rendered apiFunctions - api_specs = [spec for spec in specs if spec["type"] == "apiFunction"] - for spec in api_specs: - assert spec["function"] - func_str, type_defs = render_spec(spec) - data = { - "language": "python", - "apiFunctionId": spec["id"], - "signature": func_str, - "typedefs": type_defs, - } - resp = execute_post("/functions/rendered-specs", data) - print("adding", spec["context"], spec["name"]) - assert resp.status_code == 201, (resp.text, resp.status_code) - - def render_spec(spec: SpecificationDto): function_type = spec["type"] function_description = spec["description"] diff --git a/polyapi/rendered_spec.py b/polyapi/rendered_spec.py new file mode 100644 index 0000000..f5e9543 --- /dev/null +++ b/polyapi/rendered_spec.py @@ -0,0 +1,34 @@ +from typing import Dict +from polyapi.generate import read_cached_specs, render_spec +from polyapi.execute import execute_post +from polyapi.typedefs import SpecificationDto + + +def update_rendered_spec(spec: SpecificationDto): + print("Updating rendered spec...") + func_str, type_defs = render_spec(spec) + data = { + "language": "python", + "signature": func_str, + "typedefs": type_defs, + } + if spec["type"] == "apiFunction": + data["apiFunctionId"] = spec["id"] + elif spec["type"] == "serverFunction": + data["customFunctionId"] = spec["id"] + else: + raise NotImplementedError("todo") + + resp = execute_post("/functions/rendered-specs", data) + assert resp.status_code == 201, (resp.text, resp.status_code) + # this needs to run with something like `kn func run...` + + +def save_rendered_specs() -> None: + specs = read_cached_specs() + # right now we just support rendered apiFunctions + api_specs = [spec for spec in specs if spec["type"] == "apiFunction"] + for spec in api_specs: + assert spec["function"] + print("adding", spec["context"], spec["name"]) + update_rendered_spec(spec) diff --git a/pyproject.toml b/pyproject.toml index 7cff949..d77e224 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,7 +3,7 @@ requires = ["setuptools>=61.2", "wheel"] [project] name = "polyapi-python" -version = "0.2.5.dev1" +version = "0.2.5.dev2" description = "The Python Client for PolyAPI, the IPaaS by Developers for Developers" authors = [{ name = "Dan Fellin", email = "dan@polyapi.io" }] dependencies = [