diff --git a/gatorgrade/input/in_file_path.py b/gatorgrade/input/in_file_path.py index 3a622c6f..ef2ae0b0 100644 --- a/gatorgrade/input/in_file_path.py +++ b/gatorgrade/input/in_file_path.py @@ -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 diff --git a/gatorgrade/main.py b/gatorgrade/main.py index 23fd8b04..94705a98 100644 --- a/gatorgrade/main.py +++ b/gatorgrade/main.py @@ -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 @@ -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 diff --git a/gatorgrade/output/output.py b/gatorgrade/output/output.py index 502c3f02..dbb5412f 100644 --- a/gatorgrade/output/output.py +++ b/gatorgrade/output/output.py @@ -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 @@ -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: diff --git a/tests/output/test_output.py b/tests/output/test_output.py index 1dd27672..3af233f4 100644 --- a/tests/output/test_output.py +++ b/tests/output/test_output.py @@ -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 @@ -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() @@ -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 @@ -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