grader.utils package

Submodules

grader.utils.cli module

Module containing the CLI arguments parser.

grader.utils.cli.get_args() dict[str, Any][source]

Create the CLI parser and return the parsed arguments

My personal preference is to return a dictionary, instead of the normal argparse.Namespace object. :returns: Dictionary, containing the parsed arguments

grader.utils.config module

Module for loading the configuration file.

exception grader.utils.config.InvalidConfigError[source]

Bases: Exception

Custom exception for invalid configuration files.

grader.utils.config.load_config(config_file_path: str) dict[source]

Load the configuration file. :param config_file_path: Path to the configuration file. :return: The configuration as a dictionary.

grader.utils.constants module

Module containing the constants

grader.utils.files module

Module containing the file-related functions.

grader.utils.files.find_all_files_under_directory(directory: str, extension: str) list[str][source]

Find all files under a directory with a specific extension.

Parameters:
  • directory – The directory to search in

  • extension – The extension of the files to search for

Returns:

A list of all files under the directory with the specified extension

Return type:

list[str]

grader.utils.files.find_all_python_files(project_root_dir: str) list[str][source]

Find all python files in the project directory

Parameters:

project_root_dir – The path to the project directory

Returns:

A list of all python files in the project directory

grader.utils.files.find_all_source_files(project_root_dir: str) list[str][source]

Find all source files in the project directory

Parameters:

project_root_dir – The path to the project directory

Returns:

A list of all source files in the project directory

grader.utils.files.find_all_test_files(tests_directory: str | None = None) list[str][source]

Find all test files in the project directory

Parameters:

tests_directory – The tests directory, defaults to None

Returns:

A list of all test files in the project directory. If no tests directory is found, return an empty list

grader.utils.files.get_tests_directory_name(project_root_dir: str) str | None[source]

Check if the project directory contains a tests directory.

Parameters:

project_root_dir – The path to the project directory

Returns:

The path to the tests directory if found, otherwise None

Return type:

Optional[str]

grader.utils.logger module

Module containing the logger setup function and the custom VERBOSE level.

grader.utils.logger.setup_logger(student_id: str | None = None, verbosity: int = 0) Logger[source]

Setup the logger with the given verbosity level and student id

Parameters:
  • student_id – The id of the student. Defaults to None.

  • verbosity – . Defaults to 0.

Returns:

The configured logger object.

Return type:

logging.Logger

grader.utils.process module

Module containing a wrapper for launching shell commands

grader.utils.process.run(command: list[str], current_directory: str | None = None) CompletedProcess[str][source]

Execute a command in the terminal. Wraps the subprocess.run function, with the check=False, capture_output=True and text=True flags.

If the command passes, log the stdout. If the command fails, log the returncode, stdout and stderr.

Parameters:

command – The command to execute

Returns:

The output of the command (returncode, stdout, stderr)

grader.utils.virtual_environment module

Module containing the virtual environment class.

class grader.utils.virtual_environment.VirtualEnvironment(project_path: str)[source]

Bases: object

Class that handles the creation and deletion of a virtual environment. Acts as a context manager. Everything executed within it, can assume that the venv is setup.

is_initialized = False
setup()[source]

Setup the virtual environment. Check if there is an existing venv, if so, delete it. Check if there is a requirements.txt file. Create a new venv and install the requirements. Install the grader dependencies as well.

teardown()[source]

Delete the virtual environment.

exception grader.utils.virtual_environment.VirtualEnvironmentError[source]

Bases: Exception

Exception raised when an error occurs during the virtual environment setup.

Module contents