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

WIP: Add typing hint for src codes #99

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gatorgrade/generate/generate.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Generate a YAML file with default messages and specific paths."""
import os
from typing import List, Dict
import yaml
import yaml # type: ignore
import typer


Expand Down
2 changes: 1 addition & 1 deletion gatorgrade/input/command_line_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def generate_checks(
Returns:
A list of ShellChecks and GatorGraderChecks.
"""
checks = []
checks: List[Union[ShellCheck, GatorGraderCheck]] = []
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:
Expand Down
15 changes: 9 additions & 6 deletions gatorgrade/input/in_file_path.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""Generates a list of commands to be run through gatorgrader."""
from collections import namedtuple
from typing import List
import yaml
from pathlib import Path
from typing import List, Union
import yaml # type: ignore
from gatorgrade.input.set_up_shell import run_setup

# Represent data for a check from the configuration file.
Expand All @@ -10,24 +11,26 @@
CheckData = namedtuple("CheckData", ["file_context", "check"])


def parse_yaml_file(file_path):
def parse_yaml_file(file_path: Path) -> List:
"""Parse a YAML file and return its contents as a list of dictionaries."""
with open(file_path, encoding="utf8") as file:
data = yaml.load_all(file, Loader=yaml.FullLoader)
return list(data)


def reformat_yaml_data(data):
def reformat_yaml_data(data: List) -> List[CheckData]:
"""Reformat the raw data from a YAML file into a list of tuples."""
reformatted_data = []
reformatted_data: List[CheckData] = []
if len(data) == 2:
setup_commands = data.pop(0) # Removes the setup commands
run_setup(setup_commands)
add_checks_to_list(None, data[0], reformatted_data)
return reformatted_data


def add_checks_to_list(path, data_list, reformatted_data) -> List[CheckData]:
def add_checks_to_list(
path: Union[None, str], data_list: List, reformatted_data: List[CheckData]
):
"""Recursively loop through the data and add checks that are found to the reformatted list."""
current_path = path # Saves the current path to keep track of the location
for ddict in data_list:
Expand Down
6 changes: 5 additions & 1 deletion gatorgrade/input/parse_config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
"""Returns the list of commands to be run through gatorgrader."""
from pathlib import Path
from typing import List, Union
from gatorgrade.input.checks import ShellCheck, GatorGraderCheck

from gatorgrade.input.command_line_generator import (
generate_checks,
) # Import function to generate shell and gatorgrader checks
Expand All @@ -8,7 +12,7 @@
) # Import functions to parse and set up yaml file


def parse_config(file):
def parse_config(file: Path) -> List[Union[ShellCheck, GatorGraderCheck]]:
"""Parse the input yaml file and generate specified checks.

Args:
Expand Down
3 changes: 2 additions & 1 deletion gatorgrade/input/set_up_shell.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
"""Set-up the shell commands."""

from typing import Dict
import subprocess
import typer


def run_setup(front_matter):
def run_setup(front_matter: Dict):
"""Run the shell set up commands and exit the program if a command fails.

Args:
Expand Down
2 changes: 1 addition & 1 deletion gatorgrade/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def generate(
),
):
"""Generate a gatorgrade.yml file."""
targets = []
targets: List[str] = []
for path in paths:
targets.extend(glob.iglob(path.as_posix(), recursive=True))
generate_config(targets, root.as_posix())
Expand Down
157 changes: 105 additions & 52 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,17 @@ mkdocs-gen-files = "^0.3.4"
mkdocs-typer = "^0.0.2"
mkdocs-literate-nav = "^0.4.1"
toml = "^0.10.2"
mypy = "^0.971"


[tool.taskipy.tasks]
test = { cmd = "pytest --cov-report term-missing --cov-branch --cov=gatorgrade tests/", help = "Run the pytest test suite" }
lint = "task black && task pylint && task pydocstyle"
lint = "task black && task pylint && task pydocstyle && task mypy"
black = { cmd= "black gatorgrade/ tests/ --check", help = "Run the black checks for source code format" }
pylint = { cmd = "pylint gatorgrade/ tests/", help = "Run the pylint checks for source code documentation" }
pydocstyle = { cmd = "pydocstyle gatorgrade/ tests/", help = "Run the pydocstyle checks for source code documentation" }
mkdocs = { cmd = "mkdocs gh-deploy", help = "Build and deploy MKDocs documentation" }
mypy = { cmd = "mypy gatorgrade/ tests --ignore-missing-imports", help = "Run the mypy checks for source code static type"}

[build-system]
requires = ["poetry-core>=1.0.0"]
Expand Down