From 1382384154c3e416cd9d6c9c0f984651c855f91e Mon Sep 17 00:00:00 2001 From: burgess01 Date: Wed, 7 Dec 2022 12:03:36 -0500 Subject: [PATCH 01/14] feature: add basic config name feat for testing --- gatorgrade/input/in_file_path.py | 21 +++++++++++++++++++++ gatorgrade/main.py | 3 +++ gatorgrade/output/output.py | 6 ++++-- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/gatorgrade/input/in_file_path.py b/gatorgrade/input/in_file_path.py index 3a622c6f..45b1575d 100644 --- a/gatorgrade/input/in_file_path.py +++ b/gatorgrade/input/in_file_path.py @@ -36,12 +36,33 @@ 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 = str(file) + + # change the file path into data to look through + data = parse_yaml_file(file) + + # if they have a setup, name, and checks + if len(data) == 3: + assignment_name = str(data.pop(1)) + + 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..c13b6b88 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,6 +44,8 @@ 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) # no checks were created and this means 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: From c55c3323f8f0bac443aad69385d326b66f47dd16 Mon Sep 17 00:00:00 2001 From: burgess01 Date: Wed, 7 Dec 2022 12:06:22 -0500 Subject: [PATCH 02/14] fix: remove missing param --- gatorgrade/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gatorgrade/main.py b/gatorgrade/main.py index c13b6b88..94705a98 100644 --- a/gatorgrade/main.py +++ b/gatorgrade/main.py @@ -47,7 +47,7 @@ def gatorgrade( 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 From 7bc4f6da8fb4dfa68d0c9e0a4d8a64ed7dec9e35 Mon Sep 17 00:00:00 2001 From: burgess01 Date: Wed, 7 Dec 2022 12:14:21 -0500 Subject: [PATCH 03/14] fix: linting line removal --- gatorgrade/input/in_file_path.py | 1 - 1 file changed, 1 deletion(-) diff --git a/gatorgrade/input/in_file_path.py b/gatorgrade/input/in_file_path.py index 45b1575d..ec6dc900 100644 --- a/gatorgrade/input/in_file_path.py +++ b/gatorgrade/input/in_file_path.py @@ -38,7 +38,6 @@ def parse_yaml_file(file_path: Path) -> List[Any]: 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 = str(file) From 44cffea09f6b9f2638768dfdbce4477f51ed95ff Mon Sep 17 00:00:00 2001 From: burgess01 Date: Wed, 7 Dec 2022 12:14:40 -0500 Subject: [PATCH 04/14] feature: add dummy project names to tests --- tests/output/test_output.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) 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 From af1087524071e79975a1efb9190f5fd3b1f5bfc0 Mon Sep 17 00:00:00 2001 From: burgess01 Date: Wed, 7 Dec 2022 12:34:46 -0500 Subject: [PATCH 05/14] feature: trim proj name --- gatorgrade/input/in_file_path.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/gatorgrade/input/in_file_path.py b/gatorgrade/input/in_file_path.py index ec6dc900..a4268db1 100644 --- a/gatorgrade/input/in_file_path.py +++ b/gatorgrade/input/in_file_path.py @@ -46,7 +46,11 @@ def get_assignment_name(file: Path) -> (str): # if they have a setup, name, and checks if len(data) == 3: - assignment_name = str(data.pop(1)) + # ex. need to go from {'name': 'top\n'} to top: split by space + unedited_assignment_name = str(data.pop(1)).split(" ") + # split by space, grab second, grab before \n + assignment_name = unedited_assignment_name[1:].split("\n")[0] + print(assignment_name) return assignment_name From 9a3d3d9070487fed6f85d95ae95e49d5c1316145 Mon Sep 17 00:00:00 2001 From: burgess01 Date: Wed, 7 Dec 2022 12:36:14 -0500 Subject: [PATCH 06/14] docs: remove unneeded print --- gatorgrade/input/in_file_path.py | 1 - 1 file changed, 1 deletion(-) diff --git a/gatorgrade/input/in_file_path.py b/gatorgrade/input/in_file_path.py index a4268db1..6025ac28 100644 --- a/gatorgrade/input/in_file_path.py +++ b/gatorgrade/input/in_file_path.py @@ -50,7 +50,6 @@ def get_assignment_name(file: Path) -> (str): unedited_assignment_name = str(data.pop(1)).split(" ") # split by space, grab second, grab before \n assignment_name = unedited_assignment_name[1:].split("\n")[0] - print(assignment_name) return assignment_name From b9dd713d6446c256e195c98dce31d277bda1ad13 Mon Sep 17 00:00:00 2001 From: burgess01 Date: Wed, 7 Dec 2022 12:39:08 -0500 Subject: [PATCH 07/14] fix: make sure project name is selected --- gatorgrade/input/in_file_path.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gatorgrade/input/in_file_path.py b/gatorgrade/input/in_file_path.py index 6025ac28..2bf1ecd3 100644 --- a/gatorgrade/input/in_file_path.py +++ b/gatorgrade/input/in_file_path.py @@ -47,7 +47,7 @@ def get_assignment_name(file: Path) -> (str): # if they have a setup, name, and checks if len(data) == 3: # ex. need to go from {'name': 'top\n'} to top: split by space - unedited_assignment_name = str(data.pop(1)).split(" ") + unedited_assignment_name = str(data.pop(1)).split(" ")[1] # split by space, grab second, grab before \n assignment_name = unedited_assignment_name[1:].split("\n")[0] From ca82446557e9f941260192d54cd7dac42f62e1a4 Mon Sep 17 00:00:00 2001 From: burgess01 Date: Wed, 7 Dec 2022 12:41:29 -0500 Subject: [PATCH 08/14] feature: search for split by backslash --- gatorgrade/input/in_file_path.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gatorgrade/input/in_file_path.py b/gatorgrade/input/in_file_path.py index 2bf1ecd3..c90817ee 100644 --- a/gatorgrade/input/in_file_path.py +++ b/gatorgrade/input/in_file_path.py @@ -49,7 +49,7 @@ def get_assignment_name(file: Path) -> (str): # ex. need to go from {'name': 'top\n'} to top: split by space unedited_assignment_name = str(data.pop(1)).split(" ")[1] # split by space, grab second, grab before \n - assignment_name = unedited_assignment_name[1:].split("\n")[0] + assignment_name = unedited_assignment_name[1:].split("\\")[0] return assignment_name From ca6bd954359047a021a7c856d1d1c55dbdf2116f Mon Sep 17 00:00:00 2001 From: burgess01 Date: Wed, 7 Dec 2022 13:08:02 -0500 Subject: [PATCH 09/14] feature: add logic for code to work without setup --- gatorgrade/input/in_file_path.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/gatorgrade/input/in_file_path.py b/gatorgrade/input/in_file_path.py index c90817ee..2d752c5a 100644 --- a/gatorgrade/input/in_file_path.py +++ b/gatorgrade/input/in_file_path.py @@ -44,12 +44,14 @@ def get_assignment_name(file: Path) -> (str): # change the file path into data to look through data = parse_yaml_file(file) - # if they have a setup, name, and checks - if len(data) == 3: - # ex. need to go from {'name': 'top\n'} to top: split by space - unedited_assignment_name = str(data.pop(1)).split(" ")[1] - # split by space, grab second, grab before \n - assignment_name = unedited_assignment_name[1:].split("\\")[0] + # if they have a name field + if len(data) > 1: + for i in range(len(data) - 1): + if str(data[i]).includes("{'name':"): + # ex. need to go from {'name': 'top\n'} to top: split by space + unedited_assignment_name = str(data.pop(1)) + # split by space, grab second, grab before \n + assignment_name = unedited_assignment_name[9:].split("\\")[0] return assignment_name From dc929082c12f5b97537c0170440920834f3c882c Mon Sep 17 00:00:00 2001 From: burgess01 Date: Wed, 7 Dec 2022 13:09:54 -0500 Subject: [PATCH 10/14] docs: simplify code structure --- gatorgrade/input/in_file_path.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/gatorgrade/input/in_file_path.py b/gatorgrade/input/in_file_path.py index 2d752c5a..bc02c362 100644 --- a/gatorgrade/input/in_file_path.py +++ b/gatorgrade/input/in_file_path.py @@ -49,9 +49,7 @@ def get_assignment_name(file: Path) -> (str): for i in range(len(data) - 1): if str(data[i]).includes("{'name':"): # ex. need to go from {'name': 'top\n'} to top: split by space - unedited_assignment_name = str(data.pop(1)) - # split by space, grab second, grab before \n - assignment_name = unedited_assignment_name[9:].split("\\")[0] + unedited_assignment_name = str(data[i])[9:].split("\\")[0] return assignment_name From 5ed598e0e8c2c84213a087abf8d25a7435cd6f0c Mon Sep 17 00:00:00 2001 From: burgess01 Date: Wed, 7 Dec 2022 13:12:16 -0500 Subject: [PATCH 11/14] docs: allow to work with extra spaces --- gatorgrade/input/in_file_path.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gatorgrade/input/in_file_path.py b/gatorgrade/input/in_file_path.py index bc02c362..6c5ab515 100644 --- a/gatorgrade/input/in_file_path.py +++ b/gatorgrade/input/in_file_path.py @@ -47,7 +47,7 @@ def get_assignment_name(file: Path) -> (str): # if they have a name field if len(data) > 1: for i in range(len(data) - 1): - if str(data[i]).includes("{'name':"): + if "{'name':" in str(data[i]): # ex. need to go from {'name': 'top\n'} to top: split by space unedited_assignment_name = str(data[i])[9:].split("\\")[0] From a1dc2dd3e9676dc9e32cdf24dd625db1df6b2e9e Mon Sep 17 00:00:00 2001 From: burgess01 Date: Wed, 7 Dec 2022 13:17:04 -0500 Subject: [PATCH 12/14] docs: change way name category is grabbed --- gatorgrade/input/in_file_path.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gatorgrade/input/in_file_path.py b/gatorgrade/input/in_file_path.py index 6c5ab515..bbee25d1 100644 --- a/gatorgrade/input/in_file_path.py +++ b/gatorgrade/input/in_file_path.py @@ -46,10 +46,11 @@ def get_assignment_name(file: Path) -> (str): # if they have a name field if len(data) > 1: - for i in range(len(data) - 1): - if "{'name':" in str(data[i]): + for i in range(len(data)): + if "'name':" in str(data[i]): # ex. need to go from {'name': 'top\n'} to top: split by space unedited_assignment_name = str(data[i])[9:].split("\\")[0] + print(data) return assignment_name From a3ef28fc18ae0a6ca604928ea8b463d6c23fc04b Mon Sep 17 00:00:00 2001 From: burgess01 Date: Wed, 7 Dec 2022 13:30:41 -0500 Subject: [PATCH 13/14] feature: pass checks and imp format --- gatorgrade/input/in_file_path.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gatorgrade/input/in_file_path.py b/gatorgrade/input/in_file_path.py index bbee25d1..64101126 100644 --- a/gatorgrade/input/in_file_path.py +++ b/gatorgrade/input/in_file_path.py @@ -40,6 +40,7 @@ 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 = str(file) + config_search_key = "{'name':" # change the file path into data to look through data = parse_yaml_file(file) @@ -47,10 +48,9 @@ def get_assignment_name(file: Path) -> (str): # if they have a name field if len(data) > 1: for i in range(len(data)): - if "'name':" in str(data[i]): + if config_search_key in str(data[i]): # ex. need to go from {'name': 'top\n'} to top: split by space - unedited_assignment_name = str(data[i])[9:].split("\\")[0] - print(data) + assignment_name = str(data[i])[10:].split("\\")[0] return assignment_name From fc5d9f3a0d6234b8ecf2220cc77046fa42f776ab Mon Sep 17 00:00:00 2001 From: burgess01 Date: Wed, 7 Dec 2022 13:36:41 -0500 Subject: [PATCH 14/14] feature: if no name print current dir --- gatorgrade/input/in_file_path.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gatorgrade/input/in_file_path.py b/gatorgrade/input/in_file_path.py index 64101126..ef2ae0b0 100644 --- a/gatorgrade/input/in_file_path.py +++ b/gatorgrade/input/in_file_path.py @@ -39,7 +39,7 @@ def parse_yaml_file(file_path: Path) -> List[Any]: 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 = str(file) + assignment_name = Path.cwd().name config_search_key = "{'name':" # change the file path into data to look through