pykubegrader package#

Subpackages#

Submodules#

pykubegrader.initialize module#

pykubegrader.initialize.initialize_assignment(name: str, week: str, assignment_type: str, verbose: bool = False, assignment_points: float | None = None, assignment_tag: str | None = None) dict[source]#

Initialize an assignment in a Jupyter environment.

Parameters:
  • name (str) – The name of the assignment.

  • url (str) – The URL of the API server.

  • verbose (bool) – Whether to print detailed initialization information.

Returns:

The responses dictionary after initialization.

Return type:

dict

Raises:

Exception – If the environment is unsupported or initialization fails.

pykubegrader.initialize.move_dotfiles()[source]#

Move essential dotfiles from a fixed source directory to the current working directory.

Raises:
pykubegrader.initialize.username_to_seed(username: str, mod: int = 1000) int[source]#

pykubegrader.telemetry module#

pykubegrader.telemetry.block_direct_notebook_calls(func)[source]#

Decorator to block direct calls to functions from Jupyter Notebooks.

This decorator checks if the current code is being executed directly from a Jupyter Notebook and raises an error if it is. This is useful to prevent accidental execution of grading functions from within the notebook environment.

pykubegrader.telemetry.encrypt_to_b64(message: str) str[source]#

Encrypts a message using the server’s public key and the client’s private key.

Parameters:

message (str) – The message to be encrypted.

Returns:

The encrypted message in base64 encoding.

Return type:

str

pykubegrader.telemetry.ensure_responses() dict[str, Any][source]#
pykubegrader.telemetry.get_all_students(user, password)[source]#

Fetches a list of all students from the API and returns their usernames.

Parameters:
  • user (str) – The username for HTTP basic authentication.

  • password (str) – The password for HTTP basic authentication.

Returns:

A list of usernames extracted from the students’ email addresses.

Return type:

list

Raises:

requests.exceptions.HTTPError – If the HTTP request returned an unsuccessful status code.

pykubegrader.telemetry.get_assignments_submissions(params=None)[source]#

Fetches assignment submissions for a student from the grading API. This function retrieves the assignment submissions for a student by making a GET request to the grading API. It requires certain environment variables to be set and validates the JupyterHub username. :param params: A dictionary of parameters to be sent in the query string. Defaults to None. If not provided, it will default to {“username”: <JUPYTERHUB_USER>}. :type params: dict, optional

Raises:
  • ValueError – If necessary environment variables (student_user, student_pw, api_base_url) are not set.

  • ValueError – If there is a mismatch between the JupyterHub username from the hostname and the environment variable.

Returns:

A dictionary containing the JSON response from the API with the assignment submissions.

Return type:

dict

pykubegrader.telemetry.get_my_grades() DataFrame[source]#
pykubegrader.telemetry.is_called_directly_from_notebook()[source]#

Checks if the current code is being executed directly from a Jupyter Notebook.

Returns:

True if the code is being executed from a Jupyter Notebook, False otherwise.

Return type:

bool

pykubegrader.telemetry.log_encrypted(logger: Logger, message: str) None[source]#

Logs an encrypted version of the given message using the provided logger.

Parameters:
  • logger (object) – The logger object used to log the encrypted message.

  • message (str) – The message to be encrypted and logged.

Returns:

None

pykubegrader.telemetry.log_variable(*args, **kwargs)[source]#
pykubegrader.telemetry.score_question(term: str = 'winter_2025') None[source]#
pykubegrader.telemetry.submit_question(student_email: str, term: str, assignment: str, question: str, responses: dict, score: dict) Response[source]#
pykubegrader.telemetry.telemetry(info: ExecutionInfo) None[source]#
pykubegrader.telemetry.update_responses(key: str, value) dict[source]#
pykubegrader.telemetry.upload_execution_log() None[source]#
pykubegrader.telemetry.verify_server(jhub_user: str | None = None) str[source]#

pykubegrader.utils module#

pykubegrader.utils.list_of_lists(options: list[Any]) bool[source]#
pykubegrader.utils.shuffle_options(options: list[Any], seed: int) None[source]#

Shuffle options in list[Optional[str]] or list[list[Optional[str]]]. Shuffling is done in place. We annotate options as list[Any] just to keep Mypy happy.

Parameters:
  • options (list[Any]) – List of options to shuffle

  • seed (int) – Seed for RNG

Returns:

None

pykubegrader.utils.shuffle_questions(desc_widgets: list[HTML], dropdowns: list[Select] | list[Column], seed: int) list[tuple[HTML, Select | Column]][source]#

pykubegrader.validate module#

pykubegrader.validate.generate_keys() Box[source]#
pykubegrader.validate.get_entries_len(data: list[str], question_number: int) int[source]#

function to get the unique entries by length

Parameters:
  • data (list) – list of all the data records

  • question_number (int) – question number to evaluate

Returns:

length of the unique entries

Return type:

int

pykubegrader.validate.get_last_entry(data: list[str], field_name: str) str[source]#
pykubegrader.validate.read_logfile(filepath: str, key_box=None) tuple[list[str], list[str]][source]#
pykubegrader.validate.submission_message(response: Response) None[source]#
pykubegrader.validate.validate_logfile(filepath: str, assignment_id: str, question_max_scores: dict[int, int], free_response_questions: int = 0, key_box=None) None[source]#
pykubegrader.validate.verify_login(login_data: dict[str, str], login_url: str) None[source]#

Module contents#