polyapi-python 0.0.10__tar.gz → 0.0.12__tar.gz

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.
Files changed (25) hide show
  1. {polyapi-python-0.0.10 → polyapi-python-0.0.12}/PKG-INFO +3 -3
  2. {polyapi-python-0.0.10 → polyapi-python-0.0.12}/README.md +2 -2
  3. {polyapi-python-0.0.10 → polyapi-python-0.0.12}/polyapi/api.py +8 -1
  4. {polyapi-python-0.0.10 → polyapi-python-0.0.12}/polyapi/cli.py +3 -2
  5. {polyapi-python-0.0.10 → polyapi-python-0.0.12}/polyapi/function_cli.py +15 -11
  6. {polyapi-python-0.0.10 → polyapi-python-0.0.12}/polyapi_python.egg-info/PKG-INFO +3 -3
  7. {polyapi-python-0.0.10 → polyapi-python-0.0.12}/pyproject.toml +2 -2
  8. {polyapi-python-0.0.10 → polyapi-python-0.0.12}/LICENSE +0 -0
  9. {polyapi-python-0.0.10 → polyapi-python-0.0.12}/polyapi/__init__.py +0 -0
  10. {polyapi-python-0.0.10 → polyapi-python-0.0.12}/polyapi/__main__.py +0 -0
  11. {polyapi-python-0.0.10 → polyapi-python-0.0.12}/polyapi/config.py +0 -0
  12. {polyapi-python-0.0.10 → polyapi-python-0.0.12}/polyapi/constants.py +0 -0
  13. {polyapi-python-0.0.10 → polyapi-python-0.0.12}/polyapi/exceptions.py +0 -0
  14. {polyapi-python-0.0.10 → polyapi-python-0.0.12}/polyapi/generate.py +0 -0
  15. {polyapi-python-0.0.10 → polyapi-python-0.0.12}/polyapi/py.typed +0 -0
  16. {polyapi-python-0.0.10 → polyapi-python-0.0.12}/polyapi/schema.py +0 -0
  17. {polyapi-python-0.0.10 → polyapi-python-0.0.12}/polyapi/typedefs.py +0 -0
  18. {polyapi-python-0.0.10 → polyapi-python-0.0.12}/polyapi/utils.py +0 -0
  19. {polyapi-python-0.0.10 → polyapi-python-0.0.12}/polyapi/variables.py +0 -0
  20. {polyapi-python-0.0.10 → polyapi-python-0.0.12}/polyapi_python.egg-info/SOURCES.txt +0 -0
  21. {polyapi-python-0.0.10 → polyapi-python-0.0.12}/polyapi_python.egg-info/dependency_links.txt +0 -0
  22. {polyapi-python-0.0.10 → polyapi-python-0.0.12}/polyapi_python.egg-info/requires.txt +0 -0
  23. {polyapi-python-0.0.10 → polyapi-python-0.0.12}/polyapi_python.egg-info/top_level.txt +0 -0
  24. {polyapi-python-0.0.10 → polyapi-python-0.0.12}/setup.cfg +0 -0
  25. {polyapi-python-0.0.10 → polyapi-python-0.0.12}/tests/test_generate.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: polyapi-python
3
- Version: 0.0.10
3
+ Version: 0.0.12
4
4
  Summary: The PolyAPI Python Client
5
5
  Author-email: Dan Fellin <dan@polyapi.io>
6
6
  License: MIT License
@@ -43,7 +43,7 @@ The PolyAPI Python Library lets you use and define PolyAPI functions using Pytho
43
43
  First install the client:
44
44
 
45
45
  ```bash
46
- pip install git+https://github.com/polyapi/polyapi-python.git
46
+ pip install polyapi-python
47
47
  ```
48
48
 
49
49
  ### 2. Generate Your Functions
@@ -104,7 +104,7 @@ So that you can see your new function in your library!
104
104
  To upgrade your library to the latest version, pass the upgrade flag.:
105
105
 
106
106
  ```bash
107
- pip install git+https://github.com/polyapi/polyapi-python.git --upgrade
107
+ pip install polyapi-python --upgrade
108
108
  ```
109
109
 
110
110
  ## Unit Tests
@@ -9,7 +9,7 @@ The PolyAPI Python Library lets you use and define PolyAPI functions using Pytho
9
9
  First install the client:
10
10
 
11
11
  ```bash
12
- pip install git+https://github.com/polyapi/polyapi-python.git
12
+ pip install polyapi-python
13
13
  ```
14
14
 
15
15
  ### 2. Generate Your Functions
@@ -70,7 +70,7 @@ So that you can see your new function in your library!
70
70
  To upgrade your library to the latest version, pass the upgrade flag.:
71
71
 
72
72
  ```bash
73
- pip install git+https://github.com/polyapi/polyapi-python.git --upgrade
73
+ pip install polyapi-python --upgrade
74
74
  ```
75
75
 
76
76
  ## Unit Tests
@@ -26,6 +26,7 @@ def {function_name}({args}) -> {return_type_name}:
26
26
  resp = requests.post(url, json=data, headers=headers)
27
27
  if resp.status_code != 200 and resp.status_code != 201:
28
28
  raise PolyApiException(f"{{resp.status_code}}: {{resp.content}}")
29
+
29
30
  return {return_action}
30
31
  """
31
32
 
@@ -149,8 +150,14 @@ def render_function(
149
150
  data=data,
150
151
  )
151
152
  else:
152
- if return_type_def == "str":
153
+ if return_type_name == "str":
153
154
  return_action = "resp.text"
155
+ elif return_type_name == "int":
156
+ return_action = "int(resp.text.replace('(int) ', ''))"
157
+ elif return_type_name == "float":
158
+ return_action = "float(resp.text.replace('(float) ', ''))"
159
+ elif return_type_name == "bool":
160
+ return_action = "False if resp.text == 'False' else True"
154
161
  else:
155
162
  return_action = "resp.json()"
156
163
  rendered = SERVER_TEMPLATE.format(
@@ -13,7 +13,8 @@ def execute_from_cli():
13
13
  )
14
14
  parser.add_argument("--context", required=False, default="")
15
15
  parser.add_argument("--description", required=False, default="")
16
- parser.add_argument("--server", action="store_true")
16
+ parser.add_argument("--server", action="store_true", help="Pass --server if you want this to be a server function. By default, it will be a client function.")
17
+ parser.add_argument("--logs", action="store_true", help="Pass --logs if you want to store and see the logs from this function executing")
17
18
  parser.add_argument("command", choices=CLI_COMMANDS)
18
19
  parser.add_argument("subcommands", nargs="*")
19
20
  args = parser.parse_args()
@@ -25,4 +26,4 @@ def execute_from_cli():
25
26
  print("Generating...")
26
27
  generate()
27
28
  elif command == "function":
28
- function_add_or_update(args.context, args.description, args.server, args.subcommands)
29
+ function_add_or_update(args.context, args.description, args.server, args.logs, args.subcommands)
@@ -18,21 +18,25 @@ def _get_jsonschema_type(python_type: str):
18
18
  return PYTHON_TO_JSONSCHEMA_TYPE_MAP.get(python_type, "any")
19
19
 
20
20
 
21
- def _get_arguments_from_ast(parsed_code: ast.AST, function_name: str):
21
+ def _get_args_and_return_type_from_ast(parsed_code: ast.AST, function_name: str):
22
22
  # Iterate over every function in the AST
23
23
  for node in ast.iter_child_nodes(parsed_code):
24
24
  if isinstance(node, ast.FunctionDef) and node.name == function_name:
25
25
  function_args = [arg for arg in node.args.args]
26
- rv = []
26
+ parsed_args = []
27
27
  for arg in function_args:
28
- rv.append(
28
+ parsed_args.append(
29
29
  {
30
30
  "key": arg.arg,
31
31
  "name": arg.arg,
32
- "type": _get_jsonschema_type(getattr(arg.annotation, "id", "any")),
32
+ "type": _get_jsonschema_type(getattr(arg.annotation, "id", "Any")),
33
33
  }
34
34
  )
35
- return rv
35
+ if node.returns:
36
+ return_type = _get_jsonschema_type(getattr(node.returns, "id", "Any"))
37
+ else:
38
+ return_type = "Any"
39
+ return parsed_args, return_type
36
40
 
37
41
  # if we get here, we didn't find the function
38
42
  print(
@@ -42,7 +46,7 @@ def _get_arguments_from_ast(parsed_code: ast.AST, function_name: str):
42
46
 
43
47
 
44
48
  def function_add_or_update(
45
- context: str, description: str, server: bool, subcommands: List
49
+ context: str, description: str, server: bool, logs_enabled: bool, subcommands: List
46
50
  ):
47
51
  parser = argparse.ArgumentParser()
48
52
  parser.add_argument("subcommand", choices=["add"])
@@ -55,7 +59,7 @@ def function_add_or_update(
55
59
 
56
60
  # OK! let's parse the code and generate the arguments
57
61
  code_ast = ast.parse(code)
58
- arguments = _get_arguments_from_ast(code_ast, args.function_name)
62
+ arguments, return_type = _get_args_and_return_type_from_ast(code_ast, args.function_name)
59
63
 
60
64
  data = {
61
65
  "context": context,
@@ -63,11 +67,11 @@ def function_add_or_update(
63
67
  "description": description,
64
68
  "code": code,
65
69
  "language": "python",
66
- "typeSchemas": {},
67
- "returnType": None,
68
- "returnTypeSchema": {},
70
+ "typeSchemas": None,
71
+ "returnType": return_type,
72
+ "returnTypeSchema": None,
69
73
  "arguments": arguments,
70
- "logsEnabled": None,
74
+ "logsEnabled": logs_enabled,
71
75
  }
72
76
 
73
77
  api_key, api_url = get_api_key_and_url()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: polyapi-python
3
- Version: 0.0.10
3
+ Version: 0.0.12
4
4
  Summary: The PolyAPI Python Client
5
5
  Author-email: Dan Fellin <dan@polyapi.io>
6
6
  License: MIT License
@@ -43,7 +43,7 @@ The PolyAPI Python Library lets you use and define PolyAPI functions using Pytho
43
43
  First install the client:
44
44
 
45
45
  ```bash
46
- pip install git+https://github.com/polyapi/polyapi-python.git
46
+ pip install polyapi-python
47
47
  ```
48
48
 
49
49
  ### 2. Generate Your Functions
@@ -104,7 +104,7 @@ So that you can see your new function in your library!
104
104
  To upgrade your library to the latest version, pass the upgrade flag.:
105
105
 
106
106
  ```bash
107
- pip install git+https://github.com/polyapi/polyapi-python.git --upgrade
107
+ pip install polyapi-python --upgrade
108
108
  ```
109
109
 
110
110
  ## Unit Tests
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "polyapi-python"
3
- version = "0.0.10"
3
+ version = "0.0.12"
4
4
  description = "The PolyAPI Python Client"
5
5
  authors = [{ name = "Dan Fellin", email = "dan@polyapi.io" }]
6
6
  dependencies = ["requests", "typing_extensions", "jsonschema-gentypes"]
@@ -9,4 +9,4 @@ license = { file = "LICENSE" }
9
9
  requires-python = ">=3.10"
10
10
 
11
11
  [project.urls]
12
- Homepage = "https://github.com/polyapi/polyapi-python"
12
+ Homepage = "https://github.com/polyapi/polyapi-python"
File without changes