polyapi-python 0.2.6.dev1__tar.gz → 0.2.7__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {polyapi_python-0.2.6.dev1/polyapi_python.egg-info → polyapi_python-0.2.7}/PKG-INFO +1 -1
- {polyapi_python-0.2.6.dev1 → polyapi_python-0.2.7}/polyapi/api.py +2 -2
- {polyapi_python-0.2.6.dev1 → polyapi_python-0.2.7}/polyapi/cli.py +7 -4
- {polyapi_python-0.2.6.dev1 → polyapi_python-0.2.7}/polyapi/client.py +1 -1
- {polyapi_python-0.2.6.dev1 → polyapi_python-0.2.7}/polyapi/function_cli.py +29 -1
- {polyapi_python-0.2.6.dev1 → polyapi_python-0.2.7}/polyapi/rendered_spec.py +8 -13
- {polyapi_python-0.2.6.dev1 → polyapi_python-0.2.7}/polyapi/schema.py +0 -14
- {polyapi_python-0.2.6.dev1 → polyapi_python-0.2.7}/polyapi/server.py +2 -2
- {polyapi_python-0.2.6.dev1 → polyapi_python-0.2.7}/polyapi/utils.py +16 -5
- {polyapi_python-0.2.6.dev1 → polyapi_python-0.2.7/polyapi_python.egg-info}/PKG-INFO +1 -1
- {polyapi_python-0.2.6.dev1 → polyapi_python-0.2.7}/pyproject.toml +1 -1
- {polyapi_python-0.2.6.dev1 → polyapi_python-0.2.7}/tests/test_rendered_spec.py +2 -2
- {polyapi_python-0.2.6.dev1 → polyapi_python-0.2.7}/tests/test_utils.py +5 -8
- {polyapi_python-0.2.6.dev1 → polyapi_python-0.2.7}/LICENSE +0 -0
- {polyapi_python-0.2.6.dev1 → polyapi_python-0.2.7}/README.md +0 -0
- {polyapi_python-0.2.6.dev1 → polyapi_python-0.2.7}/polyapi/__init__.py +0 -0
- {polyapi_python-0.2.6.dev1 → polyapi_python-0.2.7}/polyapi/__main__.py +0 -0
- {polyapi_python-0.2.6.dev1 → polyapi_python-0.2.7}/polyapi/auth.py +0 -0
- {polyapi_python-0.2.6.dev1 → polyapi_python-0.2.7}/polyapi/config.py +0 -0
- {polyapi_python-0.2.6.dev1 → polyapi_python-0.2.7}/polyapi/constants.py +0 -0
- {polyapi_python-0.2.6.dev1 → polyapi_python-0.2.7}/polyapi/error_handler.py +0 -0
- {polyapi_python-0.2.6.dev1 → polyapi_python-0.2.7}/polyapi/exceptions.py +0 -0
- {polyapi_python-0.2.6.dev1 → polyapi_python-0.2.7}/polyapi/execute.py +0 -0
- {polyapi_python-0.2.6.dev1 → polyapi_python-0.2.7}/polyapi/generate.py +0 -0
- {polyapi_python-0.2.6.dev1 → polyapi_python-0.2.7}/polyapi/py.typed +0 -0
- {polyapi_python-0.2.6.dev1 → polyapi_python-0.2.7}/polyapi/typedefs.py +0 -0
- {polyapi_python-0.2.6.dev1 → polyapi_python-0.2.7}/polyapi/variables.py +0 -0
- {polyapi_python-0.2.6.dev1 → polyapi_python-0.2.7}/polyapi/webhook.py +0 -0
- {polyapi_python-0.2.6.dev1 → polyapi_python-0.2.7}/polyapi_python.egg-info/SOURCES.txt +0 -0
- {polyapi_python-0.2.6.dev1 → polyapi_python-0.2.7}/polyapi_python.egg-info/dependency_links.txt +0 -0
- {polyapi_python-0.2.6.dev1 → polyapi_python-0.2.7}/polyapi_python.egg-info/requires.txt +0 -0
- {polyapi_python-0.2.6.dev1 → polyapi_python-0.2.7}/polyapi_python.egg-info/top_level.txt +0 -0
- {polyapi_python-0.2.6.dev1 → polyapi_python-0.2.7}/setup.cfg +0 -0
- {polyapi_python-0.2.6.dev1 → polyapi_python-0.2.7}/tests/test_api.py +0 -0
- {polyapi_python-0.2.6.dev1 → polyapi_python-0.2.7}/tests/test_auth.py +0 -0
- {polyapi_python-0.2.6.dev1 → polyapi_python-0.2.7}/tests/test_function_cli.py +0 -0
- {polyapi_python-0.2.6.dev1 → polyapi_python-0.2.7}/tests/test_schema.py +0 -0
- {polyapi_python-0.2.6.dev1 → polyapi_python-0.2.7}/tests/test_server.py +0 -0
- {polyapi_python-0.2.6.dev1 → polyapi_python-0.2.7}/tests/test_variables.py +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
from typing import Any, Dict, List, Tuple
|
|
2
2
|
|
|
3
3
|
from polyapi.typedefs import PropertySpecification
|
|
4
|
-
from polyapi.utils import add_type_import_path,
|
|
4
|
+
from polyapi.utils import add_type_import_path, parse_arguments, get_type_and_def, rewrite_arg_name
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
API_DEFS_TEMPLATE = """
|
|
@@ -41,7 +41,7 @@ def render_api_function(
|
|
|
41
41
|
arg_names = [a["name"] for a in arguments]
|
|
42
42
|
args, args_def = parse_arguments(function_name, arguments)
|
|
43
43
|
return_type_name, return_type_def = get_type_and_def(return_type) # type: ignore
|
|
44
|
-
data = "{" + ", ".join([f"'{arg}': {
|
|
44
|
+
data = "{" + ", ".join([f"'{arg}': {rewrite_arg_name(arg)}" for arg in arg_names]) + "}"
|
|
45
45
|
|
|
46
46
|
api_response_type = f"{function_name}Response"
|
|
47
47
|
func_type_defs = API_DEFS_TEMPLATE.format(
|
|
@@ -4,7 +4,7 @@ from polyapi.utils import print_green
|
|
|
4
4
|
|
|
5
5
|
from .config import clear_config, set_api_key_and_url
|
|
6
6
|
from .generate import generate, clear
|
|
7
|
-
from .function_cli import function_add_or_update
|
|
7
|
+
from .function_cli import function_add_or_update, function_execute
|
|
8
8
|
from .rendered_spec import get_and_update_rendered_spec
|
|
9
9
|
|
|
10
10
|
|
|
@@ -45,8 +45,8 @@ def execute_from_cli() -> None:
|
|
|
45
45
|
clear_config()
|
|
46
46
|
generate()
|
|
47
47
|
elif command == "update_rendered_spec":
|
|
48
|
-
assert len(args.subcommands) ==
|
|
49
|
-
updated = get_and_update_rendered_spec(args.subcommands[0]
|
|
48
|
+
assert len(args.subcommands) == 1
|
|
49
|
+
updated = get_and_update_rendered_spec(args.subcommands[0])
|
|
50
50
|
if updated:
|
|
51
51
|
print("Updated rendered spec!")
|
|
52
52
|
else:
|
|
@@ -56,4 +56,7 @@ def execute_from_cli() -> None:
|
|
|
56
56
|
print("Clearing the generated library...")
|
|
57
57
|
clear()
|
|
58
58
|
elif command == "function":
|
|
59
|
-
|
|
59
|
+
if args.subcommands[0] == "execute":
|
|
60
|
+
print(function_execute(args.context, args.subcommands))
|
|
61
|
+
else:
|
|
62
|
+
function_add_or_update(args.context, args.description, args.client, args.server, args.logs, args.subcommands, not args.skip_generate)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
from typing import Any, Dict, List, Tuple
|
|
2
2
|
|
|
3
3
|
from polyapi.typedefs import PropertySpecification
|
|
4
|
-
from polyapi.utils import
|
|
4
|
+
from polyapi.utils import parse_arguments, get_type_and_def
|
|
5
5
|
|
|
6
6
|
DEFS_TEMPLATE = """
|
|
7
7
|
from typing import List, Dict, Any, TypedDict
|
|
@@ -3,7 +3,7 @@ import argparse
|
|
|
3
3
|
import json
|
|
4
4
|
import types
|
|
5
5
|
import sys
|
|
6
|
-
from typing import Dict, List, Mapping, Optional, Tuple
|
|
6
|
+
from typing import Any, Dict, List, Mapping, Optional, Tuple
|
|
7
7
|
from typing import _TypedDictMeta as BaseTypedDict # type: ignore
|
|
8
8
|
from typing_extensions import _TypedDictMeta # type: ignore
|
|
9
9
|
import requests
|
|
@@ -279,3 +279,31 @@ def function_add_or_update(
|
|
|
279
279
|
print(resp.status_code)
|
|
280
280
|
print(resp.content)
|
|
281
281
|
sys.exit(1)
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
def function_execute(context: str, subcommands: List) -> Any:
|
|
285
|
+
assert subcommands[0] == "execute"
|
|
286
|
+
context_code = importlib.import_module(f"polyapi.poly.{context}")
|
|
287
|
+
print(f"Executing poly.{context}.{subcommands[1]}... ")
|
|
288
|
+
fn = getattr(context_code, subcommands[1])
|
|
289
|
+
return fn(*subcommands[2:])
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
def spec_delete(function_type: str, function_id: str):
|
|
293
|
+
api_key, api_url = get_api_key_and_url()
|
|
294
|
+
assert api_key
|
|
295
|
+
if function_type == "api":
|
|
296
|
+
url = f"{api_url}/functions/api/{function_id}"
|
|
297
|
+
elif function_type == "serverFunction":
|
|
298
|
+
url = f"{api_url}/functions/server/{function_id}"
|
|
299
|
+
elif function_type == "customFunction":
|
|
300
|
+
url = f"{api_url}/functions/client/{function_id}"
|
|
301
|
+
elif function_type == "webhookHandle":
|
|
302
|
+
url = f"{api_url}/webhooks/{function_id}"
|
|
303
|
+
else:
|
|
304
|
+
print_red("ERROR")
|
|
305
|
+
print(f"Unknown function type: {function_type}")
|
|
306
|
+
sys.exit(1)
|
|
307
|
+
headers = get_auth_headers(api_key)
|
|
308
|
+
resp = requests.delete(url, headers=headers)
|
|
309
|
+
return resp
|
|
@@ -7,7 +7,7 @@ from polyapi.generate import read_cached_specs, render_spec
|
|
|
7
7
|
from polyapi.typedefs import SpecificationDto
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
def update_rendered_spec(
|
|
10
|
+
def update_rendered_spec(spec: SpecificationDto):
|
|
11
11
|
print("Updating rendered spec...")
|
|
12
12
|
func_str, type_defs = render_spec(spec)
|
|
13
13
|
data = {
|
|
@@ -27,9 +27,7 @@ def update_rendered_spec(api_key: str, spec: SpecificationDto):
|
|
|
27
27
|
raise NotImplementedError("todo")
|
|
28
28
|
|
|
29
29
|
# use super key on develop-k8s here!
|
|
30
|
-
|
|
31
|
-
if not base_url:
|
|
32
|
-
base_url = os.environ.get("HOST_URL")
|
|
30
|
+
api_key, base_url = get_api_key_and_url()
|
|
33
31
|
|
|
34
32
|
url = f"{base_url}/functions/rendered-specs"
|
|
35
33
|
headers = {"Authorization": f"Bearer {api_key}"}
|
|
@@ -37,11 +35,8 @@ def update_rendered_spec(api_key: str, spec: SpecificationDto):
|
|
|
37
35
|
assert resp.status_code == 201, (resp.text, resp.status_code)
|
|
38
36
|
|
|
39
37
|
|
|
40
|
-
def _get_spec(
|
|
41
|
-
|
|
42
|
-
if not base_url:
|
|
43
|
-
base_url = os.environ.get("HOST_URL")
|
|
44
|
-
|
|
38
|
+
def _get_spec(spec_id: str) -> Optional[SpecificationDto]:
|
|
39
|
+
api_key, base_url = get_api_key_and_url()
|
|
45
40
|
url = f"{base_url}/specs"
|
|
46
41
|
headers = {"Authorization": f"Bearer {api_key}"}
|
|
47
42
|
resp = requests.get(url, headers=headers)
|
|
@@ -55,10 +50,10 @@ def _get_spec(api_key: str, spec_id: str) -> Optional[SpecificationDto]:
|
|
|
55
50
|
raise NotImplementedError(resp.content)
|
|
56
51
|
|
|
57
52
|
|
|
58
|
-
def get_and_update_rendered_spec(
|
|
59
|
-
spec = _get_spec(
|
|
53
|
+
def get_and_update_rendered_spec(spec_id: str) -> bool:
|
|
54
|
+
spec = _get_spec(spec_id)
|
|
60
55
|
if spec:
|
|
61
|
-
update_rendered_spec(
|
|
56
|
+
update_rendered_spec(spec)
|
|
62
57
|
return True
|
|
63
58
|
return False
|
|
64
59
|
|
|
@@ -70,4 +65,4 @@ def save_rendered_specs() -> None:
|
|
|
70
65
|
for spec in api_specs:
|
|
71
66
|
assert spec["function"]
|
|
72
67
|
print("adding", spec["context"], spec["name"])
|
|
73
|
-
update_rendered_spec(
|
|
68
|
+
update_rendered_spec(spec)
|
|
@@ -77,20 +77,6 @@ def generate_schema_types(input_data: Dict, root=None):
|
|
|
77
77
|
with open(tmp_output) as f:
|
|
78
78
|
output = f.read()
|
|
79
79
|
|
|
80
|
-
output = _fix_title(input_data, output)
|
|
81
|
-
return output
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
def _fix_title(input_data, output) -> str:
|
|
85
|
-
""" the jsonschema_gentypes library changes all titles to Pascalcase
|
|
86
|
-
this function changes them back
|
|
87
|
-
TODO fix bug in gentypes so this step is not necessary
|
|
88
|
-
"""
|
|
89
|
-
for k, v in input_data.items():
|
|
90
|
-
if isinstance(v, dict):
|
|
91
|
-
output = _fix_title(v, output)
|
|
92
|
-
elif k == "title":
|
|
93
|
-
output = output.replace(f"class {v.title()}", f"class {v}")
|
|
94
80
|
return output
|
|
95
81
|
|
|
96
82
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
from typing import Any, Dict, List, Tuple
|
|
2
2
|
|
|
3
3
|
from polyapi.typedefs import PropertySpecification
|
|
4
|
-
from polyapi.utils import
|
|
4
|
+
from polyapi.utils import add_type_import_path, parse_arguments, get_type_and_def, rewrite_arg_name
|
|
5
5
|
|
|
6
6
|
SERVER_DEFS_TEMPLATE = """
|
|
7
7
|
from typing import List, Dict, Any, TypedDict, Callable
|
|
@@ -38,7 +38,7 @@ def render_server_function(
|
|
|
38
38
|
arg_names = [a["name"] for a in arguments]
|
|
39
39
|
args, args_def = parse_arguments(function_name, arguments)
|
|
40
40
|
return_type_name, return_type_def = get_type_and_def(return_type) # type: ignore
|
|
41
|
-
data = "{" + ", ".join([f"'{arg}': {
|
|
41
|
+
data = "{" + ", ".join([f"'{arg}': {rewrite_arg_name(arg)}" for arg in arg_names]) + "}"
|
|
42
42
|
func_type_defs = SERVER_DEFS_TEMPLATE.format(
|
|
43
43
|
args_def=args_def,
|
|
44
44
|
return_type_def=return_type_def,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import keyword
|
|
1
2
|
import re
|
|
2
3
|
import os
|
|
3
4
|
from typing import Tuple, List
|
|
@@ -164,9 +165,10 @@ def parse_arguments(function_name: str, arguments: List[PropertySpecification])
|
|
|
164
165
|
arg_type, arg_def = get_type_and_def(a["type"])
|
|
165
166
|
if arg_def:
|
|
166
167
|
args_def.append(arg_def)
|
|
167
|
-
a["name"] =
|
|
168
|
+
a["name"] = rewrite_arg_name(a["name"])
|
|
168
169
|
arg_string += f" {a['name']}: {add_type_import_path(function_name, arg_type)}"
|
|
169
170
|
description = a.get("description", "")
|
|
171
|
+
description = description.replace("\n", " ")
|
|
170
172
|
if description:
|
|
171
173
|
if idx == len(arguments) - 1:
|
|
172
174
|
arg_string += f" # {description}\n"
|
|
@@ -186,7 +188,7 @@ def poly_full_path(context, name) -> str:
|
|
|
186
188
|
return f"poly.{path}"
|
|
187
189
|
|
|
188
190
|
|
|
189
|
-
|
|
191
|
+
RESERVED_WORDS = {"List", "Dict", "Any", "Optional", "Callable"} | set(keyword.kwlist)
|
|
190
192
|
|
|
191
193
|
|
|
192
194
|
def to_func_namespace(s: str) -> str:
|
|
@@ -194,7 +196,16 @@ def to_func_namespace(s: str) -> str:
|
|
|
194
196
|
by default it is
|
|
195
197
|
"""
|
|
196
198
|
rv = s[0].upper() + s[1:]
|
|
197
|
-
|
|
198
|
-
|
|
199
|
+
rv = rewrite_reserved(rv)
|
|
200
|
+
return rv
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
def rewrite_reserved(s: str) -> str:
|
|
204
|
+
if s in RESERVED_WORDS:
|
|
205
|
+
return "_" + s
|
|
199
206
|
else:
|
|
200
|
-
return
|
|
207
|
+
return s
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
def rewrite_arg_name(s: str):
|
|
211
|
+
return rewrite_reserved(camelCase(s))
|
|
@@ -3,7 +3,7 @@ requires = ["setuptools>=61.2", "wheel"]
|
|
|
3
3
|
|
|
4
4
|
[project]
|
|
5
5
|
name = "polyapi-python"
|
|
6
|
-
version = "0.2.
|
|
6
|
+
version = "0.2.7"
|
|
7
7
|
description = "The Python Client for PolyAPI, the IPaaS by Developers for Developers"
|
|
8
8
|
authors = [{ name = "Dan Fellin", email = "dan@polyapi.io" }]
|
|
9
9
|
dependencies = [
|
|
@@ -36,7 +36,7 @@ class T(unittest.TestCase):
|
|
|
36
36
|
""" pass in a bad id to update and make sure it returns False
|
|
37
37
|
"""
|
|
38
38
|
_get_spec.return_value = None
|
|
39
|
-
updated = get_and_update_rendered_spec("
|
|
39
|
+
updated = get_and_update_rendered_spec("123")
|
|
40
40
|
self.assertEqual(_get_spec.call_count, 1)
|
|
41
41
|
self.assertFalse(updated)
|
|
42
42
|
|
|
@@ -47,6 +47,6 @@ class T(unittest.TestCase):
|
|
|
47
47
|
"""
|
|
48
48
|
_get_spec.return_value = GET_PRODUCTS_COUNT
|
|
49
49
|
post.return_value = Mock(status_code=201, text="Created")
|
|
50
|
-
updated = get_and_update_rendered_spec("
|
|
50
|
+
updated = get_and_update_rendered_spec("123")
|
|
51
51
|
self.assertEqual(_get_spec.call_count, 1)
|
|
52
52
|
self.assertTrue(updated)
|
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
import unittest
|
|
2
|
-
from polyapi.
|
|
3
|
-
from polyapi.utils import get_type_and_def
|
|
2
|
+
from polyapi.utils import get_type_and_def, rewrite_reserved
|
|
4
3
|
|
|
5
4
|
OPENAPI_FUNCTION = {'kind': 'function', 'spec': {'arguments': [{'name': 'event', 'required': False, 'type': {'kind': 'object', 'schema': {'$schema': 'http://json-schema.org/draft-06/schema#', 'type': 'array', 'items': {'$ref': '#/definitions/WebhookEventTypeElement'}, 'definitions': {'WebhookEventTypeElement': {'type': 'object', 'additionalProperties': False, 'properties': {'title': {'type': 'string'}, 'manufacturerName': {'type': 'string'}, 'carType': {'type': 'string'}, 'id': {'type': 'integer'}}, 'required': ['carType', 'id', 'manufacturerName', 'title'], 'title': 'WebhookEventTypeElement'}}}}}, {'name': 'headers', 'required': False, 'type': {'kind': 'object', 'typeName': 'Record<string, any>'}}, {'name': 'params', 'required': False, 'type': {'kind': 'object', 'typeName': 'Record<string, any>'}}, {'name': 'polyCustom', 'required': False, 'type': {'kind': 'object', 'properties': [{'name': 'responseStatusCode', 'type': {'type': 'number', 'kind': 'primitive'}, 'required': True}, {'name': 'responseContentType', 'type': {'type': 'string', 'kind': 'primitive'}, 'required': True, 'nullable': True}]}}], 'returnType': {'kind': 'void'}, 'synchronous': True}}
|
|
6
5
|
|
|
7
6
|
|
|
8
7
|
class T(unittest.TestCase):
|
|
9
|
-
def test_fix_titles(self):
|
|
10
|
-
input_data = {'properties': {'requestNumber': {'title': 'Requestnumber', 'type': 'integer'}}, 'required': ['requestNumber'], 'title': 'numOfCars', 'type': 'object', 'metadata': {'pydantic.internal.needs_apply_discriminated_union': False}}
|
|
11
|
-
output = 'from typing import TypedDict\nfrom typing_extensions import Required\n\n\nclass Numofcars(TypedDict, total=False):\n """ numOfCars. """\n\n requestNumber: Required[int]\n """\n Requestnumber.\n\n Required property\n """\n\n'
|
|
12
|
-
fixed = _fix_title(input_data, output)
|
|
13
|
-
self.assertIn("class numOfCars", fixed)
|
|
14
|
-
|
|
15
8
|
def test_get_type_and_def(self):
|
|
16
9
|
arg_type, arg_def = get_type_and_def(OPENAPI_FUNCTION)
|
|
17
10
|
self.assertEqual(arg_type, "Callable[[List[WebhookEventTypeElement], Dict, Dict, Dict], None]")
|
|
11
|
+
|
|
12
|
+
def test_rewrite_reserved(self):
|
|
13
|
+
rv = rewrite_reserved("from")
|
|
14
|
+
self.assertEqual(rv, "_from")
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{polyapi_python-0.2.6.dev1 → polyapi_python-0.2.7}/polyapi_python.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|