Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Configurable Project Name #109

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
24 changes: 24 additions & 0 deletions gatorgrade/input/in_file_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,36 @@ def parse_yaml_file(file_path: Path) -> List[Any]:
return []


def get_assignment_name(file: Path) -> (str):
"""Get the name for the project the YAML is set up for."""
# set the base assignment name to display, the file path.
assignment_name = Path.cwd().name
config_search_key = "{'name':"

# change the file path into data to look through
data = parse_yaml_file(file)

# if they have a name field
if len(data) > 1:
for i in range(len(data)):
if config_search_key in str(data[i]):
# ex. need to go from {'name': 'top\n'} to top: split by space
assignment_name = str(data[i])[10:].split("\\")[0]

return assignment_name


def reformat_yaml_data(data):
"""Reformat the raw data from a YAML file into a list of tuples."""
reformatted_data = []
if len(data) == 2:
setup_commands = data.pop(0) # Removes the setup commands
run_setup(setup_commands)
elif len(data) == 3:
setup_commands = data.pop(0) # Removes the setup commands
project_name = data.pop(0) # Removes the name entry
run_setup(setup_commands)

add_checks_to_list(None, data[0], reformatted_data)
return reformatted_data

Expand Down
5 changes: 4 additions & 1 deletion gatorgrade/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import typer
from rich.console import Console

from gatorgrade.input.in_file_path import get_assignment_name
from gatorgrade.input.parse_config import parse_config
from gatorgrade.output.output import run_checks

Expand Down Expand Up @@ -43,8 +44,10 @@ def gatorgrade(
checks = parse_config(filename)
# there are valid checks and thus the
# tool should run them with run_checks
project_name = get_assignment_name(filename)

if len(checks) > 0:
checks_status = run_checks(checks)
checks_status = run_checks(checks, project_name)
# no checks were created and this means
# that, most likely, the file was not
# valid and thus the tool cannot run checks
Expand Down
6 changes: 4 additions & 2 deletions gatorgrade/output/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ def _run_gg_check(check: GatorGraderCheck) -> CheckResult:
return CheckResult(passed=passed, description=description, diagnostic=diagnostic)


def run_checks(checks: List[Union[ShellCheck, GatorGraderCheck]]) -> bool:
def run_checks(
checks: List[Union[ShellCheck, GatorGraderCheck]], project_name: str
) -> bool:
"""Run shell and GatorGrader checks and display whether each has passed or failed.

Also, print a list of all failed checks with their diagnostics and a summary message that
Expand Down Expand Up @@ -110,7 +112,7 @@ def run_checks(checks: List[Union[ShellCheck, GatorGraderCheck]]) -> bool:
else:
percent = round(passed_count / len(results) * 100)
# compute summary results and display them in the console
summary = f"Passed {passed_count}/{len(results)} ({percent}%) of checks for {Path.cwd().name}!"
summary = f"Passed {passed_count}/{len(results)} ({percent}%) of checks for {project_name}!"
summary_color = "green" if passed_count == len(results) else "bright white"
print_with_border(summary, summary_color)
# determine whether or not the run was a success or not:
Expand Down
12 changes: 8 additions & 4 deletions tests/output/test_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ def test_run_checks_gg_check_should_show_passed(capsys):
"hello-world.py",
]
)
project_name = "test"
# When run_checks is called
output.run_checks([check])
output.run_checks([check], project_name)
# Then the output shows that the check has passed
out, _ = capsys.readouterr()
assert "✓ Check TODOs" in out
Expand All @@ -46,8 +47,9 @@ def test_run_checks_invalid_gg_args_prints_exception(capsys):
"--exact",
]
)
project_name = "test"
# When run_checks is called
output.run_checks([check])
output.run_checks([check], project_name)
# Then the output contains a declaration
# about the use of an Invalid GatorGrader check
out, _ = capsys.readouterr()
Expand Down Expand Up @@ -93,8 +95,9 @@ def test_run_checks_some_failed_prints_correct_summary(capsys):
]
),
]
project_name = "test"
# When run_checks is called
output.run_checks(checks)
output.run_checks(checks, project_name)
# Then the output shows the correct fraction and percentage of passed checks
out, _ = capsys.readouterr()
assert "Passed 2/3 (67%) of checks" in out
Expand Down Expand Up @@ -137,8 +140,9 @@ def test_run_checks_all_passed_prints_correct_summary(capsys):
]
),
]
project_name = "test"
# When run_checks is called
output.run_checks(checks)
output.run_checks(checks, project_name)
# Then the output shows the correct fraction and percentage of passed checks
out, _ = capsys.readouterr()
assert "Passed 3/3 (100%) of checks" in out