polyapi-python 0.2.3.dev1__py3-none-any.whl → 0.2.3.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/function_cli.py CHANGED
@@ -8,6 +8,7 @@ from typing_extensions import _TypedDictMeta # type: ignore
8
8
  import requests
9
9
  from stdlib_list import stdlib_list
10
10
  from pydantic import TypeAdapter
11
+ from importlib.metadata import packages_distributions
11
12
  from polyapi.generate import get_functions_and_parse, generate_functions
12
13
  from polyapi.config import get_api_key_and_url
13
14
  from polyapi.constants import PYTHON_TO_JSONSCHEMA_TYPE_MAP
@@ -112,6 +113,12 @@ def _parse_code(code: str, function_name: str):
112
113
  schemas = _get_schemas(code)
113
114
 
114
115
  parsed_code = ast.parse(code)
116
+
117
+ # the pip name and the import name might be different
118
+ # e.g. kube_hunter is the import name, but the pip name is kube-hunter
119
+ # see https://stackoverflow.com/a/75144378
120
+ pip_name_lookup = packages_distributions()
121
+
115
122
  for node in ast.iter_child_nodes(parsed_code):
116
123
  if isinstance(node, ast.Import):
117
124
  for name in node.names:
@@ -119,7 +126,8 @@ def _parse_code(code: str, function_name: str):
119
126
  requirements.append(name.name)
120
127
  elif isinstance(node, ast.ImportFrom):
121
128
  if node.module and node.module not in BASE_REQUIREMENTS:
122
- requirements.append(node.module)
129
+ req = pip_name_lookup[node.module][0]
130
+ requirements.append(req)
123
131
 
124
132
  elif isinstance(node, ast.FunctionDef) and node.name == function_name:
125
133
  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.dev1
3
+ Version: 0.2.3.dev2
4
4
  Summary: The PolyAPI Python Client
5
5
  Author-email: Dan Fellin <dan@polyapi.io>
6
6
  License: MIT License
@@ -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=5e6hJ3nitKxbQNSkp4jbuAzbJvykj3de1_aSsc1MBnY,7331
11
+ polyapi/function_cli.py,sha256=x1nAnBQVpjhCDUd_eazQ7HTLgpsNFcY9p6YHy-8iv5E,7660
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.dev1.dist-info/LICENSE,sha256=Hi0kDr56Dsy0uYIwNt4r9G7tI8x8miXRTlyvbeplCP8,1068
21
- polyapi_python-0.2.3.dev1.dist-info/METADATA,sha256=9IbEwxs-o-u_OMvTeOW_MjVIMMCQr98eqKAhPRWSy3s,4823
22
- polyapi_python-0.2.3.dev1.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
23
- polyapi_python-0.2.3.dev1.dist-info/top_level.txt,sha256=CEFllOnzowci_50RYJac-M54KD2IdAptFsayVVF_f04,8
24
- polyapi_python-0.2.3.dev1.dist-info/RECORD,,
20
+ polyapi_python-0.2.3.dev2.dist-info/LICENSE,sha256=Hi0kDr56Dsy0uYIwNt4r9G7tI8x8miXRTlyvbeplCP8,1068
21
+ polyapi_python-0.2.3.dev2.dist-info/METADATA,sha256=-kX0lz42ns-Bzdl5XS8FKZF4qUkDndJH1JlIm_GfNSo,4823
22
+ polyapi_python-0.2.3.dev2.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
23
+ polyapi_python-0.2.3.dev2.dist-info/top_level.txt,sha256=CEFllOnzowci_50RYJac-M54KD2IdAptFsayVVF_f04,8
24
+ polyapi_python-0.2.3.dev2.dist-info/RECORD,,