Source
Imported as:
from pedal.source import *
- verify()
Parses the current main code of the submission and reports any syntax errors as feedback. You can actually pass in explicit code and filename as strings, but by default uses the current submission.
- set_source(code: str, filename: str)
Convenience function for overriding the current submission with some other code. Any checks that use the main code of the submission will use this code instead. No longer necessary, mostly a legacy solution in light of the new contextualization through submissions.
- restore_code()
Undoes the latest set_source.
Sections
- separate_into_sections(pattern='^(##### Part .+)$')
Breaks the current main code file into multiple sections using the regular expression
pattern
. The first section will be set as the main code submission, and you can advance through to the next one by callingnext_section()
, or verify that there are the right number of sections withcheck_section_exists()
.
- check_section_exists(number: int)
Verifies that the right number of expected sections exist after a separation is performed. Otherwise, creates new feedback indicating the issue. The prologue before the first section is 0, while subsequent ones are 1, 2, 3, etc. So if you have 3 sections in your code plus the prologue, you should pass in 3 and not 4 to verify that all of them exist.
- next_section()
Moves the current submission main code to be the next section that was found during separation. If used when there are no more sections, the
not_enough_sections
feedback is given.
- stop_sections()
Removes any separations and restores the main code submission back to a single file.
Source Feedbacks
Feedback Function: No Source Code- Label: blank_source
- Justification: After stripping the code, there were no characters.
- Response: Source code file is blank.
- Label: not_enough_sections
- Justification: Section index exceeded the length of the separated sections list.
- Response: Tried to advance to next section but the section was not found. Tried to load section {count}, but there were only {found} sections.
- Label: source_file_not_found
- Justification: IOError while opening file to set_source
- Response: The given filename {name:filename} was either not found or could not be opened. Please make sure the file is available.
- Label: syntax_error
- Justification: Syntax error was triggered while calling ast.parse
- Response: Bad syntax on line {lineno:line}. {traceback_preamble}{traceback_message} {exception_message}{suggestion_message}
- Label: incorrect_number_of_sections
- Response: Incorrect number of sections in your file. Expected {count}, but only found {found}