polyapi-python 0.3.4.dev2__tar.gz → 0.3.5.dev1__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.3.4.dev2/polyapi_python.egg-info → polyapi_python-0.3.5.dev1}/PKG-INFO +1 -1
- {polyapi_python-0.3.4.dev2 → polyapi_python-0.3.5.dev1}/polyapi/cli.py +8 -2
- {polyapi_python-0.3.4.dev2 → polyapi_python-0.3.5.dev1}/polyapi/config.py +1 -3
- {polyapi_python-0.3.4.dev2 → polyapi_python-0.3.5.dev1}/polyapi/function_cli.py +6 -1
- {polyapi_python-0.3.4.dev2 → polyapi_python-0.3.5.dev1}/polyapi/generate.py +10 -5
- {polyapi_python-0.3.4.dev2 → polyapi_python-0.3.5.dev1}/polyapi/utils.py +6 -10
- {polyapi_python-0.3.4.dev2 → polyapi_python-0.3.5.dev1/polyapi_python.egg-info}/PKG-INFO +1 -1
- {polyapi_python-0.3.4.dev2 → polyapi_python-0.3.5.dev1}/pyproject.toml +1 -1
- {polyapi_python-0.3.4.dev2 → polyapi_python-0.3.5.dev1}/LICENSE +0 -0
- {polyapi_python-0.3.4.dev2 → polyapi_python-0.3.5.dev1}/README.md +0 -0
- {polyapi_python-0.3.4.dev2 → polyapi_python-0.3.5.dev1}/polyapi/__init__.py +0 -0
- {polyapi_python-0.3.4.dev2 → polyapi_python-0.3.5.dev1}/polyapi/__main__.py +0 -0
- {polyapi_python-0.3.4.dev2 → polyapi_python-0.3.5.dev1}/polyapi/api.py +0 -0
- {polyapi_python-0.3.4.dev2 → polyapi_python-0.3.5.dev1}/polyapi/auth.py +0 -0
- {polyapi_python-0.3.4.dev2 → polyapi_python-0.3.5.dev1}/polyapi/client.py +0 -0
- {polyapi_python-0.3.4.dev2 → polyapi_python-0.3.5.dev1}/polyapi/constants.py +0 -0
- {polyapi_python-0.3.4.dev2 → polyapi_python-0.3.5.dev1}/polyapi/deployables.py +0 -0
- {polyapi_python-0.3.4.dev2 → polyapi_python-0.3.5.dev1}/polyapi/error_handler.py +0 -0
- {polyapi_python-0.3.4.dev2 → polyapi_python-0.3.5.dev1}/polyapi/exceptions.py +0 -0
- {polyapi_python-0.3.4.dev2 → polyapi_python-0.3.5.dev1}/polyapi/execute.py +0 -0
- {polyapi_python-0.3.4.dev2 → polyapi_python-0.3.5.dev1}/polyapi/parser.py +0 -0
- {polyapi_python-0.3.4.dev2 → polyapi_python-0.3.5.dev1}/polyapi/poly_schemas.py +0 -0
- {polyapi_python-0.3.4.dev2 → polyapi_python-0.3.5.dev1}/polyapi/prepare.py +0 -0
- {polyapi_python-0.3.4.dev2 → polyapi_python-0.3.5.dev1}/polyapi/py.typed +0 -0
- {polyapi_python-0.3.4.dev2 → polyapi_python-0.3.5.dev1}/polyapi/rendered_spec.py +0 -0
- {polyapi_python-0.3.4.dev2 → polyapi_python-0.3.5.dev1}/polyapi/schema.py +0 -0
- {polyapi_python-0.3.4.dev2 → polyapi_python-0.3.5.dev1}/polyapi/server.py +0 -0
- {polyapi_python-0.3.4.dev2 → polyapi_python-0.3.5.dev1}/polyapi/sync.py +0 -0
- {polyapi_python-0.3.4.dev2 → polyapi_python-0.3.5.dev1}/polyapi/typedefs.py +0 -0
- {polyapi_python-0.3.4.dev2 → polyapi_python-0.3.5.dev1}/polyapi/variables.py +0 -0
- {polyapi_python-0.3.4.dev2 → polyapi_python-0.3.5.dev1}/polyapi/webhook.py +0 -0
- {polyapi_python-0.3.4.dev2 → polyapi_python-0.3.5.dev1}/polyapi_python.egg-info/SOURCES.txt +0 -0
- {polyapi_python-0.3.4.dev2 → polyapi_python-0.3.5.dev1}/polyapi_python.egg-info/dependency_links.txt +0 -0
- {polyapi_python-0.3.4.dev2 → polyapi_python-0.3.5.dev1}/polyapi_python.egg-info/requires.txt +0 -0
- {polyapi_python-0.3.4.dev2 → polyapi_python-0.3.5.dev1}/polyapi_python.egg-info/top_level.txt +0 -0
- {polyapi_python-0.3.4.dev2 → polyapi_python-0.3.5.dev1}/setup.cfg +0 -0
- {polyapi_python-0.3.4.dev2 → polyapi_python-0.3.5.dev1}/tests/test_api.py +0 -0
- {polyapi_python-0.3.4.dev2 → polyapi_python-0.3.5.dev1}/tests/test_auth.py +0 -0
- {polyapi_python-0.3.4.dev2 → polyapi_python-0.3.5.dev1}/tests/test_deployables.py +0 -0
- {polyapi_python-0.3.4.dev2 → polyapi_python-0.3.5.dev1}/tests/test_generate.py +0 -0
- {polyapi_python-0.3.4.dev2 → polyapi_python-0.3.5.dev1}/tests/test_parser.py +0 -0
- {polyapi_python-0.3.4.dev2 → polyapi_python-0.3.5.dev1}/tests/test_rendered_spec.py +0 -0
- {polyapi_python-0.3.4.dev2 → polyapi_python-0.3.5.dev1}/tests/test_schema.py +0 -0
- {polyapi_python-0.3.4.dev2 → polyapi_python-0.3.5.dev1}/tests/test_server.py +0 -0
- {polyapi_python-0.3.4.dev2 → polyapi_python-0.3.5.dev1}/tests/test_utils.py +0 -0
- {polyapi_python-0.3.4.dev2 → polyapi_python-0.3.5.dev1}/tests/test_variables.py +0 -0
|
@@ -45,10 +45,12 @@ def execute_from_cli():
|
|
|
45
45
|
# Generate command
|
|
46
46
|
generate_parser = subparsers.add_parser("generate", help="Generates Poly library")
|
|
47
47
|
generate_parser.add_argument("--no-types", action="store_true", help="Generate SDK without type definitions")
|
|
48
|
+
generate_parser.add_argument("--contexts", type=str, required=False, help="Contexts to generate")
|
|
48
49
|
|
|
49
50
|
def generate_command(args):
|
|
50
51
|
initialize_config()
|
|
51
|
-
|
|
52
|
+
contexts = args.contexts.split(",") if args.contexts else None
|
|
53
|
+
generate(contexts=contexts, no_types=args.no_types)
|
|
52
54
|
|
|
53
55
|
generate_parser.set_defaults(command=generate_command)
|
|
54
56
|
|
|
@@ -69,6 +71,7 @@ def execute_from_cli():
|
|
|
69
71
|
fn_add_parser.add_argument("--logs", choices=["enabled", "disabled"], default=None, help="Enable or disable logs for the function.")
|
|
70
72
|
fn_add_parser.add_argument("--execution-api-key", required=False, default="", help="API key for execution (for server functions only).")
|
|
71
73
|
fn_add_parser.add_argument("--disable-ai", "--skip-generate", action="store_true", help="Pass --disable-ai skip AI generation of missing descriptions")
|
|
74
|
+
fn_add_parser.add_argument("--generate-contexts", type=str, help="Server function only – only include certain contexts to speed up function execution")
|
|
72
75
|
|
|
73
76
|
def add_function(args):
|
|
74
77
|
initialize_config()
|
|
@@ -80,6 +83,8 @@ def execute_from_cli():
|
|
|
80
83
|
err = "You must specify `--server` or `--client`."
|
|
81
84
|
elif logs_enabled and not args.server:
|
|
82
85
|
err = "Option `logs` is only for server functions (--server)."
|
|
86
|
+
elif args.generate_contexts and not args.server:
|
|
87
|
+
err = "Option `generate-contexts` is only for server functions (--server)."
|
|
83
88
|
|
|
84
89
|
if err:
|
|
85
90
|
print_red("ERROR")
|
|
@@ -95,7 +100,8 @@ def execute_from_cli():
|
|
|
95
100
|
server=args.server,
|
|
96
101
|
logs_enabled=logs_enabled,
|
|
97
102
|
generate=not args.disable_ai,
|
|
98
|
-
execution_api_key=args.execution_api_key
|
|
103
|
+
execution_api_key=args.execution_api_key,
|
|
104
|
+
generate_contexts=args.generate_contexts
|
|
99
105
|
)
|
|
100
106
|
|
|
101
107
|
fn_add_parser.set_defaults(command=add_function)
|
|
@@ -3,7 +3,7 @@ import os
|
|
|
3
3
|
import configparser
|
|
4
4
|
from typing import Tuple
|
|
5
5
|
|
|
6
|
-
from polyapi.utils import is_valid_polyapi_url,
|
|
6
|
+
from polyapi.utils import is_valid_polyapi_url, print_green, print_yellow
|
|
7
7
|
|
|
8
8
|
# cached values
|
|
9
9
|
API_KEY = None
|
|
@@ -78,8 +78,6 @@ def initialize_config(force=False):
|
|
|
78
78
|
errors = []
|
|
79
79
|
if not is_valid_polyapi_url(url):
|
|
80
80
|
errors.append(f"{url} is not a valid Poly API Base URL")
|
|
81
|
-
if not is_valid_uuid(key):
|
|
82
|
-
errors.append(f"{key} is not a valid Poly App Key or User Key")
|
|
83
81
|
if errors:
|
|
84
82
|
print_yellow("\n".join(errors))
|
|
85
83
|
sys.exit(1)
|
|
@@ -24,6 +24,7 @@ def function_add_or_update(
|
|
|
24
24
|
client: bool,
|
|
25
25
|
server: bool,
|
|
26
26
|
logs_enabled: Optional[bool],
|
|
27
|
+
generate_contexts: Optional[str],
|
|
27
28
|
generate: bool = True,
|
|
28
29
|
execution_api_key: str = ""
|
|
29
30
|
):
|
|
@@ -59,6 +60,9 @@ def function_add_or_update(
|
|
|
59
60
|
"logsEnabled": logs_enabled,
|
|
60
61
|
}
|
|
61
62
|
|
|
63
|
+
if generate_contexts:
|
|
64
|
+
data["generateContexts"] = generate_contexts.split(",")
|
|
65
|
+
|
|
62
66
|
if server and parsed["dependencies"]:
|
|
63
67
|
print_yellow(
|
|
64
68
|
"\nPlease note that deploying your functions will take a few minutes because it makes use of libraries other than polyapi."
|
|
@@ -87,7 +91,8 @@ def function_add_or_update(
|
|
|
87
91
|
function_id = resp.json()["id"]
|
|
88
92
|
print(f"Function ID: {function_id}")
|
|
89
93
|
if generate:
|
|
90
|
-
|
|
94
|
+
contexts=generate_contexts.split(",") if generate_contexts else None
|
|
95
|
+
generate_library(contexts=contexts)
|
|
91
96
|
else:
|
|
92
97
|
print("Error adding function.")
|
|
93
98
|
print(resp.status_code)
|
|
@@ -2,7 +2,7 @@ import json
|
|
|
2
2
|
import requests
|
|
3
3
|
import os
|
|
4
4
|
import shutil
|
|
5
|
-
from typing import List, Tuple, cast
|
|
5
|
+
from typing import List, Optional, Tuple, cast
|
|
6
6
|
|
|
7
7
|
from .auth import render_auth_function
|
|
8
8
|
from .client import render_client_function
|
|
@@ -36,12 +36,16 @@ Unresolved schema, please add the following schema to complete it:
|
|
|
36
36
|
path:'''
|
|
37
37
|
|
|
38
38
|
|
|
39
|
-
def get_specs(no_types: bool = False) -> List:
|
|
39
|
+
def get_specs(contexts=Optional[List[str]], no_types: bool = False) -> List:
|
|
40
40
|
api_key, api_url = get_api_key_and_url()
|
|
41
41
|
assert api_key
|
|
42
42
|
headers = get_auth_headers(api_key)
|
|
43
43
|
url = f"{api_url}/specs"
|
|
44
44
|
params = {"noTypes": str(no_types).lower()}
|
|
45
|
+
|
|
46
|
+
if contexts:
|
|
47
|
+
params["contexts"] = contexts
|
|
48
|
+
|
|
45
49
|
resp = requests.get(url, headers=headers, params=params)
|
|
46
50
|
if resp.status_code == 200:
|
|
47
51
|
return resp.json()
|
|
@@ -197,11 +201,12 @@ def remove_old_library():
|
|
|
197
201
|
shutil.rmtree(path)
|
|
198
202
|
|
|
199
203
|
|
|
200
|
-
def generate(no_types: bool = False) -> None:
|
|
201
|
-
|
|
204
|
+
def generate(contexts: Optional[List[str]] = None, no_types: bool = False) -> None:
|
|
205
|
+
generate_msg = f"Generating Poly Python SDK for contexts ${contexts}..." if contexts else "Generating Poly Python SDK..."
|
|
206
|
+
print(generate_msg, end="", flush=True)
|
|
202
207
|
remove_old_library()
|
|
203
208
|
|
|
204
|
-
specs = get_specs(no_types=no_types)
|
|
209
|
+
specs = get_specs(no_types=no_types, contexts=contexts)
|
|
205
210
|
cache_specs(specs)
|
|
206
211
|
|
|
207
212
|
limit_ids: List[str] = [] # useful for narrowing down generation to a single function to debug
|
|
@@ -2,6 +2,7 @@ import keyword
|
|
|
2
2
|
import re
|
|
3
3
|
import os
|
|
4
4
|
import uuid
|
|
5
|
+
from urllib.parse import urlparse
|
|
5
6
|
from typing import Tuple, List
|
|
6
7
|
from colorama import Fore, Style
|
|
7
8
|
from polyapi.constants import BASIC_PYTHON_TYPES
|
|
@@ -261,21 +262,16 @@ valid_subdomains = ["na[1-2]", "eu[1-2]", "dev"]
|
|
|
261
262
|
|
|
262
263
|
|
|
263
264
|
def is_valid_polyapi_url(_url: str):
|
|
265
|
+
# in dev allow localhost (and 127.0.0.1) over http *or* https
|
|
266
|
+
parsed = urlparse(_url)
|
|
267
|
+
if parsed.scheme in ("http", "https") and parsed.hostname in ("localhost", "127.0.0.1"):
|
|
268
|
+
return True
|
|
269
|
+
|
|
264
270
|
# Join the subdomains into a pattern
|
|
265
271
|
subdomain_pattern = "|".join(valid_subdomains)
|
|
266
272
|
pattern = rf"^https://({subdomain_pattern})\.polyapi\.io$"
|
|
267
273
|
return re.match(pattern, _url) is not None
|
|
268
274
|
|
|
269
|
-
|
|
270
|
-
def is_valid_uuid(uuid_string, version=4):
|
|
271
|
-
try:
|
|
272
|
-
uuid_obj = uuid.UUID(uuid_string, version=version)
|
|
273
|
-
except ValueError:
|
|
274
|
-
return False
|
|
275
|
-
|
|
276
|
-
return str(uuid_obj) == uuid_string
|
|
277
|
-
|
|
278
|
-
|
|
279
275
|
def return_type_already_defined_in_args(return_type_name: str, args_def: str) -> bool:
|
|
280
276
|
"""
|
|
281
277
|
Checks if the return_type_name preceded optionally by 'class ' and followed by ' =' exists in args_def.
|
|
@@ -3,7 +3,7 @@ requires = ["setuptools>=61.2", "wheel"]
|
|
|
3
3
|
|
|
4
4
|
[project]
|
|
5
5
|
name = "polyapi-python"
|
|
6
|
-
version = "0.3.
|
|
6
|
+
version = "0.3.5.dev1"
|
|
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 = [
|
|
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
|
|
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.3.4.dev2 → polyapi_python-0.3.5.dev1}/polyapi_python.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
{polyapi_python-0.3.4.dev2 → polyapi_python-0.3.5.dev1}/polyapi_python.egg-info/requires.txt
RENAMED
|
File without changes
|
{polyapi_python-0.3.4.dev2 → polyapi_python-0.3.5.dev1}/polyapi_python.egg-info/top_level.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
|
|
File without changes
|
|
File without changes
|