Generates a dictionary of shell and gator grader command options from a list of dict checks.
Generate a list of checks based on check data from the configuration file.
Parameters:
Name |
Type |
Description |
Default |
check_data_list |
List[CheckData]
|
A list of CheckData that each represent a check from the
configuration file. |
required
|
Returns:
Source code in gatorgrade/input/command_line_generator.py
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67 | def generate_checks(
check_data_list: List[CheckData],
) -> List[Union[ShellCheck, GatorGraderCheck]]:
"""Generate a list of checks based on check data from the configuration file.
Args:
check_data_list: A list of CheckData that each represent a check from the
configuration file.
Returns:
A list of ShellChecks and GatorGraderChecks.
"""
checks = []
for check_data in check_data_list:
# If the check has a `command` key, then it is a shell check
if "command" in check_data.check:
checks.append(
ShellCheck(
command=check_data.check.get("command"),
description=check_data.check.get("description"),
json_info=check_data.check,
)
)
# Otherwise, it is a GatorGrader check
else:
gg_args = []
# Add description option if in data
description = check_data.check.get("description")
if description is not None:
gg_args.extend(["--description", str(description)])
# Always add name of check, which should be in data
gg_args.append(str(check_data.check.get("check")))
# Add any additional options
options = check_data.check.get("options")
if options is not None:
for option in options:
# If option should be a flag (i.e. its value is the `True` boolean),
# add only the option without a value
option_value = options[option]
if isinstance(option_value, bool):
if option_value:
gg_args.append(f"--{option}")
# Otherwise, add both the option and its value
else:
gg_args.extend([f"--{option}", str(option_value)])
# Add directory and file if file context in data
if check_data.file_context is not None:
# Get the file and directory using os
dirname, filename = os.path.split(check_data.file_context)
if dirname == "":
dirname = "."
gg_args.extend(["--directory", dirname, "--file", filename])
checks.append(GatorGraderCheck(gg_args=gg_args, json_info=check_data.check))
return checks
|