polyapi-python 0.3.9.dev6__tar.gz → 0.3.9.dev8__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 (46) hide show
  1. {polyapi_python-0.3.9.dev6 → polyapi_python-0.3.9.dev8}/PKG-INFO +1 -1
  2. {polyapi_python-0.3.9.dev6 → polyapi_python-0.3.9.dev8}/polyapi/__init__.py +18 -1
  3. {polyapi_python-0.3.9.dev6 → polyapi_python-0.3.9.dev8}/polyapi/execute.py +3 -4
  4. {polyapi_python-0.3.9.dev6 → polyapi_python-0.3.9.dev8}/polyapi/generate.py +40 -4
  5. {polyapi_python-0.3.9.dev6 → polyapi_python-0.3.9.dev8}/polyapi/schema.py +6 -1
  6. {polyapi_python-0.3.9.dev6 → polyapi_python-0.3.9.dev8}/polyapi_python.egg-info/PKG-INFO +1 -1
  7. {polyapi_python-0.3.9.dev6 → polyapi_python-0.3.9.dev8}/pyproject.toml +1 -1
  8. {polyapi_python-0.3.9.dev6 → polyapi_python-0.3.9.dev8}/LICENSE +0 -0
  9. {polyapi_python-0.3.9.dev6 → polyapi_python-0.3.9.dev8}/README.md +0 -0
  10. {polyapi_python-0.3.9.dev6 → polyapi_python-0.3.9.dev8}/polyapi/__main__.py +0 -0
  11. {polyapi_python-0.3.9.dev6 → polyapi_python-0.3.9.dev8}/polyapi/api.py +0 -0
  12. {polyapi_python-0.3.9.dev6 → polyapi_python-0.3.9.dev8}/polyapi/auth.py +0 -0
  13. {polyapi_python-0.3.9.dev6 → polyapi_python-0.3.9.dev8}/polyapi/cli.py +0 -0
  14. {polyapi_python-0.3.9.dev6 → polyapi_python-0.3.9.dev8}/polyapi/client.py +0 -0
  15. {polyapi_python-0.3.9.dev6 → polyapi_python-0.3.9.dev8}/polyapi/config.py +0 -0
  16. {polyapi_python-0.3.9.dev6 → polyapi_python-0.3.9.dev8}/polyapi/constants.py +0 -0
  17. {polyapi_python-0.3.9.dev6 → polyapi_python-0.3.9.dev8}/polyapi/deployables.py +0 -0
  18. {polyapi_python-0.3.9.dev6 → polyapi_python-0.3.9.dev8}/polyapi/error_handler.py +0 -0
  19. {polyapi_python-0.3.9.dev6 → polyapi_python-0.3.9.dev8}/polyapi/exceptions.py +0 -0
  20. {polyapi_python-0.3.9.dev6 → polyapi_python-0.3.9.dev8}/polyapi/function_cli.py +0 -0
  21. {polyapi_python-0.3.9.dev6 → polyapi_python-0.3.9.dev8}/polyapi/parser.py +0 -0
  22. {polyapi_python-0.3.9.dev6 → polyapi_python-0.3.9.dev8}/polyapi/poly_schemas.py +0 -0
  23. {polyapi_python-0.3.9.dev6 → polyapi_python-0.3.9.dev8}/polyapi/prepare.py +0 -0
  24. {polyapi_python-0.3.9.dev6 → polyapi_python-0.3.9.dev8}/polyapi/py.typed +0 -0
  25. {polyapi_python-0.3.9.dev6 → polyapi_python-0.3.9.dev8}/polyapi/rendered_spec.py +0 -0
  26. {polyapi_python-0.3.9.dev6 → polyapi_python-0.3.9.dev8}/polyapi/server.py +0 -0
  27. {polyapi_python-0.3.9.dev6 → polyapi_python-0.3.9.dev8}/polyapi/sync.py +0 -0
  28. {polyapi_python-0.3.9.dev6 → polyapi_python-0.3.9.dev8}/polyapi/typedefs.py +0 -0
  29. {polyapi_python-0.3.9.dev6 → polyapi_python-0.3.9.dev8}/polyapi/utils.py +0 -0
  30. {polyapi_python-0.3.9.dev6 → polyapi_python-0.3.9.dev8}/polyapi/variables.py +0 -0
  31. {polyapi_python-0.3.9.dev6 → polyapi_python-0.3.9.dev8}/polyapi/webhook.py +0 -0
  32. {polyapi_python-0.3.9.dev6 → polyapi_python-0.3.9.dev8}/polyapi_python.egg-info/SOURCES.txt +0 -0
  33. {polyapi_python-0.3.9.dev6 → polyapi_python-0.3.9.dev8}/polyapi_python.egg-info/dependency_links.txt +0 -0
  34. {polyapi_python-0.3.9.dev6 → polyapi_python-0.3.9.dev8}/polyapi_python.egg-info/requires.txt +0 -0
  35. {polyapi_python-0.3.9.dev6 → polyapi_python-0.3.9.dev8}/polyapi_python.egg-info/top_level.txt +0 -0
  36. {polyapi_python-0.3.9.dev6 → polyapi_python-0.3.9.dev8}/setup.cfg +0 -0
  37. {polyapi_python-0.3.9.dev6 → polyapi_python-0.3.9.dev8}/tests/test_api.py +0 -0
  38. {polyapi_python-0.3.9.dev6 → polyapi_python-0.3.9.dev8}/tests/test_auth.py +0 -0
  39. {polyapi_python-0.3.9.dev6 → polyapi_python-0.3.9.dev8}/tests/test_deployables.py +0 -0
  40. {polyapi_python-0.3.9.dev6 → polyapi_python-0.3.9.dev8}/tests/test_generate.py +0 -0
  41. {polyapi_python-0.3.9.dev6 → polyapi_python-0.3.9.dev8}/tests/test_parser.py +0 -0
  42. {polyapi_python-0.3.9.dev6 → polyapi_python-0.3.9.dev8}/tests/test_rendered_spec.py +0 -0
  43. {polyapi_python-0.3.9.dev6 → polyapi_python-0.3.9.dev8}/tests/test_schema.py +0 -0
  44. {polyapi_python-0.3.9.dev6 → polyapi_python-0.3.9.dev8}/tests/test_server.py +0 -0
  45. {polyapi_python-0.3.9.dev6 → polyapi_python-0.3.9.dev8}/tests/test_utils.py +0 -0
  46. {polyapi_python-0.3.9.dev6 → polyapi_python-0.3.9.dev8}/tests/test_variables.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: polyapi-python
3
- Version: 0.3.9.dev6
3
+ Version: 0.3.9.dev8
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
@@ -2,6 +2,8 @@ import os
2
2
  import sys
3
3
  import copy
4
4
  import truststore
5
+ import logging
6
+ import builtins
5
7
  from typing import Any, Dict, Optional, overload, Literal
6
8
  from typing_extensions import TypedDict
7
9
  truststore.inject_into_ssl()
@@ -98,4 +100,19 @@ class _PolyCustom:
98
100
  return new
99
101
 
100
102
 
101
- polyCustom: PolyCustomDict = _PolyCustom()
103
+ polyCustom: PolyCustomDict = _PolyCustom()
104
+
105
+ original_print = print
106
+
107
+ logging.basicConfig(level=logging.INFO, format='%(levelname)s - %(message)s')
108
+
109
+ def log_prints(*objects, sep=' ', end='\n', file=sys.stdout, flush=False):
110
+ message = sep.join(map(str, objects)) + end
111
+ if file is sys.stdout:
112
+ logging.info(message)
113
+ elif file is sys.stderr:
114
+ logging.error(message)
115
+ else:
116
+ original_print(*objects, sep=sep, end=end, file=file, flush=flush)
117
+
118
+ builtins.print = log_prints
@@ -1,12 +1,11 @@
1
1
  from typing import Dict, Optional
2
2
  import requests
3
3
  import os
4
- import logging
4
+ import sys
5
5
  from requests import Response
6
6
  from polyapi.config import get_api_key_and_url, get_mtls_config
7
7
  from polyapi.exceptions import PolyApiException
8
8
 
9
- logger = logging.getLogger("poly")
10
9
 
11
10
  def direct_execute(function_type, function_id, data) -> Response:
12
11
  """ execute a specific function id/type
@@ -49,7 +48,7 @@ def direct_execute(function_type, function_id, data) -> Response:
49
48
  if (resp.status_code < 200 or resp.status_code >= 300):
50
49
  error_content = resp.content.decode("utf-8", errors="ignore")
51
50
  if function_type == 'api' and os.getenv("LOGS_ENABLED"):
52
- logger.error(f"Error executing api function with id: {function_id}. Status code: {resp.status_code}. Request data: {data}, Response: {error_content}")
51
+ print(f"Error executing api function with id: {function_id}. Status code: {resp.status_code}. Request data: {data}, Response: {error_content}", file=sys.stderr)
53
52
  elif function_type != 'api':
54
53
  raise PolyApiException(f"{resp.status_code}: {error_content}")
55
54
 
@@ -73,7 +72,7 @@ def execute(function_type, function_id, data) -> Response:
73
72
  if (resp.status_code < 200 or resp.status_code >= 300) and os.getenv("LOGS_ENABLED"):
74
73
  error_content = resp.content.decode("utf-8", errors="ignore")
75
74
  if function_type == 'api' and os.getenv("LOGS_ENABLED"):
76
- logger.error(f"Error executing api function with id: {function_id}. Status code: {resp.status_code}. Request data: {data}, Response: {error_content}")
75
+ print(f"Error executing api function with id: {function_id}. Status code: {resp.status_code}. Request data: {data}, Response: {error_content}", file=sys.stderr)
77
76
  elif function_type != 'api':
78
77
  raise PolyApiException(f"{resp.status_code}: {error_content}")
79
78
 
@@ -4,6 +4,8 @@ import os
4
4
  import shutil
5
5
  import logging
6
6
  import tempfile
7
+
8
+ from copy import deepcopy
7
9
  from typing import Any, List, Optional, Tuple, cast
8
10
 
9
11
  from .auth import render_auth_function
@@ -136,19 +138,22 @@ def parse_function_specs(
136
138
  limit_ids: List[str] | None = None, # optional list of ids to limit to
137
139
  ) -> List[SpecificationDto]:
138
140
  functions = []
139
- for spec in specs:
140
- if not spec:
141
+ for raw_spec in specs:
142
+ if not raw_spec:
141
143
  continue
142
144
 
143
145
  # For no_types mode, we might not have function data, but we still want to include the spec
144
146
  # if it's a supported function type
145
- if spec["type"] not in SUPPORTED_FUNCTION_TYPES:
147
+ if raw_spec["type"] not in SUPPORTED_FUNCTION_TYPES:
146
148
  continue
147
149
 
148
150
  # Skip if we have a limit and this spec is not in it
149
- if limit_ids and spec.get("id") not in limit_ids:
151
+ if limit_ids and raw_spec.get("id") not in limit_ids:
150
152
  continue
151
153
 
154
+ # Should really be fixed in specs api, but for now handle json strings in arg schemas
155
+ spec = normalize_args_schema(raw_spec)
156
+
152
157
  # For customFunction, check language if we have function data
153
158
  if spec["type"] == "customFunction":
154
159
  if spec.get("language") and spec["language"] != "python":
@@ -286,6 +291,37 @@ def generate_from_cache() -> None:
286
291
  )
287
292
 
288
293
 
294
+ def _parse_arg_schema(value: Any) -> Any:
295
+ if isinstance(value, str):
296
+ text = value.strip()
297
+ if text and text[0] in "{[":
298
+ try:
299
+ return json.loads(text)
300
+ except json.JSONDecodeError:
301
+ logging.warning("Could not parse function argument schema (leaving as str): %s", text[:200])
302
+ return value
303
+
304
+
305
+ def normalize_args_schema(
306
+ raw_spec: SpecificationDto
307
+ ) -> SpecificationDto:
308
+ spec = deepcopy(raw_spec)
309
+
310
+ function_block = spec.get("function")
311
+ if not isinstance(function_block, dict):
312
+ return spec
313
+ arguments_block = function_block.get("arguments")
314
+ if not isinstance(arguments_block, list):
315
+ return spec
316
+
317
+ for argument in arguments_block:
318
+ arg_type = argument.get("type")
319
+ if isinstance(arg_type, dict) and "schema" in arg_type:
320
+ arg_type["schema"] = _parse_arg_schema(arg_type["schema"])
321
+
322
+ return spec
323
+
324
+
289
325
  def generate(contexts: Optional[List[str]] = None, names: Optional[List[str]] = None, function_ids: Optional[List[str]] = None, no_types: bool = False) -> None:
290
326
  generate_msg = f"Generating Poly Python SDK for contexts ${contexts}..." if contexts else "Generating Poly Python SDK..."
291
327
  print(generate_msg, end="", flush=True)
@@ -3,6 +3,8 @@
3
3
  import logging
4
4
  import contextlib
5
5
  import re
6
+ import polyapi
7
+ import builtins
6
8
  from typing import Dict
7
9
  from jsonschema_gentypes.cli import process_config
8
10
  from jsonschema_gentypes import configuration
@@ -89,9 +91,12 @@ def generate_schema_types(input_data: Dict, root=None):
89
91
  }
90
92
 
91
93
  # jsonschema_gentypes prints source to stdout
92
- # no option to surpress so we do this
94
+ # no option to suppress so we do this
95
+ # Not reverting the print monkeypatch causes print to bypass redirect
96
+ builtins.print = polyapi.original_print
93
97
  with contextlib.redirect_stdout(None):
94
98
  process_config(config, [tmp_input])
99
+ builtins.print = polyapi.log_prints
95
100
 
96
101
  with open(tmp_output, encoding='utf-8') as f:
97
102
  output = f.read()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: polyapi-python
3
- Version: 0.3.9.dev6
3
+ Version: 0.3.9.dev8
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.3.9.dev6"
6
+ version = "0.3.9.dev8"
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 = [