aiverify-moonshot 0.4.5__py3-none-any.whl → 0.4.6__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.
@@ -5,8 +5,17 @@ from rich.console import Console
5
5
  from rich.table import Table
6
6
 
7
7
  from moonshot.api import api_delete_result, api_get_all_result, api_read_result
8
- from moonshot.integrations.cli.benchmark.cookbook import show_cookbook_results
9
- from moonshot.integrations.cli.benchmark.recipe import show_recipe_results
8
+ from moonshot.integrations.cli.benchmark.cookbook import _show_cookbook_results
9
+ from moonshot.integrations.cli.benchmark.recipe import _show_recipe_results
10
+ from moonshot.integrations.cli.cli_errors import (
11
+ ERROR_BENCHMARK_DELETE_RESULT_RESULT_VALIDATION,
12
+ ERROR_BENCHMARK_LIST_RESULTS_FIND_VALIDATION,
13
+ ERROR_BENCHMARK_LIST_RESULTS_PAGINATION_VALIDATION,
14
+ ERROR_BENCHMARK_LIST_RESULTS_PAGINATION_VALIDATION_1,
15
+ ERROR_BENCHMARK_VIEW_RESULT_METADATA_INVALID_VALIDATION,
16
+ ERROR_BENCHMARK_VIEW_RESULT_METADATA_VALIDATION,
17
+ ERROR_BENCHMARK_VIEW_RESULT_RESULT_FILENAME_VALIDATION,
18
+ )
10
19
  from moonshot.integrations.cli.common.display_helper import (
11
20
  display_view_list_format,
12
21
  display_view_str_format,
@@ -23,23 +32,44 @@ def list_results(args) -> list | None:
23
32
  """
24
33
  List all available results.
25
34
 
26
- This function retrieves all available results by calling the api_get_all_result_name function from the
27
- moonshot.api module. It then creates a table with the result id and name. If there are no results, it prints a
28
- message indicating that no results were found.
35
+ This function retrieves all available results by calling the api_get_all_result function from the
36
+ moonshot.api module. It then filters the results based on the provided keyword and pagination arguments.
37
+ If there are no results, it prints a message indicating that no results were found.
29
38
 
30
39
  Args:
31
- args: A namespace object from argparse. It should have an optional attribute:
32
- find (str): Optional field to find result(s) with a keyword.
33
- pagination (str): Optional field to paginate results.
40
+ args (argparse.Namespace): The arguments provided to the command line interface.
41
+ find (str): Optional field to find result(s) with a keyword.
42
+ pagination (str): Optional field to paginate results.
34
43
 
35
44
  Returns:
36
- list | None: A list of Result or None if there is no result.
45
+ list | None: A list of results or None if there are no results.
37
46
  """
38
47
 
39
48
  try:
49
+ if args.find is not None:
50
+ if not isinstance(args.find, str) or not args.find:
51
+ raise TypeError(ERROR_BENCHMARK_LIST_RESULTS_FIND_VALIDATION)
52
+
53
+ if args.pagination is not None:
54
+ if not isinstance(args.pagination, str) or not args.pagination:
55
+ raise TypeError(ERROR_BENCHMARK_LIST_RESULTS_PAGINATION_VALIDATION)
56
+ try:
57
+ pagination = literal_eval(args.pagination)
58
+ if not (
59
+ isinstance(pagination, tuple)
60
+ and len(pagination) == 2
61
+ and all(isinstance(i, int) for i in pagination)
62
+ ):
63
+ raise ValueError(
64
+ ERROR_BENCHMARK_LIST_RESULTS_PAGINATION_VALIDATION_1
65
+ )
66
+ except (ValueError, SyntaxError):
67
+ raise ValueError(ERROR_BENCHMARK_LIST_RESULTS_PAGINATION_VALIDATION_1)
68
+ else:
69
+ pagination = ()
70
+
40
71
  results_list = api_get_all_result()
41
72
  keyword = args.find.lower() if args.find else ""
42
- pagination = literal_eval(args.pagination) if args.pagination else ()
43
73
 
44
74
  if results_list:
45
75
  filtered_results_list = filter_data(results_list, keyword, pagination)
@@ -52,6 +82,7 @@ def list_results(args) -> list | None:
52
82
 
53
83
  except Exception as e:
54
84
  print(f"[list_results]: {str(e)}")
85
+ return None
55
86
 
56
87
 
57
88
  def view_result(args) -> None:
@@ -60,24 +91,34 @@ def view_result(args) -> None:
60
91
 
61
92
  This function retrieves a specific result by calling the api_read_result function from the
62
93
  moonshot.api module using the result filename provided in the args.
63
- It then checks if the result filename starts with "cookbook". If it does, it displays the result using the
64
- display_view_cookbook_result function. Otherwise, it uses the display_view_recipe_result function.
94
+ It then checks the metadata of the result to determine whether to display it as a cookbook or recipe result.
65
95
 
66
96
  Args:
67
- args: A namespace object from argparse. It should have the following attribute:
97
+ args (argparse.Namespace): The arguments provided to the command line interface.
68
98
  result_filename (str): The filename of the result to view.
69
99
 
70
100
  Returns:
71
101
  None
72
102
  """
73
103
  try:
104
+ if (
105
+ not isinstance(args.result_filename, str)
106
+ or not args.result_filename
107
+ or args.result_filename is None
108
+ ):
109
+ raise TypeError(ERROR_BENCHMARK_VIEW_RESULT_RESULT_FILENAME_VALIDATION)
110
+
74
111
  result_info = api_read_result(args.result_filename)
75
- if result_info["metadata"].get("cookbooks"):
76
- display_view_cookbook_result(result_info)
77
- elif result_info["metadata"].get("recipes"):
78
- display_view_recipe_result(result_info)
112
+ if isinstance(result_info, dict) and "metadata" in result_info:
113
+ if result_info["metadata"].get("cookbooks"):
114
+ _display_view_cookbook_result(result_info)
115
+ elif result_info["metadata"].get("recipes"):
116
+ _display_view_recipe_result(result_info)
117
+ else:
118
+ raise TypeError(ERROR_BENCHMARK_VIEW_RESULT_METADATA_INVALID_VALIDATION)
79
119
  else:
80
- print("[view_result]: Unable to determine cookbook or recipe")
120
+ raise TypeError(ERROR_BENCHMARK_VIEW_RESULT_METADATA_VALIDATION)
121
+
81
122
  except Exception as e:
82
123
  print(f"[view_result]: {str(e)}")
83
124
 
@@ -92,7 +133,7 @@ def delete_result(args) -> None:
92
133
  prints an error message.
93
134
 
94
135
  Args:
95
- args: A namespace object from argparse. It should have the following attribute:
136
+ args (argparse.Namespace): The arguments provided to the command line interface.
96
137
  result (str): The identifier of the result to delete.
97
138
 
98
139
  Returns:
@@ -105,7 +146,11 @@ def delete_result(args) -> None:
105
146
  if confirmation.lower() != "y":
106
147
  console.print("[bold yellow]Result deletion cancelled.[/]")
107
148
  return
149
+
108
150
  try:
151
+ if args.result is None or not isinstance(args.result, str) or not args.result:
152
+ raise ValueError(ERROR_BENCHMARK_DELETE_RESULT_RESULT_VALIDATION)
153
+
109
154
  api_delete_result(args.result)
110
155
  print("[delete_result]: Result deleted.")
111
156
  except Exception as e:
@@ -123,7 +168,7 @@ def _display_results(results_list):
123
168
  message indicating that no results were found.
124
169
 
125
170
  Args:
126
- results_list (list): A list of results. Each result is a dictionary with keys 'id' and 'name'.
171
+ results_list (list): A list of results. Each result is a dictionary with keys 'id' and 'metadata'.
127
172
 
128
173
  Returns:
129
174
  None
@@ -170,13 +215,12 @@ def _display_results(results_list):
170
215
  console.print(table)
171
216
 
172
217
 
173
- def display_view_recipe_result(result_info):
218
+ def _display_view_recipe_result(result_info):
174
219
  """
175
220
  Display the recipe result.
176
221
 
177
- This function takes the result file and result info as arguments. It converts the result info into a dictionary
178
- using the convert_string_tuples_in_dict function. It then retrieves the recipes, endpoints, and duration from the
179
- converted result info. Finally, it calls the show_recipe_results function from the
222
+ This function takes the result info as an argument. It retrieves the recipes, endpoints, and duration from the
223
+ result info. Finally, it calls the show_recipe_results function from the
180
224
  moonshot.integrations.cli.benchmark.recipe module to display the recipe results.
181
225
 
182
226
  Args:
@@ -188,16 +232,15 @@ def display_view_recipe_result(result_info):
188
232
  recipes = result_info["metadata"]["recipes"]
189
233
  endpoints = result_info["metadata"]["endpoints"]
190
234
  duration = result_info["metadata"]["duration"]
191
- show_recipe_results(recipes, endpoints, result_info, duration)
235
+ _show_recipe_results(recipes, endpoints, result_info, duration)
192
236
 
193
237
 
194
- def display_view_cookbook_result(result_info):
238
+ def _display_view_cookbook_result(result_info):
195
239
  """
196
240
  Display the cookbook result.
197
241
 
198
- This function takes the result file and result info as arguments. It converts the result info into a dictionary
199
- using the convert_string_tuples_in_dict function. It then retrieves the cookbooks, endpoints, and duration from the
200
- converted result info. Finally, it calls the show_cookbook_results function from the
242
+ This function takes the result info as an argument. It retrieves the cookbooks, endpoints, and duration from the
243
+ result info. Finally, it calls the show_cookbook_results function from the
201
244
  moonshot.integrations.cli.benchmark.cookbook module to display the cookbook results.
202
245
 
203
246
  Args:
@@ -209,7 +252,7 @@ def display_view_cookbook_result(result_info):
209
252
  cookbooks = result_info["metadata"]["cookbooks"]
210
253
  endpoints = result_info["metadata"]["endpoints"]
211
254
  duration = result_info["metadata"]["duration"]
212
- show_cookbook_results(cookbooks, endpoints, result_info, duration)
255
+ _show_cookbook_results(cookbooks, endpoints, result_info, duration)
213
256
 
214
257
 
215
258
  # ------------------------------------------------------------------------------
@@ -5,6 +5,12 @@ from rich.console import Console
5
5
  from rich.table import Table
6
6
 
7
7
  from moonshot.api import api_get_all_run
8
+ from moonshot.integrations.cli.cli_errors import (
9
+ ERROR_BENCHMARK_LIST_RUNS_FIND_VALIDATION,
10
+ ERROR_BENCHMARK_LIST_RUNS_PAGINATION_VALIDATION,
11
+ ERROR_BENCHMARK_LIST_RUNS_PAGINATION_VALIDATION_1,
12
+ ERROR_BENCHMARK_VIEW_RUN_RUNNER_ID_VALIDATION,
13
+ )
8
14
  from moonshot.integrations.cli.common.display_helper import (
9
15
  display_view_list_format,
10
16
  display_view_str_format,
@@ -22,23 +28,41 @@ def list_runs(args) -> list | None:
22
28
  List all runs.
23
29
 
24
30
  This function retrieves all available runs by calling the api_get_all_run function from the
25
- moonshot.api module. It then calls the _display_runs function to present the retrieved run information
26
- in a user-friendly format on the command line interface. If an exception occurs during the retrieval
27
- or display process, it prints an error message.
31
+ moonshot.api module. It then filters the runs based on the provided keyword and pagination arguments.
32
+ If there are no runs, it prints a message indicating that no runs were found.
28
33
 
29
34
  Args:
30
- args: A namespace object from argparse. It should have an optional attribute:
31
- find (str): Optional field to find run(s) with a keyword.
32
- pagination (str): Optional field to paginate runs.
35
+ args (argparse.Namespace): The arguments provided to the command line interface.
36
+ find (str): Optional field to find run(s) with a keyword.
37
+ pagination (str): Optional field to paginate runs.
33
38
 
34
39
  Returns:
35
- list | None: A list of Run or None if there is no result.
40
+ list | None: A list of runs or None if there are no runs.
36
41
  """
37
42
 
38
43
  try:
44
+ if args.find is not None:
45
+ if not isinstance(args.find, str) or not args.find:
46
+ raise TypeError(ERROR_BENCHMARK_LIST_RUNS_FIND_VALIDATION)
47
+
48
+ if args.pagination is not None:
49
+ if not isinstance(args.pagination, str) or not args.pagination:
50
+ raise TypeError(ERROR_BENCHMARK_LIST_RUNS_PAGINATION_VALIDATION)
51
+ try:
52
+ pagination = literal_eval(args.pagination)
53
+ if not (
54
+ isinstance(pagination, tuple)
55
+ and len(pagination) == 2
56
+ and all(isinstance(i, int) for i in pagination)
57
+ ):
58
+ raise ValueError(ERROR_BENCHMARK_LIST_RUNS_PAGINATION_VALIDATION_1)
59
+ except (ValueError, SyntaxError):
60
+ raise ValueError(ERROR_BENCHMARK_LIST_RUNS_PAGINATION_VALIDATION_1)
61
+ else:
62
+ pagination = ()
63
+
39
64
  runner_run_info = api_get_all_run()
40
65
  keyword = args.find.lower() if args.find else ""
41
- pagination = literal_eval(args.pagination) if args.pagination else ()
42
66
 
43
67
  if runner_run_info:
44
68
  filtered_runs_list = filter_data(runner_run_info, keyword, pagination)
@@ -51,6 +75,7 @@ def list_runs(args) -> list | None:
51
75
 
52
76
  except Exception as e:
53
77
  print(f"[list_runs]: {str(e)}")
78
+ return None
54
79
 
55
80
 
56
81
  def view_run(args) -> None:
@@ -62,13 +87,20 @@ def view_run(args) -> None:
62
87
  user-friendly format.
63
88
 
64
89
  Args:
65
- args: A namespace object from argparse. It should have the following attribute:
66
- runner (str): The identifier of the runner whose runs are to be viewed.
90
+ args (argparse.Namespace): The arguments provided to the command line interface.
91
+ runner_id (str): The identifier of the runner whose runs are to be viewed.
67
92
 
68
93
  Returns:
69
94
  None
70
95
  """
71
96
  try:
97
+ if (
98
+ not isinstance(args.runner_id, str)
99
+ or not args.runner_id
100
+ or args.runner_id is None
101
+ ):
102
+ raise TypeError(ERROR_BENCHMARK_VIEW_RUN_RUNNER_ID_VALIDATION)
103
+
72
104
  runner_run_info = api_get_all_run(args.runner_id)
73
105
  _display_runs(runner_run_info)
74
106
  except Exception as e:
@@ -151,7 +183,7 @@ def _display_runs(runs_list: list):
151
183
  # ------------------------------------------------------------------------------
152
184
  # View run arguments
153
185
  view_run_args = cmd2.Cmd2ArgumentParser(
154
- description="View a runner runs.",
186
+ description="View a runner's runs.",
155
187
  epilog="Example:\n view_run my-new-cookbook-runner",
156
188
  )
157
189
  view_run_args.add_argument("runner_id", type=str, help="Name of the runner")
@@ -10,6 +10,10 @@ from moonshot.api import (
10
10
  api_load_session,
11
11
  api_read_runner,
12
12
  )
13
+ from moonshot.integrations.cli.cli_errors import (
14
+ ERROR_BENCHMARK_DELETE_RUNNER_RUNNER_VALIDATION,
15
+ ERROR_BENCHMARK_VIEW_RUNNER_RUNNER_VALIDATION,
16
+ )
13
17
  from moonshot.integrations.cli.common.display_helper import (
14
18
  display_view_list_format,
15
19
  display_view_str_format,
@@ -25,9 +29,9 @@ def list_runners() -> None:
25
29
  """
26
30
  List all runners.
27
31
 
28
- This function retrieves and displays information about all runners, including their associated runs and session
29
- information. It fetches the data using the api_get_all_runner, api_get_all_run, and api_get_available_session_info
30
- functions, then calls the display_runners function to present it in a user-friendly format.
32
+ Retrieves and displays information about all runners, including their associated runs and session
33
+ information. Fetches the data using the api_get_all_runner, api_get_all_run, and api_get_available_session_info
34
+ functions, then calls the _display_runners function to present it in a user-friendly format.
31
35
 
32
36
  Returns:
33
37
  None
@@ -36,7 +40,7 @@ def list_runners() -> None:
36
40
  runner_info = api_get_all_runner()
37
41
  runner_run_info = api_get_all_run()
38
42
  _, runner_session_info = api_get_available_session_info()
39
- display_runners(runner_info, runner_run_info, runner_session_info)
43
+ _display_runners(runner_info, runner_run_info, runner_session_info)
40
44
  except Exception as e:
41
45
  print(f"[list_runners]: {str(e)}")
42
46
 
@@ -45,22 +49,25 @@ def view_runner(args) -> None:
45
49
  """
46
50
  View a specific runner.
47
51
 
48
- This function retrieves and displays information about a specific runner, including its associated runs and session
49
- information. It uses the runner identifier provided in the arguments to fetch the data and then calls the
50
- display_runners function to present it in a user-friendly format.
52
+ Retrieves and displays information about a specific runner, including its associated runs and session
53
+ information. Uses the runner identifier provided in the arguments to fetch the data and then calls the
54
+ _display_runners function to present it in a user-friendly format.
51
55
 
52
56
  Args:
53
- args: A namespace object from argparse. It should have the following attribute:
57
+ args (argparse.Namespace): A namespace object from argparse. It should have the following attribute:
54
58
  runner (str): The identifier of the runner to view.
55
59
 
56
60
  Returns:
57
61
  None
58
62
  """
59
63
  try:
64
+ if not isinstance(args.runner, str) or not args.runner or args.runner is None:
65
+ raise TypeError(ERROR_BENCHMARK_VIEW_RUNNER_RUNNER_VALIDATION)
66
+
60
67
  runner_info = api_read_runner(args.runner)
61
68
  runner_run_info = api_get_all_run(args.runner)
62
69
  runner_session_info = api_load_session(args.runner)
63
- display_runners([runner_info], runner_run_info, [runner_session_info])
70
+ _display_runners([runner_info], runner_run_info, [runner_session_info])
64
71
  except Exception as e:
65
72
  print(f"[view_runner]: {str(e)}")
66
73
 
@@ -69,13 +76,13 @@ def delete_runner(args) -> None:
69
76
  """
70
77
  Delete a runner.
71
78
 
72
- This function deletes a runner with the specified identifier. It prompts the user for confirmation before proceeding
79
+ Deletes a runner with the specified identifier. Prompts the user for confirmation before proceeding
73
80
  with the deletion. If the user confirms, it calls the api_delete_runner function from the moonshot.api module to
74
81
  delete the runner. If the deletion is successful, it prints a confirmation message. If an exception occurs, it
75
82
  prints an error message.
76
83
 
77
84
  Args:
78
- args: A namespace object from argparse. It should have the following attribute:
85
+ args (argparse.Namespace): A namespace object from argparse. It should have the following attribute:
79
86
  runner (str): The identifier of the runner to delete.
80
87
 
81
88
  Returns:
@@ -88,7 +95,11 @@ def delete_runner(args) -> None:
88
95
  if confirmation.lower() != "y":
89
96
  console.print("[bold yellow]Runner deletion cancelled.[/]")
90
97
  return
98
+
91
99
  try:
100
+ if args.runner is None or not isinstance(args.runner, str) or not args.runner:
101
+ raise ValueError(ERROR_BENCHMARK_DELETE_RUNNER_RUNNER_VALIDATION)
102
+
92
103
  api_delete_runner(args.runner)
93
104
  print("[delete_runner]: Runner deleted.")
94
105
  except Exception as e:
@@ -98,24 +109,22 @@ def delete_runner(args) -> None:
98
109
  # ------------------------------------------------------------------------------
99
110
  # Helper functions: Display on cli
100
111
  # ------------------------------------------------------------------------------
101
- def display_runners(
112
+ def _display_runners(
102
113
  runner_list: list, runner_run_info_list: list, runner_session_info_list: list
103
114
  ) -> None:
104
115
  """
105
116
  Display runners in a table format.
106
117
 
107
- This function takes lists of runner information, run information, and session information, then displays them in a
118
+ Takes lists of runner information, run information, and session information, then displays them in a
108
119
  table format on the command line interface. Each runner is listed with details such as the runner's ID, name,
109
120
  description, number of runs, number of sessions, database file, and endpoints.
110
121
 
111
122
  Args:
112
- runner_list: A list of dictionaries, where each dictionary contains information about a runner.
113
-
114
- runner_run_info_list: A list of dictionaries, where each dictionary contains information about a run
115
- associated with a runner.
116
-
117
- runner_session_info_list: A list of dictionaries, where each dictionary contains information about a session
118
- associated with a runner.
123
+ runner_list (list): A list of dictionaries, where each dictionary contains information about a runner.
124
+ runner_run_info_list (list): A list of dictionaries, where each dictionary contains information about a run
125
+ associated with a runner.
126
+ runner_session_info_list (list): A list of dictionaries, where each dictionary contains information about a
127
+ session associated with a runner.
119
128
 
120
129
  Returns:
121
130
  None