polyapi-python 0.3.8.dev1__py3-none-any.whl → 0.3.8.dev2__py3-none-any.whl

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/cli.py CHANGED
@@ -36,6 +36,9 @@ def execute_from_cli():
36
36
  set_api_key_and_url(args.url, args.api_key)
37
37
  else:
38
38
  initialize_config(force=True)
39
+ # setup command should have default cache values
40
+ from .config import cache_generate_args
41
+ cache_generate_args(contexts=None, names=None, function_ids=None, no_types=False)
39
42
  generate()
40
43
 
41
44
  setup_parser.set_defaults(command=setup)
@@ -46,11 +49,34 @@ def execute_from_cli():
46
49
  generate_parser = subparsers.add_parser("generate", help="Generates Poly library")
47
50
  generate_parser.add_argument("--no-types", action="store_true", help="Generate SDK without type definitions")
48
51
  generate_parser.add_argument("--contexts", type=str, required=False, help="Contexts to generate")
52
+ generate_parser.add_argument("--names", type=str, required=False, help="Resource names to generate (comma-separated)")
53
+ generate_parser.add_argument("--function-ids", type=str, required=False, help="Function IDs to generate (comma-separated)")
49
54
 
50
55
  def generate_command(args):
56
+ from .config import cache_generate_args
57
+
51
58
  initialize_config()
59
+
52
60
  contexts = args.contexts.split(",") if args.contexts else None
53
- generate(contexts=contexts, no_types=args.no_types)
61
+ names = args.names.split(",") if args.names else None
62
+ function_ids = args.function_ids.split(",") if args.function_ids else None
63
+ no_types = args.no_types
64
+
65
+ # overwrite all cached values with the values passed in from the command line
66
+ final_contexts = contexts
67
+ final_names = names
68
+ final_function_ids = function_ids
69
+ final_no_types = no_types
70
+
71
+ # cache the values used for this explicit generate command
72
+ cache_generate_args(
73
+ contexts=final_contexts,
74
+ names=final_names,
75
+ function_ids=final_function_ids,
76
+ no_types=final_no_types
77
+ )
78
+
79
+ generate(contexts=final_contexts, names=final_names, function_ids=final_function_ids, no_types=final_no_types)
54
80
 
55
81
  generate_parser.set_defaults(command=generate_command)
56
82
 
polyapi/config.py CHANGED
@@ -12,6 +12,10 @@ API_FUNCTION_DIRECT_EXECUTE = None
12
12
  MTLS_CERT_PATH = None
13
13
  MTLS_KEY_PATH = None
14
14
  MTLS_CA_PATH = None
15
+ LAST_GENERATE_CONTEXTS = None
16
+ LAST_GENERATE_NAMES = None
17
+ LAST_GENERATE_FUNCTION_IDS = None
18
+ LAST_GENERATE_NO_TYPES = None
15
19
 
16
20
 
17
21
  def get_config_file_path() -> str:
@@ -55,6 +59,16 @@ def get_api_key_and_url() -> Tuple[str | None, str | None]:
55
59
  MTLS_CERT_PATH = config.get("polyapi", "mtls_cert_path", fallback=None)
56
60
  MTLS_KEY_PATH = config.get("polyapi", "mtls_key_path", fallback=None)
57
61
  MTLS_CA_PATH = config.get("polyapi", "mtls_ca_path", fallback=None)
62
+
63
+ # Read and cache generate command arguments
64
+ global LAST_GENERATE_CONTEXTS, LAST_GENERATE_NAMES, LAST_GENERATE_FUNCTION_IDS, LAST_GENERATE_NO_TYPES
65
+ contexts_str = config.get("polyapi", "last_generate_contexts_used", fallback=None)
66
+ LAST_GENERATE_CONTEXTS = contexts_str.split(",") if contexts_str else None
67
+ names_str = config.get("polyapi", "last_generate_names_used", fallback=None)
68
+ LAST_GENERATE_NAMES = names_str.split(",") if names_str else None
69
+ function_ids_str = config.get("polyapi", "last_generate_function_ids_used", fallback=None)
70
+ LAST_GENERATE_FUNCTION_IDS = function_ids_str.split(",") if function_ids_str else None
71
+ LAST_GENERATE_NO_TYPES = config.get("polyapi", "last_generate_no_types_used", fallback="false").lower() == "true"
58
72
 
59
73
  return key, url
60
74
 
@@ -133,4 +147,58 @@ def get_direct_execute_config() -> bool:
133
147
  if API_FUNCTION_DIRECT_EXECUTE is None:
134
148
  # Force a config read if value isn't cached
135
149
  get_api_key_and_url()
136
- return bool(API_FUNCTION_DIRECT_EXECUTE)
150
+ return bool(API_FUNCTION_DIRECT_EXECUTE)
151
+
152
+
153
+ def get_cached_generate_args() -> Tuple[list | None, list | None, list | None, bool]:
154
+ """Return cached generate command arguments"""
155
+ global LAST_GENERATE_CONTEXTS, LAST_GENERATE_NAMES, LAST_GENERATE_FUNCTION_IDS, LAST_GENERATE_NO_TYPES
156
+ if LAST_GENERATE_CONTEXTS is None and LAST_GENERATE_NAMES is None and LAST_GENERATE_FUNCTION_IDS is None and LAST_GENERATE_NO_TYPES is None:
157
+ # Force a config read if values aren't cached
158
+ get_api_key_and_url()
159
+ return LAST_GENERATE_CONTEXTS, LAST_GENERATE_NAMES, LAST_GENERATE_FUNCTION_IDS, bool(LAST_GENERATE_NO_TYPES)
160
+
161
+
162
+ def cache_generate_args(contexts: list | None = None, names: list | None = None, function_ids: list | None = None, no_types: bool = False):
163
+ """Cache generate command arguments to config file"""
164
+ from typing import List
165
+
166
+ # Read existing config
167
+ path = get_config_file_path()
168
+ config = configparser.ConfigParser()
169
+
170
+ if os.path.exists(path):
171
+ with open(path, "r") as f:
172
+ config.read_file(f)
173
+
174
+ # Ensure polyapi section exists
175
+ if "polyapi" not in config:
176
+ config["polyapi"] = {}
177
+
178
+ # Update cached values
179
+ global LAST_GENERATE_CONTEXTS, LAST_GENERATE_NAMES, LAST_GENERATE_FUNCTION_IDS, LAST_GENERATE_NO_TYPES
180
+ LAST_GENERATE_CONTEXTS = contexts
181
+ LAST_GENERATE_NAMES = names
182
+ LAST_GENERATE_FUNCTION_IDS = function_ids
183
+ LAST_GENERATE_NO_TYPES = no_types
184
+
185
+ # Write values to config
186
+ if contexts is not None:
187
+ config.set("polyapi", "last_generate_contexts_used", ",".join(contexts))
188
+ elif config.has_option("polyapi", "last_generate_contexts_used"):
189
+ config.remove_option("polyapi", "last_generate_contexts_used")
190
+
191
+ if names is not None:
192
+ config.set("polyapi", "last_generate_names_used", ",".join(names))
193
+ elif config.has_option("polyapi", "last_generate_names_used"):
194
+ config.remove_option("polyapi", "last_generate_names_used")
195
+
196
+ if function_ids is not None:
197
+ config.set("polyapi", "last_generate_function_ids_used", ",".join(function_ids))
198
+ elif config.has_option("polyapi", "last_generate_function_ids_used"):
199
+ config.remove_option("polyapi", "last_generate_function_ids_used")
200
+
201
+ config.set("polyapi", "last_generate_no_types_used", str(no_types).lower())
202
+
203
+ with open(path, "w") as f:
204
+ config.write(f)
polyapi/function_cli.py CHANGED
@@ -1,7 +1,7 @@
1
1
  import sys
2
2
  from typing import Any, List, Optional
3
3
  import requests
4
- from polyapi.generate import generate as generate_library
4
+
5
5
  from polyapi.config import get_api_key_and_url
6
6
  from polyapi.utils import get_auth_headers, print_green, print_red, print_yellow
7
7
  from polyapi.parser import parse_function_code, get_jsonschema_type
@@ -91,7 +91,9 @@ def function_add_or_update(
91
91
  function_id = resp.json()["id"]
92
92
  print(f"Function ID: {function_id}")
93
93
  if generate:
94
- generate_library()
94
+ # Use cached generate arguments when regenerating after function deployment
95
+ from polyapi.generate import generate_from_cache
96
+ generate_from_cache()
95
97
  else:
96
98
  print("Error adding function.")
97
99
  print(resp.status_code)
polyapi/generate.py CHANGED
@@ -14,7 +14,7 @@ from .api import render_api_function
14
14
  from .server import render_server_function
15
15
  from .utils import add_import_to_init, get_auth_headers, init_the_init, print_green, to_func_namespace
16
16
  from .variables import generate_variables
17
- from .config import get_api_key_and_url, get_direct_execute_config
17
+ from .config import get_api_key_and_url, get_direct_execute_config, get_cached_generate_args
18
18
 
19
19
  SUPPORTED_FUNCTION_TYPES = {
20
20
  "apiFunction",
@@ -36,7 +36,7 @@ Unresolved schema, please add the following schema to complete it:
36
36
  path:'''
37
37
 
38
38
 
39
- def get_specs(contexts=Optional[List[str]], no_types: bool = False) -> List:
39
+ def get_specs(contexts: Optional[List[str]] = None, names: Optional[List[str]] = None, function_ids: Optional[List[str]] = None, 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)
@@ -45,6 +45,12 @@ def get_specs(contexts=Optional[List[str]], no_types: bool = False) -> List:
45
45
 
46
46
  if contexts:
47
47
  params["contexts"] = contexts
48
+
49
+ if names:
50
+ params["names"] = names
51
+
52
+ if function_ids:
53
+ params["functionIds"] = function_ids
48
54
 
49
55
  # Add apiFunctionDirectExecute parameter if direct execute is enabled
50
56
  if get_direct_execute_config():
@@ -264,12 +270,26 @@ sys.modules[__name__] = _SchemaModule()
264
270
  ''')
265
271
 
266
272
 
267
- def generate(contexts: Optional[List[str]] = None, no_types: bool = False) -> None:
273
+ def generate_from_cache() -> None:
274
+ """
275
+ Generate using cached values after non-explicit call.
276
+ """
277
+ cached_contexts, cached_names, cached_function_ids, cached_no_types = get_cached_generate_args()
278
+
279
+ generate(
280
+ contexts=cached_contexts,
281
+ names=cached_names,
282
+ function_ids=cached_function_ids,
283
+ no_types=cached_no_types
284
+ )
285
+
286
+
287
+ def generate(contexts: Optional[List[str]] = None, names: Optional[List[str]] = None, function_ids: Optional[List[str]] = None, no_types: bool = False) -> None:
268
288
  generate_msg = f"Generating Poly Python SDK for contexts ${contexts}..." if contexts else "Generating Poly Python SDK..."
269
289
  print(generate_msg, end="", flush=True)
270
290
  remove_old_library()
271
291
 
272
- specs = get_specs(no_types=no_types, contexts=contexts)
292
+ specs = get_specs(contexts=contexts, names=names, function_ids=function_ids, no_types=no_types)
273
293
  cache_specs(specs)
274
294
 
275
295
  limit_ids: List[str] = [] # useful for narrowing down generation to a single function to debug
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: polyapi-python
3
- Version: 0.3.8.dev1
3
+ Version: 0.3.8.dev2
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
@@ -31,7 +31,7 @@ License-File: LICENSE
31
31
  Requires-Dist: requests>=2.32.3
32
32
  Requires-Dist: typing_extensions>=4.12.2
33
33
  Requires-Dist: jsonschema-gentypes==2.6.0
34
- Requires-Dist: pydantic==2.6.4
34
+ Requires-Dist: pydantic>=2.6.4
35
35
  Requires-Dist: stdlib_list==0.10.0
36
36
  Requires-Dist: colorama==0.4.4
37
37
  Requires-Dist: python-socketio[asyncio_client]==5.11.1
@@ -2,16 +2,16 @@ polyapi/__init__.py,sha256=hw7x4j9JNJfPdkIOZqV0X9pbYcw3_5AH1iQFdSogH-c,3235
2
2
  polyapi/__main__.py,sha256=V4zhAh_YGxno5f_KSrlkELxcuDh9bR3WSd0n-2r-qQQ,93
3
3
  polyapi/api.py,sha256=2nds6ZdNe9OHvCba4IjOPga0CAYIsib2SbhEyDDCmd8,2188
4
4
  polyapi/auth.py,sha256=zrIGatjba5GwUTNjKj1GHQWTEDP9B-HrSzCKbLFoqvc,5336
5
- polyapi/cli.py,sha256=jtKXARbT9AOgYTR6nf3OiwiPvsyUlLVbyynEA84PDzw,8924
5
+ polyapi/cli.py,sha256=NcLXOUdkcXgsFboO5PXwncK4uzGLu1mIXJDUn5NUgKo,10192
6
6
  polyapi/client.py,sha256=CoFDYvyKsqL4wPQbUDIr0Qb8Q5eD92xN4OEEcJEVuGQ,1296
7
- polyapi/config.py,sha256=QQxRZ9nMUykItUMAdw97dad0DPEV1luRwkeqOyrEKf8,4316
7
+ polyapi/config.py,sha256=cAMv2n9tGN_BTvqt7V32o5F86qRhxAKyey_PoId2D8s,7638
8
8
  polyapi/constants.py,sha256=sc-FnS0SngBLvSu1ZWMs0UCf9EYD1u1Yhfr-sZXGLns,607
9
9
  polyapi/deployables.py,sha256=KjVAillK3OMNpT2F5KzmAefoTSmhDN0ZIwzEMXPCRU0,12261
10
10
  polyapi/error_handler.py,sha256=I_e0iz6VM23FLVQWJljxs2NGcl_OODbi43OcbnqBlp8,2398
11
11
  polyapi/exceptions.py,sha256=Zh7i7eCUhDuXEdUYjatkLFTeZkrx1BJ1P5ePgbJ9eIY,89
12
12
  polyapi/execute.py,sha256=sjI6BMBYPSCD6UngV9DzpJIRSU6p02aShNaTXhDExtY,3457
13
- polyapi/function_cli.py,sha256=hv5K5niegqitT6VwbS7M5ec3nEMyqwVtE6tcpwHoxIk,4125
14
- polyapi/generate.py,sha256=1ZwcUEfhYLc64Wh5aYhvU6P594HOL2LYycPKkH39frc,15394
13
+ polyapi/function_cli.py,sha256=H0sVrbvRBXw_xeApe2MvQw8p_xE7jVTTOU-07Dg041A,4220
14
+ polyapi/generate.py,sha256=zLS3P6qqmy92lb1lryIB_pE2IUp_ePh7jIsUy3EJecQ,16125
15
15
  polyapi/parser.py,sha256=mdoh4pNq8pyiHE0-i6Coqj8frEXfBLRk6itpAXMrrgI,20373
16
16
  polyapi/poly_schemas.py,sha256=T4kfZyfgVLiqLD28GmYNiHnrNx77J_HO4uzk8LUAhlo,3137
17
17
  polyapi/prepare.py,sha256=t-Gj5SrLokUuAJ70IKY6myK_OoJ-N7SazeIMlu5cmuc,7396
@@ -24,8 +24,8 @@ polyapi/typedefs.py,sha256=MGDwWaijLNqokXF9UCHGAP-yKixOzztrH4Lsj800AJs,2328
24
24
  polyapi/utils.py,sha256=1F7Dwst_PbPuUBUSxx5r8d2DHDgqHtu07QW92T_YSdw,12454
25
25
  polyapi/variables.py,sha256=j7WWrGLr2O5SkWGxnsusnnfl25kVL3b6SQYcVGEoC8c,4277
26
26
  polyapi/webhook.py,sha256=NTSXYOl_QqsFekWRepPyVTsV9SVkgUu0HfG1SJJDHOE,4958
27
- polyapi_python-0.3.8.dev1.dist-info/licenses/LICENSE,sha256=6b_I7aPVp8JXhqQwdw7_B84Ca0S4JGjHj0sr_1VOdB4,1068
28
- polyapi_python-0.3.8.dev1.dist-info/METADATA,sha256=xDnbtcsNeG5SyystGCPuFMXxChLiloGwaE1HMO2do6U,5782
29
- polyapi_python-0.3.8.dev1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
30
- polyapi_python-0.3.8.dev1.dist-info/top_level.txt,sha256=CEFllOnzowci_50RYJac-M54KD2IdAptFsayVVF_f04,8
31
- polyapi_python-0.3.8.dev1.dist-info/RECORD,,
27
+ polyapi_python-0.3.8.dev2.dist-info/licenses/LICENSE,sha256=6b_I7aPVp8JXhqQwdw7_B84Ca0S4JGjHj0sr_1VOdB4,1068
28
+ polyapi_python-0.3.8.dev2.dist-info/METADATA,sha256=XuaptRLFeUrF0g2r4OcDZ-cLLb5fsfEj8qDzUSepQ6s,5782
29
+ polyapi_python-0.3.8.dev2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
30
+ polyapi_python-0.3.8.dev2.dist-info/top_level.txt,sha256=CEFllOnzowci_50RYJac-M54KD2IdAptFsayVVF_f04,8
31
+ polyapi_python-0.3.8.dev2.dist-info/RECORD,,