-
Notifications
You must be signed in to change notification settings - Fork 78
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
Conversation
Can we read problem.yaml for this? As a problemtools user, having to pass -F every time will be very annoying. |
Agreed. If |
|
I think it would be nice to change DIR_END to something more clear such as STATEMENT_DIR. Additionally, I dislike having a copy of Also, it would be probably be wise to use constants instead of hard-coding strings such as "2023-07". Perhaps create a file version.py that has these constants, the Finally, I think version "default" is strange. It would probably be better to explicitly set a default problem version that exists, i.e., legacy. |
|
@Matistjati I think your input is very valid and think it makes a lot of sense. I am a little unsure what DIR_END stands for or does but STATEMENT_DIR makes more sense. Having a copy of Should there be one latex template per format maybe? Instead of checking for the old folder then the new. It feels like it could build up to a mess over time. Maybe also throwing a VersionError instead of a generic RuntimeError would be a good idea. |
|
It could also be argued that when splitting it into version.py that the |
|
Alright, this feedback seems reasonable, thanks. I'll try to implement these changes |
|
The code specific to certain format versions has now been moved to a separate file, and the feedback provided here has been implemented. Also, the format-version flag was changed to -v to stay consistent with similar functions in verifyproblem.py and made optional to use automatic detection |
problemtools/verifyproblem.py
Outdated
| if not self.statements: | ||
| allowed_statements = ', '.join(f'problem.{ext}, problem.[a-z][a-z].{ext}' for ext in self.EXTENSIONS) | ||
| self.error(f'No problem statements found (expected file of one of following forms in folder problem_statement/: {allowed_statements}') | ||
| allowed_statements = ', '.join(f'problem.{ext}, problem.[a-z][a-z].{ext}' for ext in STATEMENT_DATA.get_statement_extensions) |
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.
You probably meant to call STATEMENT_DATA.get_statement_extensions here.
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.
Yes, you're right. Thank you
|
There were some good changes here! However:
Overall good improvements. |
|
The flag has been changed to be -v in both places now. Also the data objects in formatversion.py have been replaced with a dictionary instead. |
|
I don't see any constants? Concretely, my suggestion is to expose This way, you can use Also, didn't we agree to not touch problemset_0.1.cls? Since any packages using that one are likely invalid in the 2023-07 format. |
|
I don't fully see the point of get_format_data, when you could just index the dictionary. As I see it, you would use More importantly, I think the code is suffering a little from all the changes and should be polished and cleaned up. |
The reason for Having As for the second half of the comment, it seemed to work fine for me without crashing, but I see no real reason to keep it in |
I can add those as well. The main reason for not having that as a priority currently was since it likely won't be used in the code for the statements, nor specific to this PR in any greater extent than this provides some extra overhead for the format versioning itself.
Yes, I can revert that back to the previous version |
|
Nice! Given my (comparatively limited) knowledge, I think we're ready to merge. @Zazmuz @square-cylinder opinions? |
|
Also @ElliotRipa, for the future, please rebase instead of merging. Currently, ~40% of the commits in this PR are merges, and it makes it harder to follow. |
gkreitz
left a comment
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.
Overall, this looks good. I added some minor comments, somewhat on the picky side.
This will need to be rebased, as there are merge conflicts. When rebasing, please also consider squishing a bit to get a cleaner commit history for this PR.
problemtools/formatversion.py
Outdated
| The data specific to any given format version. | ||
| """ | ||
| FORMAT_DATA = { | ||
| "legacy": { |
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.
You probably want to use the VERSION_* constants in this dict rather than copy-pasting the values.
| """ | ||
| Returns a dictionary containing the necessary data for a file format. | ||
| """ | ||
| def get_format_data(path): |
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?
problemtools/formatversion.py
Outdated
|
|
||
|
|
||
| """ | ||
| Returns a dictionary containing the necessary data for a file format. |
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.
These functions should document what keys the dict has. "The necessary data" is pretty vague. :)
(The best/easiest way to document what keys to expect would be to return a dataclass rather than a dict.)
problemtools/formatversion.py
Outdated
| VERSION_2023_07 = "2023-07" | ||
|
|
||
|
|
||
| """ |
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.
AFAIK, docstrings should be the first thing in the function, not before?
problemtools/verifyproblem.py
Outdated
| PART_NAME = 'statement' | ||
|
|
||
| EXTENSIONS = [] | ||
| FORMAT_DATA = None |
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.
Why is this in all caps when it seems to be an instance variable?
Also, why are you initializing it here?
problemtools/template.py
Outdated
| else: | ||
| version_data = formatversion.get_format_data_by_name(version) | ||
|
|
||
| stmtdir = os.path.join(problemdir, version_data.get('statement_directory')) |
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.
Is there a reason you index the version data dict with get? I think the vast majority of the code base indexes dicts using brackets. (This comment applies throughout the PR in a lot of places).
|
All right, the changes have been implemented now. I wound up changing to a dataclass instead of a dict, and I also rebased to get a cleaner commit history |
Overview