polyapi-python 0.2.3.dev3__py3-none-any.whl → 0.2.3.dev5__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/function_cli.py CHANGED
@@ -3,7 +3,7 @@ import argparse
3
3
  import json
4
4
  import types
5
5
  import sys
6
- from typing import Dict, List, Tuple
6
+ from typing import Dict, List, Mapping, Optional, Tuple
7
7
  from typing_extensions import _TypedDictMeta # type: ignore
8
8
  import requests
9
9
  from stdlib_list import stdlib_list
@@ -18,7 +18,7 @@ import importlib
18
18
 
19
19
  # these libraries are already installed in the base docker image
20
20
  # and shouldnt be included in additional requirements
21
- BASE_REQUIREMENTS = {"polyapi", "requests", "typing_extensions", "jsonschema-gentypes", "pydantic"}
21
+ BASE_REQUIREMENTS = {"polyapi", "requests", "typing_extensions", "jsonschema-gentypes", "pydantic", "cloudevents"}
22
22
  all_stdlib_symbols = stdlib_list('.'.join([str(v) for v in sys.version_info[0:2]]))
23
23
  BASE_REQUIREMENTS.update(all_stdlib_symbols) # dont need to pip install stuff in the python standard library
24
24
 
@@ -104,6 +104,19 @@ def _get_type(expr: ast.expr | None, schemas: List[Dict]) -> Tuple[str, Dict | N
104
104
  return json_type, _get_type_schema(json_type, python_type, schemas)
105
105
 
106
106
 
107
+ def _get_req_name_if_not_in_base(n: Optional[str], pip_name_lookup: Mapping[str, List[str]]) -> Optional[str]:
108
+ if not n:
109
+ return None
110
+
111
+ if "." in n:
112
+ n = n.split(".")[0]
113
+
114
+ if n in BASE_REQUIREMENTS:
115
+ return None
116
+ else:
117
+ return pip_name_lookup[n][0]
118
+
119
+
107
120
  def _parse_code(code: str, function_name: str):
108
121
  parsed_args = []
109
122
  return_type = None
@@ -121,13 +134,16 @@ def _parse_code(code: str, function_name: str):
121
134
 
122
135
  for node in ast.iter_child_nodes(parsed_code):
123
136
  if isinstance(node, ast.Import):
137
+ # TODO maybe handle `import foo.bar` case?
124
138
  for name in node.names:
125
- if name.name not in BASE_REQUIREMENTS:
126
- requirements.append(name.name)
139
+ req = _get_req_name_if_not_in_base(name.name, pip_name_lookup)
140
+ if req:
141
+ requirements.append(req)
127
142
  elif isinstance(node, ast.ImportFrom):
128
- if node.module and node.module not in BASE_REQUIREMENTS:
129
- req = pip_name_lookup[node.module][0]
130
- requirements.append(req)
143
+ if node.module:
144
+ req = _get_req_name_if_not_in_base(node.module, pip_name_lookup)
145
+ if req:
146
+ requirements.append(req)
131
147
 
132
148
  elif isinstance(node, ast.FunctionDef) and node.name == function_name:
133
149
  function_args = [arg for arg in node.args.args]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: polyapi-python
3
- Version: 0.2.3.dev3
3
+ Version: 0.2.3.dev5
4
4
  Summary: The PolyAPI Python Client
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.31.0
32
32
  Requires-Dist: typing-extensions ==4.10.0
33
33
  Requires-Dist: jsonschema-gentypes ==2.4.0
34
- Requires-Dist: pydantic ==2.5.3
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
@@ -8,7 +8,7 @@ polyapi/constants.py,sha256=NGjso6K5rGnE8TGdrXmdEfvvr-HI3DTVGwOYiWO68LM,511
8
8
  polyapi/error_handler.py,sha256=vl6ZBtsHmC3eu13IMpmZEXBTDJbrPrzmViBCCrEspd4,1621
9
9
  polyapi/exceptions.py,sha256=Zh7i7eCUhDuXEdUYjatkLFTeZkrx1BJ1P5ePgbJ9eIY,89
10
10
  polyapi/execute.py,sha256=06XWTxGJqtsDiLY10RjRebIMFRfhtAIMmBRbuWu3e8A,1873
11
- polyapi/function_cli.py,sha256=x1nAnBQVpjhCDUd_eazQ7HTLgpsNFcY9p6YHy-8iv5E,7660
11
+ polyapi/function_cli.py,sha256=--K-9qYzGjhfg_HxTUwlnQOpDNwt5dkTadQFLUxGr4g,8097
12
12
  polyapi/generate.py,sha256=ZZVkA3uL5yPWisnFhIBjoFAYfr96h9m6I0XOCbEpiyk,8970
13
13
  polyapi/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
14
14
  polyapi/schema.py,sha256=1a7nIO867Xy3bagmPUNdYMxtS5OoCAv8oKIbYgj55dk,2957
@@ -17,8 +17,8 @@ polyapi/typedefs.py,sha256=RZ3I6sgJm_5MuuORG1QjUE-UJy_z2WRXNdiWjEdLvQg,1371
17
17
  polyapi/utils.py,sha256=wZQrwSOst5wyoYYLoMk1DnAEbVsJ0-2YkmmDQ9gI3FY,5399
18
18
  polyapi/variables.py,sha256=d36-trnfTL_8m2NkorMiImb4O3UrJbiFV38CHxV5i0A,4200
19
19
  polyapi/webhook.py,sha256=A89eNnYcVpVe9doJPDLfscIhF-C7Q2AI3vu-SzGxMBg,2923
20
- polyapi_python-0.2.3.dev3.dist-info/LICENSE,sha256=Hi0kDr56Dsy0uYIwNt4r9G7tI8x8miXRTlyvbeplCP8,1068
21
- polyapi_python-0.2.3.dev3.dist-info/METADATA,sha256=S_sQaLzN8kWw5UrytVLor2fargI-U23dD_d6A3DEigo,4823
22
- polyapi_python-0.2.3.dev3.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
23
- polyapi_python-0.2.3.dev3.dist-info/top_level.txt,sha256=CEFllOnzowci_50RYJac-M54KD2IdAptFsayVVF_f04,8
24
- polyapi_python-0.2.3.dev3.dist-info/RECORD,,
20
+ polyapi_python-0.2.3.dev5.dist-info/LICENSE,sha256=Hi0kDr56Dsy0uYIwNt4r9G7tI8x8miXRTlyvbeplCP8,1068
21
+ polyapi_python-0.2.3.dev5.dist-info/METADATA,sha256=yLnKqdRKrPJAv2WFXTTsw5z82-_vQKohRRw1fOdNsTw,4823
22
+ polyapi_python-0.2.3.dev5.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
23
+ polyapi_python-0.2.3.dev5.dist-info/top_level.txt,sha256=CEFllOnzowci_50RYJac-M54KD2IdAptFsayVVF_f04,8
24
+ polyapi_python-0.2.3.dev5.dist-info/RECORD,,