logbookgenerator.computation package¶
Submodules¶
logbookgenerator.computation.code_processing module¶
code_processing.py: Contains the functions for processing the code files.
- logbookgenerator.computation.code_processing.process_block_comment(comment_lines: list[str], code_lines: list[str], task_comments: dict[str, list[tuple[str, str]]]) tuple[list[str], list[str], dict[str, list[tuple[str, str]]]]¶
Process a block comment to extract answer comments and related code.
- Parameters:
comment_lines (list[str]) – The comment lines.
code_lines (list[str]) – The code lines.
task_comments (dict[str, list[tuple[str, str]]]) – A dictionary where keys are task identifiers and values are lists of tuples containing comments and associated code.
- Returns:
The updated comment lines, code lines, and task comments.
- Return type:
tuple[list[str], list[str], dict[str, list[tuple[str, str]]]]
- Raises:
ValueError – If the block comment is empty.
- logbookgenerator.computation.code_processing.process_code_comments(code_lines: list[str], remove_comments: bool = False) tuple[dict[str, list[tuple[str, str]]] | str, str | None]¶
Process the C++ code to extract answer comments and related code.
- Parameters:
code_lines (list[str]) – The code lines.
remove_comments (bool, optional) – Whether to remove comments from the code, by default False
- Returns:
The task comments, or the code as a string, and any remaining code lines, if remove_comments is True.
- Return type:
tuple[dict[str, list[tuple[str, str]]] | str, str | None]
Notes
The resulting dictionary is in the form: {
- “task_{task_number}_{subtask_number}”: [
(“The comment”, “The associated code”), …
}
- logbookgenerator.computation.code_processing.process_inline_comment(comment_line: str, code_lines: list[str], task_comments: dict[str, list[tuple[str, str]]]) tuple[str, list[str], dict[str, list[tuple[str, str]]]]¶
Process an inline comment to extract answer comments and related code.
- Parameters:
comment_line (str) – The comment line.
code_lines (list[str]) – The code lines.
task_comments (dict[str, list[tuple[str, str]]]) – A dictionary where keys are task identifiers and values are lists of tuples containing comments and associated code.
- Returns:
The updated comment line, code lines, and task comments.
- Return type:
tuple[str, list[str], dict[str, list[tuple[str, str]]]]
logbookgenerator.computation.comment_extraction module¶
comment_extraction.py: Contains the functions for extracting comments from the code files.
- logbookgenerator.computation.comment_extraction.extract_block_comment(code_lines: list[str], line_number: int) tuple[list[str], int]¶
Extract a block comment from the code lines.
- Parameters:
code_lines (list[str]) – The code lines.
line_number (int) – The line number of the block comment start.
- Returns:
list[str] – The block comment lines.
int – The line number of the last line of the block comment.
- logbookgenerator.computation.comment_extraction.extract_comment_code(comment_lines: list[str], line_number: int) tuple[str, int]¶
Extract the comment and code from the comment lines.
- Parameters:
comment_lines (list[str]) – The comment lines.
line_number (int) – The line number of the comment start.
- Returns:
str – The comment content.
int – The line number of the last line of the comment.
- logbookgenerator.computation.comment_extraction.extract_comment_content(comment_lines: list[str]) str¶
Extract the comment content from the comment lines.
- Parameters:
comment_lines (list[str]) – The comment lines.
- Returns:
The comment content.
- Return type:
str
- logbookgenerator.computation.comment_extraction.extract_comment_id(comment_line: str) str¶
Extract the comment identifier from the comment line.
- Parameters:
comment_line (str) – The comment line.
- Returns:
The comment identifier.
- Return type:
str
logbookgenerator.computation.config_generation module¶
config_generation.py: Generate the configuration file for the logbook.
- logbookgenerator.computation.config_generation.build_config_file() Path¶
Builds the YAML config file with user input.
- Returns:
The path to the configuration file.
- Return type:
Path
Notes
The generated YAML file will have the following structure: ``` — module:
code: <module_code> name: <module_name> semester: <module_semester> year: <module_year>
- statement:
text: <statement_text>
- student:
id: <student_id> name: <student_name>
- university:
department: <university_department> name: <university_name> start: <university_start>
logbookgenerator.computation.context_generation module¶
context_generation.py: Contains the functions for generating the context for the logbook.
- logbookgenerator.computation.context_generation.generate_coursework_context(coursework_files: dict[str, str]) tuple[dict[str, Any], dict[str, str]]¶
Generate the coursework context.
- Parameters:
coursework_files (dict[str, str]) – The coursework files.
- Returns:
The coursework context and clean codes.
- Return type:
tuple[dict[str, Any], dict[str, str]]
Notes
The clean code is the code without any comments. The coursework context is a dictionary in the form: {
- “file_name”: {
- “task_{task_number}_{subtask_number}”: [
(“The comment”, “The associated code”), …
}
- logbookgenerator.computation.context_generation.generate_logbook_contexts(config: dict[str, Any], weekly_files: list[dict[str, dict[str, str] | str]], coursework_files: dict[str, str], references: list[dict[str, str]]) tuple[dict[str, Any], dict[str, Any] | None, dict[str, str] | None]¶
Generate the contexts for the logbook.
- Parameters:
config (dict[str, Any]) – The configuration file.
weekly_files (list[dict[str, dict[str, str] | str]]) – The weekly files, containing the CPP files and reflections.
coursework_files (dict[str, str]) – The coursework files.
references (list[dict[str, str]]) – The references.
- Returns:
The logbook contexts, coursework context, and clean coursework code.
- Return type:
tuple[dict[str, Any], dict[str, Any] | None, dict[str, str] | None]
- logbookgenerator.computation.context_generation.generate_tasks_context(cpp_files: dict[str, str]) dict[str, Any]¶
Generate the tasks context.
- Parameters:
cpp_files (dict[str, str]) – The CPP files.
- Returns:
The tasks context.
- Return type:
dict[str, Any]
- logbookgenerator.computation.context_generation.generate_week_context(week_number: int, week_start_date: datetime, week_end_date: datetime, weekly_file: dict[str, dict[str, str] | str]) dict[str, Any]¶
Generate the week context.
- Parameters:
week_number (int) – The week number.
week_start_date (datetime) – The start date of the week.
week_end_date (datetime) – The end date of the week.
weekly_file (dict[str, dict[str, str] | str]) – The weekly file, containing the CPP files and reflections.
- Returns:
The week context.
- Return type:
dict[str, Any]
- logbookgenerator.computation.context_generation.generate_weeks_context(weekly_files: list[dict[str, dict[str, str] | str]], start_date: datetime) dict[str, Any]¶
Generate the weeks context.
- Parameters:
weekly_files (list[dict[str, dict[str, str] | str]]) – The weekly files, containing the CPP files and reflections.
start_date (datetime) – The start date of the university.
- Returns:
The weeks context.
- Return type:
dict[str, Any]
logbookgenerator.computation.parsing module¶
parsing.py: Contains the functions for parsing the input directory.
- logbookgenerator.computation.parsing.parse_input_directory(input_directory: Path) tuple[list[dict[str, dict[str, str] | str]], dict[str, str], list[dict[str, str]]]¶
Parse the input directory.
- Parameters:
input_directory (Path) – Path to the input directory.
- Returns:
The weekly files (code and reflections), coursework files, and references.
- Return type:
tuple[list[dict[str, dict[str, str] | str]], dict[str, str], list[dict[str, str]]]
- logbookgenerator.computation.parsing.parse_weekly_directories(input_directory: Path) tuple[list[dict[str, dict[str, str] | str]], dict[str, str]]¶
Parse the weeks directory.
- Parameters:
input_directory (Path) – Path to the input directory.
- Returns:
The CPP files and reflections for each week, given as a list of weeks, where each week has keys “cpp” and “reflection”, each containing a dictionary of files or a string respectively. Also returns the coursework files.
- Return type:
tuple[list[dict[str, dict[str, str] | str]], dict[str, str]]
logbookgenerator.computation.render_context module¶
render_context.py: Contains the logic for rendering the context into a logbook.
- logbookgenerator.computation.render_context.create_coursework(coursework_context: dict[str, Any]) str¶
Create the coursework from the context.
- Parameters:
coursework_context (dict) – The contexts to render into the coursework.
Notes
This function renders each part of the coursework and then combines them into the final markdown coursework.
- logbookgenerator.computation.render_context.create_logbook(logbook_contexts: dict[str, Any]) str¶
Create the logbook from the contexts.
- Parameters:
logbook_contexts (dict) – The contexts to render into the logbook.
Notes
This function renders each part of the logbook and then combines them into the final markdown logbook.
- logbookgenerator.computation.render_context.render_template(template_path: Path, context: dict[str, Any]) str¶
Render the template with the context.
- Parameters:
template_path (Path) – Path to the template.
context (dict[str, Any]) – Context to render the template.
- Returns:
Rendered template.
- Return type:
str
- Raises:
FileNotFoundError – If the template does not exist.
jinja2.exceptions.TemplateSyntaxError – If there is a syntax error in the template.
Module contents¶
Computation package for the project.