polyapi-python 0.2.5.dev13__py3-none-any.whl → 0.2.6.dev1__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
@@ -27,6 +27,7 @@ def execute_from_cli() -> None:
27
27
  parser.add_argument("--client", action="store_true", help="Pass --client when adding function to add a client function.")
28
28
  parser.add_argument("--server", action="store_true", help="Pass --server when adding function to add a server function.")
29
29
  parser.add_argument("--logs", action="store_true", help="Pass --logs when adding function if you want to store and see the function logs.")
30
+ parser.add_argument("--skip-generate", action="store_true", help="Pass --skip-generate to skip generating the library after adding a function.")
30
31
  parser.add_argument("command", choices=CLI_COMMANDS)
31
32
  parser.add_argument("subcommands", nargs="*")
32
33
  args = parser.parse_args()
@@ -55,4 +56,4 @@ def execute_from_cli() -> None:
55
56
  print("Clearing the generated library...")
56
57
  clear()
57
58
  elif command == "function":
58
- function_add_or_update(args.context, args.description, args.client, args.server, args.logs, args.subcommands)
59
+ function_add_or_update(args.context, args.description, args.client, args.server, args.logs, args.subcommands, not args.skip_generate)
polyapi/function_cli.py CHANGED
@@ -207,6 +207,7 @@ def function_add_or_update(
207
207
  server: bool,
208
208
  logs_enabled: bool,
209
209
  subcommands: List,
210
+ generate: bool = True,
210
211
  ):
211
212
  parser = argparse.ArgumentParser()
212
213
  parser.add_argument("subcommand", choices=["add"])
@@ -268,10 +269,11 @@ def function_add_or_update(
268
269
  print_green("DEPLOYED")
269
270
  function_id = resp.json()["id"]
270
271
  print(f"Function ID: {function_id}")
271
- print("Generating new custom function...", end="")
272
- functions = get_functions_and_parse(limit_ids=[function_id])
273
- generate_functions(functions)
274
- print_green("DONE")
272
+ if generate:
273
+ print("Generating new custom function...", end="")
274
+ functions = get_functions_and_parse(limit_ids=[function_id])
275
+ generate_functions(functions)
276
+ print_green("DONE")
275
277
  else:
276
278
  print("Error adding function.")
277
279
  print(resp.status_code)
polyapi/generate.py CHANGED
@@ -11,7 +11,7 @@ from polyapi.webhook import render_webhook_handle
11
11
  from .typedefs import PropertySpecification, SpecificationDto, VariableSpecDto
12
12
  from .api import render_api_function
13
13
  from .server import render_server_function
14
- from .utils import add_import_to_init, get_auth_headers, init_the_init
14
+ from .utils import add_import_to_init, get_auth_headers, init_the_init, to_func_namespace
15
15
  from .variables import generate_variables
16
16
  from .config import get_api_key_and_url, initialize_config
17
17
 
@@ -232,10 +232,10 @@ def add_function_file(
232
232
  # add function to init
233
233
  init_path = os.path.join(full_path, "__init__.py")
234
234
  with open(init_path, "a") as f:
235
- f.write(f"\n\nfrom . import _{function_name}\n\n{func_str}")
235
+ f.write(f"\n\nfrom . import {to_func_namespace(function_name)}\n\n{func_str}")
236
236
 
237
237
  # add type_defs to underscore file
238
- file_path = os.path.join(full_path, f"_{function_name}.py")
238
+ file_path = os.path.join(full_path, f"{to_func_namespace(function_name)}.py")
239
239
  with open(file_path, "w") as f:
240
240
  f.write(func_type_defs)
241
241
 
polyapi/utils.py CHANGED
@@ -75,11 +75,11 @@ def add_type_import_path(function_name: str, arg: str) -> str:
75
75
  else:
76
76
  if '"' in sub:
77
77
  sub = sub.replace('"', "")
78
- return f'List["_{function_name}.{camelCase(sub)}"]'
78
+ return f'List["{to_func_namespace(function_name)}.{camelCase(sub)}"]'
79
79
  else:
80
- return f'List[_{function_name}.{camelCase(sub)}]'
80
+ return f'List[{to_func_namespace(function_name)}.{camelCase(sub)}]'
81
81
 
82
- return f'_{function_name}.{camelCase(arg)}'
82
+ return f'{to_func_namespace(function_name)}.{camelCase(arg)}'
83
83
 
84
84
 
85
85
  def get_type_and_def(type_spec: PropertyType) -> Tuple[str, str]:
@@ -183,4 +183,18 @@ def poly_full_path(context, name) -> str:
183
183
  path = context + "." + name
184
184
  else:
185
185
  path = name
186
- return f"poly.{path}"
186
+ return f"poly.{path}"
187
+
188
+
189
+ RESERVED_TYPES = {"List", "Dict", "Any", "Optional", "Callable"}
190
+
191
+
192
+ def to_func_namespace(s: str) -> str:
193
+ """ convert a function name to some function namespace
194
+ by default it is
195
+ """
196
+ rv = s[0].upper() + s[1:]
197
+ if rv in RESERVED_TYPES:
198
+ return "_" + rv
199
+ else:
200
+ return rv
polyapi/webhook.py CHANGED
@@ -6,7 +6,7 @@ from typing import Any, Dict, List, Tuple
6
6
 
7
7
  from polyapi.config import get_api_key_and_url
8
8
  from polyapi.typedefs import PropertySpecification
9
- from polyapi.utils import parse_arguments, poly_full_path
9
+ from polyapi.utils import parse_arguments, poly_full_path, to_func_namespace
10
10
 
11
11
  # all active webhook handlers, used by unregister_all to cleanup
12
12
  active_handlers: List[Dict[str, Any]] = []
@@ -124,7 +124,7 @@ def render_webhook_handle(
124
124
 
125
125
  if "WebhookEventType" in function_args:
126
126
  # let's add the function name import!
127
- function_args = function_args.replace("WebhookEventType", f"_{function_name}.WebhookEventType")
127
+ function_args = function_args.replace("WebhookEventType", f"{to_func_namespace(function_name)}.WebhookEventType")
128
128
 
129
129
  func_str = WEBHOOK_TEMPLATE.format(
130
130
  description=function_description,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: polyapi-python
3
- Version: 0.2.5.dev13
3
+ Version: 0.2.6.dev1
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,25 +2,25 @@ polyapi/__init__.py,sha256=5iujRodfgRyLxT-zY0L3xax3rKRvfSt4NZlZYKOz03w,608
2
2
  polyapi/__main__.py,sha256=V4zhAh_YGxno5f_KSrlkELxcuDh9bR3WSd0n-2r-qQQ,93
3
3
  polyapi/api.py,sha256=bE651P47RuhqNYkVyvTH_pA44JypRZED_2M5UG_qzDI,1863
4
4
  polyapi/auth.py,sha256=zrIGatjba5GwUTNjKj1GHQWTEDP9B-HrSzCKbLFoqvc,5336
5
- polyapi/cli.py,sha256=QYsZmsnVLsf4LgE4iN7Tse1rrlTpycgG9nuL3Uoq9HU,2484
5
+ polyapi/cli.py,sha256=ZiOkD9DmlixxPvxfk1JQGoQwXv9Zf2cxk-J1ZMZN6IA,2657
6
6
  polyapi/client.py,sha256=w15XOABkwdL4V4r2iWY_nypzLjvoKVuux8jUKbA16pQ,1329
7
7
  polyapi/config.py,sha256=S8TU10upy5OW1_vX-CqQTJD-ZOB6329aMjiUCmukfUI,2292
8
8
  polyapi/constants.py,sha256=sc-FnS0SngBLvSu1ZWMs0UCf9EYD1u1Yhfr-sZXGLns,607
9
9
  polyapi/error_handler.py,sha256=I_e0iz6VM23FLVQWJljxs2NGcl_OODbi43OcbnqBlp8,2398
10
10
  polyapi/exceptions.py,sha256=Zh7i7eCUhDuXEdUYjatkLFTeZkrx1BJ1P5ePgbJ9eIY,89
11
11
  polyapi/execute.py,sha256=kXnvlNQ7nz9cRlV2_5gXH09UCmyiDP5zi3wiAw0uDuk,1943
12
- polyapi/function_cli.py,sha256=F0cb5MGcmFvspgwxptWq_2e50X5NNno0B0p8Vgu_oNI,9129
13
- polyapi/generate.py,sha256=dtS6Wyb_lq9FrOs7NA_ceKCX9rogx2_3Fp57_hGwdDc,7957
12
+ polyapi/function_cli.py,sha256=NE8CT1E22PC5DorVWJefXsBBGUnpSIsUyhHla02SV4k,9193
13
+ polyapi/generate.py,sha256=LN2Z6fE-HfpMsXlkJfOl8bqZdR3fUythE_ZsAe15tmk,8012
14
14
  polyapi/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
15
15
  polyapi/rendered_spec.py,sha256=JIsFkqAhYEtKa3-ToTli_th_wLbJpxgr_eYOMz4Z7yY,2345
16
16
  polyapi/schema.py,sha256=qxzuWhpDLyO4eGutiaWHGVL9sT46-kVE3r4xByIwGVI,3662
17
17
  polyapi/server.py,sha256=n-nMGjXoq9T9ZwE2EBDkAaxJ7UytConGaHthkjbkCXA,1894
18
18
  polyapi/typedefs.py,sha256=mRqwd2LKofxNn_VSKxBzixni2j-tai8mfTQ0Wi2aLNM,1487
19
- polyapi/utils.py,sha256=f003Y5qP1uuyMKrvvaIUYS1TSGfSZjLnwPiXR5o4eA8,6530
19
+ polyapi/utils.py,sha256=JtL_v0PVkJBlTeRu0gIV5IDScqoiggS8m-VcS4HN22c,6890
20
20
  polyapi/variables.py,sha256=d36-trnfTL_8m2NkorMiImb4O3UrJbiFV38CHxV5i0A,4200
21
- polyapi/webhook.py,sha256=GvnS49Vl4k5STTvv4KKUnUAyn27OhIHHXChFmiI53Cs,4849
22
- polyapi_python-0.2.5.dev13.dist-info/LICENSE,sha256=Hi0kDr56Dsy0uYIwNt4r9G7tI8x8miXRTlyvbeplCP8,1068
23
- polyapi_python-0.2.5.dev13.dist-info/METADATA,sha256=45skR2rTfVlxzxk-IUFBVP5g5dO7mlA8KNDOR3g59Is,4868
24
- polyapi_python-0.2.5.dev13.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
25
- polyapi_python-0.2.5.dev13.dist-info/top_level.txt,sha256=CEFllOnzowci_50RYJac-M54KD2IdAptFsayVVF_f04,8
26
- polyapi_python-0.2.5.dev13.dist-info/RECORD,,
21
+ polyapi/webhook.py,sha256=LWv28c2MLz_OKBI_Nn7WR4C-gs1SWgbdXsoxIIf-9UI,4886
22
+ polyapi_python-0.2.6.dev1.dist-info/LICENSE,sha256=Hi0kDr56Dsy0uYIwNt4r9G7tI8x8miXRTlyvbeplCP8,1068
23
+ polyapi_python-0.2.6.dev1.dist-info/METADATA,sha256=98yrjJMCmcYSHOsXQ-JY2OY_Tah6CPDr3vHNfAuoObM,4867
24
+ polyapi_python-0.2.6.dev1.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
25
+ polyapi_python-0.2.6.dev1.dist-info/top_level.txt,sha256=CEFllOnzowci_50RYJac-M54KD2IdAptFsayVVF_f04,8
26
+ polyapi_python-0.2.6.dev1.dist-info/RECORD,,