-
Notifications
You must be signed in to change notification settings - Fork 82
Extract graders model #474
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
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
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,24 @@ | ||
| """Checks for a problem package's custom graders.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from ..diagnostics import Diagnostics | ||
| from ..metadata import Metadata | ||
| from ..model import Graders | ||
|
|
||
|
|
||
| def check_graders(graders: Graders, metadata: Metadata, diag: Diagnostics) -> None: | ||
| """Run all checks on a problem's custom graders.""" | ||
| if len(graders.graders) > 1: | ||
| diag.fatal('There is more than one custom grader') | ||
|
|
||
| grader = graders.grader | ||
| if grader is None: | ||
| return | ||
|
|
||
| if metadata.is_pass_fail(): | ||
| diag.fatal('There is a grader but the problem is pass-fail') | ||
|
|
||
| success, msg = grader.compile() | ||
| if not success: | ||
| diag.fatal(f'Compile error for {grader}', msg) |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from dataclasses import dataclass, field | ||
| from pathlib import Path | ||
|
|
||
| from ..languages import Languages | ||
| from ..run import Program, find_programs, get_tool | ||
|
|
||
| DEFAULT_GRADER = get_tool('default_grader') | ||
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
| class Graders: | ||
| """A problem's graders: custom grader programs found on disk, if any.""" | ||
|
|
||
| graders: list[Program] = field(default_factory=list) | ||
|
|
||
| @property | ||
| def grader(self) -> Program | None: | ||
| """The custom grader, if there's exactly one; None if there are zero (default grading is used). | ||
|
|
||
| Does not validate that there's at most one grader; callers that care about the invalid | ||
| case of more than one custom grader must check `len(graders)` themselves and report it.""" | ||
| return self.graders[0] if len(self.graders) == 1 else None | ||
|
|
||
|
|
||
| def load_graders(probdir: Path, language_config: Languages, work_dir: str) -> Graders: | ||
| graders = find_programs(str(probdir / 'graders'), language_config=language_config, work_dir=work_dir) | ||
| return Graders(graders=graders) |
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.
Uh oh!
There was an error while loading. Please reload this page.