-
Notifications
You must be signed in to change notification settings - Fork 79
Allow verifying statements according to the new problem format #289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
122f0bc
Make cls templates able work with either problem format
ElliotRipa 4738fc1
Allow problem statement to use either problem format
ElliotRipa ab5f2b5
Make template.py detect format version instead
ElliotRipa 60c7504
Provisional updates
ElliotRipa a7676d9
Add formatversion.py
ElliotRipa be21d6f
Minor fixes in imports
ElliotRipa 9a9cc38
Move version specific functionality to separate file
ElliotRipa c531bc3
Change to flag '-v' for format-version
ElliotRipa d235ba0
Add missing parentheses
ElliotRipa 4496918
Use dictionary instead of data objects for format data
ElliotRipa e71dbf9
Make problem2html.py use -v to specify format version
ElliotRipa b59ce65
Add constants for version names
ElliotRipa b805d01
Rollback problemset_0.1.cls
ElliotRipa 2aa9be0
Move initialisation of FORMAT_DATA to setup
ElliotRipa 470fbb8
Make formatversion.py use dataobjects instead of dicts
ElliotRipa cba93dc
Fix documentation
ElliotRipa f964bc3
Remove unnecessary initialisation
ElliotRipa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| import os | ||
| import yaml | ||
| from dataclasses import dataclass | ||
|
|
||
|
|
||
| VERSION_LEGACY = "legacy" | ||
| VERSION_2023_07 = "2023-07" | ||
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
| class FormatData: | ||
| """ | ||
| A class containing data specific to the format version. | ||
| name: the version name. | ||
| statement_directory: the directory where the statements should be found. | ||
| statement_extensions: the allowed extensions for the statements. | ||
| """ | ||
| name: str | ||
| statement_directory: str | ||
| statement_extensions: list[str] | ||
|
|
||
|
|
||
| FORMAT_DATACLASSES = { | ||
| VERSION_LEGACY: FormatData(name=VERSION_LEGACY, statement_directory="problem_statement", statement_extensions=["tex"]), | ||
| VERSION_2023_07: FormatData(name=VERSION_2023_07, statement_directory="statement", statement_extensions=["md", "tex"]) | ||
| } | ||
|
|
||
|
|
||
| def detect_problem_version(path) -> str: | ||
| """ | ||
| Returns the problem version value of problem.yaml or throws an error if it is unable to read the file. | ||
| Args: | ||
| path: the problem path | ||
|
|
||
| Returns: | ||
| the version name as a String | ||
|
|
||
| """ | ||
| config_path = os.path.join(path, 'problem.yaml') | ||
| try: | ||
| with open(config_path) as f: | ||
| config: dict = yaml.safe_load(f) or {} | ||
| except Exception as e: | ||
| raise VersionError(f"Error reading problem.yaml: {e}") | ||
| return config.get('problem_format_version', VERSION_LEGACY) | ||
|
|
||
|
|
||
| def get_format_data(path): | ||
| """ | ||
| Gets the dataclass object containing the necessary data for a problem format. | ||
| Args: | ||
| path: the problem path | ||
|
|
||
| Returns: | ||
| the dataclass object containing the necessary data for a problem format | ||
|
|
||
| """ | ||
| return get_format_data_by_name(detect_problem_version(path)) | ||
|
|
||
|
|
||
| def get_format_data_by_name(name): | ||
| """ | ||
| Gets the dataclass object containing the necessary data for a problem format given the format name. | ||
| Args: | ||
| name: the format name | ||
|
|
||
| Returns: | ||
| the dataclass object containing the necessary data for a problem format | ||
|
|
||
| """ | ||
| data = FORMAT_DATACLASSES.get(name) | ||
| if not data: | ||
| raise VersionError(f"No version found with name {name}") | ||
| else: | ||
| return data | ||
|
|
||
|
|
||
| class VersionError(Exception): | ||
| pass | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't this be implemented as
return get_format_data_by_name(detect_problem_version(path))to avoid code duplication?