Source

Source Report Data

Field

Type

Initial

Description

substitutions

List[Substitution]

[]

The history of previous source codes before the latest substitutions.

success

bool

None

Whether the current file has been parsed successfully.

ast

ast.Ast

None

The root node of the latest successfully parsed chunk of code.

get_original_program(report=<pedal.core.report.Report object>) str[source]

Retrieves the original version of the Submission’s main code, ignoring all subsitutions. :param report:

Returns:

get_program(report=<pedal.core.report.Report object>) str[source]

Retrieves the current main file’s code.

reset(report=<pedal.core.report.Report object>)[source]

Resets the Source tool back to its initial configuration, removing any previously stored code/parses/section info.

Parameters:

report – The report object to be reseting.

Returns:

The data associated with the Source tool.

Return type:

dict

restore_code(report=<pedal.core.report.Report object>)[source]
Parameters:

report

set_source(code, filename='answer.py', sections=False, independent=False, report=<pedal.core.report.Report object>)[source]

Sets the contents of the Source to be the given code. Can also be optionally given a filename. If there is no existing Submission, this contextualizes the Report with a new Submission containing the given code. Otherwise, it creates a Substitution and temporarily replaces the Submission’s current main code.

Parameters:
  • code (str) – The contents of the source file.

  • filename (str) – The filename of the students’ code. Defaults to answer.py.

  • sections (str or bool) – Whether the file should be divided into sections. If a str, then it should be a Python regular expression for how the sections are separated. If False, there will be no sections. If True, then the default pattern will be used: ‘^##### Part (d+)$’

  • independent (bool) – Whether the separate sections should be considered separate or all existing in an accumulating namespace.

  • report (Report) – The report object to store data and feedback in. If left None, defaults to the global MAIN_REPORT.

set_source_file(filename: str, sections=False, independent=False, report=<pedal.core.report.Report object>)[source]

Uses the given filename on the filesystem as the new main file.

Parameters:
  • filename (str or list[str]) – Checks the files, in the given order, to be loaded. If a single string is given, we check if there is a “;” and separate it as multiple options. If a file isn’t found, then the next option in the list is tried. If “.py” is the ending of a given option, then the first Python file found will be used, respecting any directories given (e.g., `”.py”` finds any in this directory, while "source/*.py" finds the first Python file in the source/ directory). If no files are found, the source_file_not_found feedback will be delivered.

  • sections

  • independent

  • report

Returns:

verify(code=None, filename='answer.py', report=<pedal.core.report.Report object>, muted=False, enhance=True)[source]

Parses the given source code and checks for syntax errors; if no code is given, defaults to the current Main file of the submission.

Parameters:
  • enhance (bool) – Whether to use native Python error messages or the Pedal enhanced ones.

  • muted – Whether this Feedback should be considered for showing to the student.

  • code (str) – Some code to parse and syntax check.

  • filename (str) – An optional filename to use

  • report

Returns:

verify_section(code=None, filename='answer.py', report=<pedal.core.report.Report object>, muted=False, enhance=True)

Parses the given source code and checks for syntax errors; if no code is given, defaults to the current Main file of the submission.

Parameters:
  • enhance (bool) – Whether to use native Python error messages or the Pedal enhanced ones.

  • muted – Whether this Feedback should be considered for showing to the student.

  • code (str) – Some code to parse and syntax check.

  • filename (str) – An optional filename to use

  • report

Returns: