-
Notifications
You must be signed in to change notification settings - Fork 7
Improve file handling for stdin #608
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
Changes from all commits
4c4f7ae
1162799
b14b935
9475ad7
868ac78
19b04b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| import itertools | ||
| import logging | ||
| import shutil | ||
| from pathlib import Path | ||
|
|
||
| from attrs import define | ||
|
|
@@ -16,6 +17,7 @@ | |
| ) | ||
| from tested.languages.conventionalize import selector_name | ||
| from tested.languages.preparation import exception_file, value_file | ||
| from tested.testsuite import ContentPath | ||
| from tested.utils import safe_del | ||
|
|
||
| _logger = logging.getLogger(__name__) | ||
|
|
@@ -180,6 +182,26 @@ def set_up_unit( | |
| # See https://github.com/dodona-edu/universal-judge/issues/57 | ||
| destination.hardlink_to(origin) | ||
|
|
||
| # Create dynamically generated files if necessary. | ||
| dynamically_generated_file = unit.get_dynamically_generated_files() | ||
| if dynamically_generated_file is not None: | ||
| destination = execution_dir / dynamically_generated_file.path | ||
|
|
||
| if isinstance(dynamically_generated_file.content, ContentPath): | ||
| _logger.debug( | ||
| f"Copying input file %s to %s", | ||
| dynamically_generated_file.content.path, | ||
| destination, | ||
| ) | ||
| source_file = ( | ||
| bundle.config.resources / dynamically_generated_file.content.path | ||
| ) | ||
| shutil.copy2(source_file, destination) | ||
| else: | ||
| _logger.debug(f"Creating dynamically generated file %s", destination) | ||
| destination.parent.mkdir(parents=True, exist_ok=True) | ||
| destination.write_text(dynamically_generated_file.content) | ||
|
Comment on lines
+190
to
+203
|
||
|
|
||
| return execution_dir, dependencies | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -128,12 +128,16 @@ def get_readable_input( | |||||
| args = f"$ {command}" | ||||||
| # Determine the stdin | ||||||
| if isinstance(case.input.stdin, TextData): | ||||||
| stdin = case.input.stdin.get_data_as_string(bundle.config.resources) | ||||||
| if case.input.stdin.path is not None: | ||||||
| stdin = Path(case.input.stdin.path) | ||||||
| else: | ||||||
| stdin = case.input.stdin.get_data_as_string(bundle.config.resources) | ||||||
| else: | ||||||
| stdin = "" | ||||||
|
|
||||||
| # If we have both stdin and arguments, we use a here-document. | ||||||
| if case.input.arguments and stdin: | ||||||
| if stdin and isinstance(stdin, Path): | ||||||
| text = f"${args} < {stdin}" | ||||||
|
||||||
| text = f"${args} < {stdin}" | |
| text = f"$ {args} < {stdin}" |
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.
The error message "Invalid stdin content is required but got..." is misleading when neither content nor path is provided. Consider improving it to something like "stdin requires either 'content' or 'path' field, but neither was provided" to better reflect the actual error condition.