polyapi-python 0.2.5.dev7__tar.gz → 0.2.5.dev9__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.
Files changed (40) hide show
  1. {polyapi_python-0.2.5.dev7/polyapi_python.egg-info → polyapi_python-0.2.5.dev9}/PKG-INFO +1 -1
  2. {polyapi_python-0.2.5.dev7 → polyapi_python-0.2.5.dev9}/polyapi/rendered_spec.py +4 -5
  3. {polyapi_python-0.2.5.dev7 → polyapi_python-0.2.5.dev9}/polyapi/schema.py +16 -0
  4. {polyapi_python-0.2.5.dev7 → polyapi_python-0.2.5.dev9}/polyapi/utils.py +5 -19
  5. {polyapi_python-0.2.5.dev7 → polyapi_python-0.2.5.dev9/polyapi_python.egg-info}/PKG-INFO +1 -1
  6. {polyapi_python-0.2.5.dev7 → polyapi_python-0.2.5.dev9}/pyproject.toml +1 -1
  7. polyapi_python-0.2.5.dev9/tests/test_schema.py +20 -0
  8. polyapi_python-0.2.5.dev7/tests/test_schema.py +0 -14
  9. {polyapi_python-0.2.5.dev7 → polyapi_python-0.2.5.dev9}/LICENSE +0 -0
  10. {polyapi_python-0.2.5.dev7 → polyapi_python-0.2.5.dev9}/README.md +0 -0
  11. {polyapi_python-0.2.5.dev7 → polyapi_python-0.2.5.dev9}/polyapi/__init__.py +0 -0
  12. {polyapi_python-0.2.5.dev7 → polyapi_python-0.2.5.dev9}/polyapi/__main__.py +0 -0
  13. {polyapi_python-0.2.5.dev7 → polyapi_python-0.2.5.dev9}/polyapi/api.py +0 -0
  14. {polyapi_python-0.2.5.dev7 → polyapi_python-0.2.5.dev9}/polyapi/auth.py +0 -0
  15. {polyapi_python-0.2.5.dev7 → polyapi_python-0.2.5.dev9}/polyapi/cli.py +0 -0
  16. {polyapi_python-0.2.5.dev7 → polyapi_python-0.2.5.dev9}/polyapi/client.py +0 -0
  17. {polyapi_python-0.2.5.dev7 → polyapi_python-0.2.5.dev9}/polyapi/config.py +0 -0
  18. {polyapi_python-0.2.5.dev7 → polyapi_python-0.2.5.dev9}/polyapi/constants.py +0 -0
  19. {polyapi_python-0.2.5.dev7 → polyapi_python-0.2.5.dev9}/polyapi/error_handler.py +0 -0
  20. {polyapi_python-0.2.5.dev7 → polyapi_python-0.2.5.dev9}/polyapi/exceptions.py +0 -0
  21. {polyapi_python-0.2.5.dev7 → polyapi_python-0.2.5.dev9}/polyapi/execute.py +0 -0
  22. {polyapi_python-0.2.5.dev7 → polyapi_python-0.2.5.dev9}/polyapi/function_cli.py +0 -0
  23. {polyapi_python-0.2.5.dev7 → polyapi_python-0.2.5.dev9}/polyapi/generate.py +0 -0
  24. {polyapi_python-0.2.5.dev7 → polyapi_python-0.2.5.dev9}/polyapi/py.typed +0 -0
  25. {polyapi_python-0.2.5.dev7 → polyapi_python-0.2.5.dev9}/polyapi/server.py +0 -0
  26. {polyapi_python-0.2.5.dev7 → polyapi_python-0.2.5.dev9}/polyapi/typedefs.py +0 -0
  27. {polyapi_python-0.2.5.dev7 → polyapi_python-0.2.5.dev9}/polyapi/variables.py +0 -0
  28. {polyapi_python-0.2.5.dev7 → polyapi_python-0.2.5.dev9}/polyapi/webhook.py +0 -0
  29. {polyapi_python-0.2.5.dev7 → polyapi_python-0.2.5.dev9}/polyapi_python.egg-info/SOURCES.txt +0 -0
  30. {polyapi_python-0.2.5.dev7 → polyapi_python-0.2.5.dev9}/polyapi_python.egg-info/dependency_links.txt +0 -0
  31. {polyapi_python-0.2.5.dev7 → polyapi_python-0.2.5.dev9}/polyapi_python.egg-info/requires.txt +0 -0
  32. {polyapi_python-0.2.5.dev7 → polyapi_python-0.2.5.dev9}/polyapi_python.egg-info/top_level.txt +0 -0
  33. {polyapi_python-0.2.5.dev7 → polyapi_python-0.2.5.dev9}/setup.cfg +0 -0
  34. {polyapi_python-0.2.5.dev7 → polyapi_python-0.2.5.dev9}/tests/test_api.py +0 -0
  35. {polyapi_python-0.2.5.dev7 → polyapi_python-0.2.5.dev9}/tests/test_auth.py +0 -0
  36. {polyapi_python-0.2.5.dev7 → polyapi_python-0.2.5.dev9}/tests/test_function_cli.py +0 -0
  37. {polyapi_python-0.2.5.dev7 → polyapi_python-0.2.5.dev9}/tests/test_rendered_spec.py +0 -0
  38. {polyapi_python-0.2.5.dev7 → polyapi_python-0.2.5.dev9}/tests/test_server.py +0 -0
  39. {polyapi_python-0.2.5.dev7 → polyapi_python-0.2.5.dev9}/tests/test_utils.py +0 -0
  40. {polyapi_python-0.2.5.dev7 → polyapi_python-0.2.5.dev9}/tests/test_variables.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: polyapi-python
3
- Version: 0.2.5.dev7
3
+ Version: 0.2.5.dev9
4
4
  Summary: The Python Client for PolyAPI, the IPaaS by Developers for Developers
5
5
  Author-email: Dan Fellin <dan@polyapi.io>
6
6
  License: MIT License
@@ -1,4 +1,5 @@
1
- from typing import Dict, Optional
1
+ import os
2
+ from typing import Optional
2
3
 
3
4
  import requests
4
5
  from polyapi.config import get_api_key_and_url
@@ -24,8 +25,7 @@ def update_rendered_spec(api_key: str, spec: SpecificationDto):
24
25
  # use super key on develop-k8s here!
25
26
  _, base_url = get_api_key_and_url()
26
27
  if not base_url:
27
- # local node server runs on port 8000
28
- base_url = "http://localhost:8000"
28
+ base_url = os.environ.get("HOST_URL")
29
29
 
30
30
  url = f"{base_url}/functions/rendered-specs"
31
31
  headers = {"Authorization": f"Bearer {api_key}"}
@@ -37,8 +37,7 @@ def update_rendered_spec(api_key: str, spec: SpecificationDto):
37
37
  def _get_spec(api_key: str, spec_id: str) -> Optional[SpecificationDto]:
38
38
  _, base_url = get_api_key_and_url()
39
39
  if not base_url:
40
- # local node server runs on port 8000
41
- base_url = "http://localhost:8000"
40
+ base_url = os.environ.get("HOST_URL")
42
41
 
43
42
  url = f"{base_url}/specs"
44
43
  headers = {"Authorization": f"Bearer {api_key}"}
@@ -1,3 +1,4 @@
1
+ import logging
1
2
  import contextlib
2
3
  from typing import Dict
3
4
  from jsonschema_gentypes.cli import process_config
@@ -31,6 +32,21 @@ def _temp_store_input_data(input_data: Dict) -> str:
31
32
  return temp_file.name
32
33
 
33
34
 
35
+ def wrapped_generate_schema_types(type_spec: dict, root, fallback_type):
36
+ if not root:
37
+ root = "MyList" if fallback_type == "List" else "MyDict"
38
+
39
+ try:
40
+ return clean_title(root), generate_schema_types(type_spec, root=root)
41
+ except RecursionError:
42
+ # some schemas are so huge, our library cant handle it
43
+ # TODO identify critical recursion penalty and maybe switch underlying logic to iterative?
44
+ return fallback_type, ""
45
+ except:
46
+ logging.exception(f"Error when generating schema type: {type_spec}")
47
+ return fallback_type, ""
48
+
49
+
34
50
  def generate_schema_types(input_data: Dict, root=None):
35
51
  """takes in a Dict representing a schema as input then appends the resulting python code to the output file"""
36
52
  _cleanup_input_for_gentypes(input_data)
@@ -1,16 +1,16 @@
1
1
  import re
2
2
  import os
3
- import logging
4
3
  from typing import Tuple, List
5
4
  from colorama import Fore, Style
6
5
  from polyapi.constants import BASIC_PYTHON_TYPES
7
6
  from polyapi.typedefs import PropertySpecification, PropertyType
8
- from polyapi.schema import generate_schema_types, clean_title, map_primitive_types
7
+ from polyapi.schema import wrapped_generate_schema_types, clean_title, map_primitive_types
9
8
 
10
9
 
11
10
  # this string should be in every __init__ file.
12
11
  # it contains all the imports needed for the function or variable code to run
13
12
  CODE_IMPORTS = "from typing import List, Dict, Any, TypedDict, Optional, Callable\nimport logging\nimport requests\nimport socketio # type: ignore\nfrom polyapi.config import get_api_key_and_url\nfrom polyapi.execute import execute, execute_post, variable_get, variable_update\n\n"
13
+ FALLBACK_TYPES = {"Dict", "List"}
14
14
 
15
15
 
16
16
  def init_the_init(full_path: str) -> None:
@@ -96,11 +96,7 @@ def get_type_and_def(type_spec: PropertyType) -> Tuple[str, str]:
96
96
  if type_spec.get("items"):
97
97
  items = type_spec["items"]
98
98
  if items.get("$ref"):
99
- try:
100
- return "ResponseType", generate_schema_types(type_spec, root="ResponseType") # type: ignore
101
- except:
102
- logging.exception(f"Error when generating schema type: {type_spec}")
103
- return "Dict", ""
99
+ return wrapped_generate_schema_types(type_spec, "ResponseType", "Dict") # type: ignore
104
100
  else:
105
101
  item_type, _ = get_type_and_def(items)
106
102
  title = f"List[{item_type}]"
@@ -116,12 +112,7 @@ def get_type_and_def(type_spec: PropertyType) -> Tuple[str, str]:
116
112
  title = schema.get("title", "")
117
113
  if title:
118
114
  assert isinstance(title, str)
119
- title = clean_title(title)
120
- try:
121
- return title, generate_schema_types(schema, root=title) # type: ignore
122
- except:
123
- logging.exception(f"Error when generating schema type: {schema}")
124
- return "Dict", ""
115
+ return wrapped_generate_schema_types(schema, title, "Dict") # type: ignore
125
116
 
126
117
  elif schema.get("items"):
127
118
  # fallback to schema $ref name if no explicit title
@@ -132,16 +123,11 @@ def get_type_and_def(type_spec: PropertyType) -> Tuple[str, str]:
132
123
  title = items.get("$ref", "") # type: ignore
133
124
 
134
125
  title = title.rsplit("/", 1)[-1]
135
- title = clean_title(title)
136
126
  if not title:
137
127
  return "List", ""
138
128
 
139
129
  title = f"List[{title}]"
140
- try:
141
- return title, generate_schema_types(schema, root=title)
142
- except:
143
- logging.exception(f"Error when generating schema type: {schema}")
144
- return "List", ""
130
+ return wrapped_generate_schema_types(schema, title, "List")
145
131
  else:
146
132
  return "Any", ""
147
133
  else:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: polyapi-python
3
- Version: 0.2.5.dev7
3
+ Version: 0.2.5.dev9
4
4
  Summary: The Python Client for PolyAPI, the IPaaS by Developers for Developers
5
5
  Author-email: Dan Fellin <dan@polyapi.io>
6
6
  License: MIT License
@@ -3,7 +3,7 @@ requires = ["setuptools>=61.2", "wheel"]
3
3
 
4
4
  [project]
5
5
  name = "polyapi-python"
6
- version = "0.2.5.dev7"
6
+ version = "0.2.5.dev9"
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 = [
@@ -0,0 +1,20 @@
1
+ import unittest
2
+ from polyapi.schema import wrapped_generate_schema_types
3
+
4
+ SCHEMA = {
5
+ "$schema": "http://json-schema.org/draft-06/schema#",
6
+ "type": "object",
7
+ "properties": {"name": {"type": "string"}},
8
+ "required": ["name"],
9
+ "additionalProperties": False,
10
+ "definitions": {},
11
+ }
12
+
13
+
14
+ class T(unittest.TestCase):
15
+ def test_fix_titles(self):
16
+ output = wrapped_generate_schema_types(SCHEMA, "", "Dict")
17
+ self.assertEqual("MyDict", output[0])
18
+ self.assertIn("class MyDict", output[1])
19
+
20
+ # should not throw with unknown dialect error
@@ -1,14 +0,0 @@
1
- import unittest
2
- from polyapi.schema import generate_schema_types
3
-
4
-
5
- class T(unittest.TestCase):
6
- def test_fix_titles(self):
7
- # schema = json.loads(SCHEMA)
8
- schema = {"$schema": "http://json-schema.org/draft-06/schema#"}
9
- try:
10
- a, b = generate_schema_types(schema)
11
- except AssertionError:
12
- pass
13
-
14
- # should not throw with unknown dialect error