polyapi-python 0.3.1.dev16__py3-none-any.whl → 0.3.2__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
@@ -21,7 +21,7 @@ def execute_from_cli():
21
21
  description="Manage your Poly API configurations and functions",
22
22
  formatter_class=argparse.RawTextHelpFormatter
23
23
  )
24
-
24
+
25
25
  subparsers = parser.add_subparsers(help="Available commands")
26
26
 
27
27
  ###########################################################################
@@ -66,13 +66,13 @@ def execute_from_cli():
66
66
  fn_add_parser.add_argument("--description", required=False, default="", help="Description of the function")
67
67
  fn_add_parser.add_argument("--server", action="store_true", help="Marks the function as a server function")
68
68
  fn_add_parser.add_argument("--client", action="store_true", help="Marks the function as a client function")
69
- fn_add_parser.add_argument("--logs", choices=["enabled", "disabled"], default="disabled", help="Enable or disable logs for the function.")
69
+ fn_add_parser.add_argument("--logs", choices=["enabled", "disabled"], default=None, help="Enable or disable logs for the function.")
70
70
  fn_add_parser.add_argument("--execution-api-key", required=False, default="", help="API key for execution (for server functions only).")
71
71
  fn_add_parser.add_argument("--disable-ai", "--skip-generate", action="store_true", help="Pass --disable-ai skip AI generation of missing descriptions")
72
72
 
73
73
  def add_function(args):
74
74
  initialize_config()
75
- logs_enabled = args.logs == "enabled"
75
+ logs_enabled = args.logs == "enabled" if args.logs else None
76
76
  err = ""
77
77
  if args.server and args.client:
78
78
  err = "Specify either `--server` or `--client`. Found both."
polyapi/deployables.py CHANGED
@@ -245,7 +245,7 @@ def update_deployment_comments(file_content: str, deployable: dict) -> str:
245
245
  if deployable['deployments']:
246
246
  deployment_comments = write_deploy_comments(deployable['deployments'])
247
247
  deployable['deploymentCommentRanges'] = [(0, len(deployment_comments) + 1)]
248
- file_content = f"{deployment_comments}{file_content}"
248
+ file_content = f"{deployment_comments}\n{file_content}"
249
249
  return file_content
250
250
 
251
251
  def update_deployable_function_comments(file_content: str, deployable: dict, disable_docs: bool = False) -> str:
@@ -261,7 +261,7 @@ def update_deployable_function_comments(file_content: str, deployable: dict, dis
261
261
  if deployable["docStartIndex"] == deployable["docEndIndex"]:
262
262
  # Function doesn't yet have any docstrings so we need to add additional whitespace
263
263
  docstring = " " + docstring + "\n"
264
-
264
+
265
265
  return f"{file_content[:deployable['docStartIndex']]}{docstring}{file_content[deployable['docEndIndex']:]}"
266
266
  return file_content
267
267
 
@@ -271,17 +271,17 @@ def write_updated_deployable(deployable: dict, disable_docs: bool = False) -> di
271
271
  """
272
272
  with open(deployable['file'], 'r', encoding='utf-8') as file:
273
273
  file_contents = file.read()
274
-
274
+
275
275
  if deployable['type'] in ['client-function', 'server-function']:
276
276
  file_contents = update_deployable_function_comments(file_contents, deployable, disable_docs)
277
277
  else:
278
278
  raise ValueError(f"Unsupported deployable type: '{deployable['type']}'")
279
279
 
280
280
  file_contents = update_deployment_comments(file_contents, deployable)
281
-
281
+
282
282
  with open(deployable['file'], 'w', encoding='utf-8') as file:
283
283
  file.write(file_contents)
284
-
284
+
285
285
  deployable['fileRevision'] = get_deployable_file_revision(file_contents)
286
286
  return deployable
287
287
 
polyapi/function_cli.py CHANGED
@@ -1,5 +1,5 @@
1
1
  import sys
2
- from typing import Any, List
2
+ from typing import Any, List, Optional
3
3
  import requests
4
4
  from polyapi.generate import get_functions_and_parse, generate_functions
5
5
  from polyapi.config import get_api_key_and_url
@@ -23,7 +23,7 @@ def function_add_or_update(
23
23
  description: str,
24
24
  client: bool,
25
25
  server: bool,
26
- logs_enabled: bool,
26
+ logs_enabled: Optional[bool],
27
27
  generate: bool = True,
28
28
  execution_api_key: str = ""
29
29
  ):
@@ -45,6 +45,9 @@ def function_add_or_update(
45
45
  )
46
46
  sys.exit(1)
47
47
 
48
+ if logs_enabled is None:
49
+ logs_enabled = parsed["config"].get("logs_enabled", None)
50
+
48
51
  data = {
49
52
  "context": context or parsed["context"],
50
53
  "name": name,
@@ -52,9 +55,8 @@ def function_add_or_update(
52
55
  "code": code,
53
56
  "language": "python",
54
57
  "returnType": get_jsonschema_type(return_type),
55
- "returnTypeSchema": parsed["types"]["returns"]["typeSchema"],
56
- "arguments": [{**p, "key": p["name"], "type": get_jsonschema_type(p["type"]) } for p in parsed["types"]["params"]],
57
- "logsEnabled": logs_enabled or parsed["config"].get("logs_enabled", False),
58
+ "arguments": [{**p, "key": p["name"], "type": get_jsonschema_type(p["type"])} for p in parsed["types"]["params"]],
59
+ "logsEnabled": logs_enabled,
58
60
  }
59
61
 
60
62
  if server and parsed["dependencies"]:
polyapi/parser.py CHANGED
@@ -47,7 +47,7 @@ def _parse_sphinx_docstring(docstring: str) -> Dict[str, Any]:
47
47
  "type": "Any"
48
48
  }
49
49
  current_section = None
50
-
50
+
51
51
  for line in lines:
52
52
  stripped_line = line.strip()
53
53
  if stripped_line.startswith(":param "):
@@ -56,7 +56,7 @@ def _parse_sphinx_docstring(docstring: str) -> Dict[str, Any]:
56
56
  param_name = param_name.strip()
57
57
  if param_name in params:
58
58
  params[param_name]["description"] = param_desc.strip()
59
- else:
59
+ else:
60
60
  params[param_name] = { "name": param_name, "type": "", "description": param_desc.strip() }
61
61
  current_section = param_name
62
62
 
@@ -118,7 +118,7 @@ def _parse_google_docstring(docstring: str) -> Dict[str, Any]:
118
118
  for line in lines:
119
119
  line = line.rstrip()
120
120
  section_match = section_pattern.match(line)
121
-
121
+
122
122
  if section_match:
123
123
  mode = section_match.group(1).lower()
124
124
  continue
@@ -181,7 +181,7 @@ def _get_schemas(code: str) -> List[Dict]:
181
181
 
182
182
  def get_jsonschema_type(python_type: str):
183
183
  if python_type == "Any":
184
- return "Any"
184
+ return "any"
185
185
 
186
186
  if python_type == "List":
187
187
  return "array"
@@ -338,6 +338,7 @@ def parse_function_code(code: str, name: Optional[str] = "", context: Optional[s
338
338
  "params": [],
339
339
  "returns": {
340
340
  "type": "",
341
+ "typeSchema": None,
341
342
  "description": "",
342
343
  }
343
344
  },
@@ -364,7 +365,7 @@ def parse_function_code(code: str, name: Optional[str] = "", context: Optional[s
364
365
  self._line_offsets.append(
365
366
  self._line_offsets[i-1] + len(self._lines[i-1])
366
367
  )
367
-
368
+
368
369
  self._extract_deploy_comments()
369
370
 
370
371
  def visit_AnnAssign(self, node):
@@ -435,13 +436,14 @@ def parse_function_code(code: str, name: Optional[str] = "", context: Optional[s
435
436
 
436
437
  def _extract_deploy_comments(self):
437
438
  for i in range(len(self._lines)):
438
- line = self._lines[i].strip()
439
+ line = self._lines[i]
439
440
  if line and not line.startswith("#"):
440
441
  return
441
- deployment = _parse_deploy_comment(line)
442
+ deployment = _parse_deploy_comment(line.strip())
442
443
  if deployment:
444
+ start = self._line_offsets[i]
443
445
  deployable["deployments"].append(deployment)
444
- deployable["deploymentCommentRanges"].append([self._line_offsets[i], len(line)])
446
+ deployable["deploymentCommentRanges"].append([start, start + len(line)])
445
447
 
446
448
  def visit_Import(self, node: ast.Import):
447
449
  # TODO maybe handle `import foo.bar` case?
@@ -471,8 +473,7 @@ def parse_function_code(code: str, name: Optional[str] = "", context: Optional[s
471
473
  "type": python_type,
472
474
  "description": "",
473
475
  }
474
- if type_schema:
475
- json_arg["typeSchema"] = json.dumps(type_schema)
476
+ json_arg["typeSchema"] = json.dumps(type_schema) if type_schema else None
476
477
 
477
478
  if docstring_params:
478
479
  try:
@@ -482,7 +483,7 @@ def parse_function_code(code: str, name: Optional[str] = "", context: Optional[s
482
483
  if docstring_params[type_index]["type"] != python_type:
483
484
  deployable["dirty"] = True
484
485
  except:
485
- pass
486
+ pass
486
487
  else:
487
488
  deployable["dirty"] = True
488
489
 
@@ -496,7 +497,7 @@ def parse_function_code(code: str, name: Optional[str] = "", context: Optional[s
496
497
  deployable["types"]["returns"]["typeSchema"] = return_type_schema
497
498
  else:
498
499
  deployable["types"]["returns"]["type"] = "Any"
499
-
500
+
500
501
  def generic_visit(self, node):
501
502
  if hasattr(node, 'lineno') and hasattr(node, 'col_offset'):
502
503
  self._current_offset = self._line_offsets[node.lineno - 1] + node.col_offset
polyapi/sync.py CHANGED
@@ -84,7 +84,9 @@ def sync_deployable(deployable: SyncDeployment) -> Deployment:
84
84
  "fileRevision": deployable["fileRevision"],
85
85
  }
86
86
 
87
- def sync_deployables(dry_run: bool, instance: str = os.getenv('POLY_API_BASE_URL')):
87
+ def sync_deployables(dry_run: bool, instance: str | None = None):
88
+ if not instance:
89
+ _, instance = get_api_key_and_url()
88
90
  prepare_deployable_directory()
89
91
  git_revision = get_cache_deployments_revision()
90
92
  all_deployables = load_deployable_records()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: polyapi-python
3
- Version: 0.3.1.dev16
3
+ Version: 0.3.2
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
@@ -29,7 +29,7 @@ Requires-Python: >=3.10
29
29
  Description-Content-Type: text/markdown
30
30
  License-File: LICENSE
31
31
  Requires-Dist: requests==2.31.0
32
- Requires-Dist: typing_extensions==4.10.0
32
+ Requires-Dist: typing_extensions>=4.10.0
33
33
  Requires-Dist: jsonschema-gentypes==2.6.0
34
34
  Requires-Dist: pydantic==2.6.4
35
35
  Requires-Dist: stdlib_list==0.10.0
@@ -2,29 +2,29 @@ polyapi/__init__.py,sha256=a1Poy1kaTncYnUg6nWRcTjVm-R1CUQk12UX7VYQ9d5k,616
2
2
  polyapi/__main__.py,sha256=V4zhAh_YGxno5f_KSrlkELxcuDh9bR3WSd0n-2r-qQQ,93
3
3
  polyapi/api.py,sha256=e-8nOzq6SXD7_YPVBlW82_9wVxDCc8XD9ioMv_QvnH0,1877
4
4
  polyapi/auth.py,sha256=zrIGatjba5GwUTNjKj1GHQWTEDP9B-HrSzCKbLFoqvc,5336
5
- polyapi/cli.py,sha256=nhqJ437ICZWKcP31hcn6YdzrhSFDXEDn1tTJ5TnubEM,8307
5
+ polyapi/cli.py,sha256=GyZWdTPXnOL_gKBPIBk4EiGyyi76vcI9_vrU0q_RWb8,8320
6
6
  polyapi/client.py,sha256=CoFDYvyKsqL4wPQbUDIr0Qb8Q5eD92xN4OEEcJEVuGQ,1296
7
7
  polyapi/config.py,sha256=uvEvOfWYZTLmBmZX-5jJxCzWPpwzVmEOIiQIdi98P4Y,3015
8
8
  polyapi/constants.py,sha256=sc-FnS0SngBLvSu1ZWMs0UCf9EYD1u1Yhfr-sZXGLns,607
9
- polyapi/deployables.py,sha256=74Bs2kDhyoQhezc0I1V4pi7l-SYg7_zpYrXYPjAePMw,11954
9
+ polyapi/deployables.py,sha256=WVcNNB6W5ZW_-ukf_kK3moRcnwIkC-O4te6vLepjcco,11936
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=kXnvlNQ7nz9cRlV2_5gXH09UCmyiDP5zi3wiAw0uDuk,1943
13
- polyapi/function_cli.py,sha256=mRXCdxleID4hQhrRzVNZOm8MFmKIfo8Ru7bZcBPnsOY,4186
13
+ polyapi/function_cli.py,sha256=i6q9V3vHIFlhfwu4QNI6adygxW07G08ZxIroJqLe89I,4183
14
14
  polyapi/generate.py,sha256=SIRfN7RF3Z7eQ8kSNg4H70LeT7Hmh-Mn5maibvM7kAM,7969
15
- polyapi/parser.py,sha256=rtI4-SR6v7mqG2vF_P6qgC-qn-M_QG-e95PJUZv92cc,20248
15
+ polyapi/parser.py,sha256=Dqkg7cy9yae9HP4WcPtNzyZxrUrtDsGshFYW-vPvTzE,20263
16
16
  polyapi/prepare.py,sha256=Q8CWV4kmZ2dbXYVsud34AgJkj5ymcQ_IcYhLuikc9yk,6659
17
17
  polyapi/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
18
18
  polyapi/rendered_spec.py,sha256=uaNzBhP4cX7iGfKwzZv0dxMagWzsGeDr0cQYx_AyIhQ,2153
19
19
  polyapi/schema.py,sha256=VVMHAT5yU47cRC7xF44BrmUSemlk5oIKSxH2HTVPaQ8,3169
20
20
  polyapi/server.py,sha256=NzQCZFSAJK7XiRw1kiU_i9uMvgYK7i8qh7UX2xjytJU,1908
21
- polyapi/sync.py,sha256=tv86d6rbA9z_IliX-_esoxry6Ho_DkkVqv3BhiOZcXs,6430
21
+ polyapi/sync.py,sha256=PGdC0feBBjEVrF3d9EluW_OAxbWuzSrfh84czma8kWg,6476
22
22
  polyapi/typedefs.py,sha256=U0i30Y9CgoUBWeMUbpM28S8eVOEU9NfdckK1VAop3A0,1994
23
23
  polyapi/utils.py,sha256=jzCh-ivKMcgp5fIXynhYmP9UyzsISr9bGGEzdPP8n3w,7644
24
24
  polyapi/variables.py,sha256=d36-trnfTL_8m2NkorMiImb4O3UrJbiFV38CHxV5i0A,4200
25
25
  polyapi/webhook.py,sha256=LWv28c2MLz_OKBI_Nn7WR4C-gs1SWgbdXsoxIIf-9UI,4886
26
- polyapi_python-0.3.1.dev16.dist-info/LICENSE,sha256=Hi0kDr56Dsy0uYIwNt4r9G7tI8x8miXRTlyvbeplCP8,1068
27
- polyapi_python-0.3.1.dev16.dist-info/METADATA,sha256=HguVVBsKLZE9v7_k8_R3d3CMGPSHmKmc0QlSj07sbfw,5327
28
- polyapi_python-0.3.1.dev16.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
29
- polyapi_python-0.3.1.dev16.dist-info/top_level.txt,sha256=CEFllOnzowci_50RYJac-M54KD2IdAptFsayVVF_f04,8
30
- polyapi_python-0.3.1.dev16.dist-info/RECORD,,
26
+ polyapi_python-0.3.2.dist-info/LICENSE,sha256=Hi0kDr56Dsy0uYIwNt4r9G7tI8x8miXRTlyvbeplCP8,1068
27
+ polyapi_python-0.3.2.dist-info/METADATA,sha256=v6_MrKsOJFe1W7nLbnYUP6K83dtac3SP2K4H9-0vTEI,5321
28
+ polyapi_python-0.3.2.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
29
+ polyapi_python-0.3.2.dist-info/top_level.txt,sha256=CEFllOnzowci_50RYJac-M54KD2IdAptFsayVVF_f04,8
30
+ polyapi_python-0.3.2.dist-info/RECORD,,