-
Notifications
You must be signed in to change notification settings - Fork 5
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
Update default interpretation of YAML strings and objects #457
Merged
Conversation
This file contains 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
YAML strings and objects are now interpreted as literal YAML values by default. We introduce `!expression` and `!oracle` to "cast" strings and objects to expressions and oracles respectively. The list of arguments in an oracle uses the same logic: YAML types by default, expressions when tagged as such. Using the same logic for arguments is not that obvious: we could also force the use of the expression syntax, as we do with actual expressions and statements. However, it felt more natural to be consistent with the return value (which is in the same YAML object) than with the expressions and statements. This is basically a reversal of the previous behaviour, where strings and objects needed a `!v` tag. This tag has now been removed.
dodona-server
added a commit
to dvanderfaeillie/comp-denken-sjc
that referenced
this pull request
Nov 19, 2023
See dodona-edu/universal-judge#457 for more information
All exercise repositories have been migrated on Dodona and changes pushed where possible. For posterity, this is the migration script that was run: migrate.pyimport re
import shlex
import subprocess
from pathlib import Path
print("*** Migrating stuff ***")
print(f"Working inside {Path.cwd()}.")
cwd = Path.cwd()
all_contents = sorted(cwd.iterdir())
excluded_repositories = ["TESTed_challenges.git", "javascript-oefeningen"]
start_index = 0
for i, potential_repo in enumerate(all_contents[start_index:], start=start_index):
if not potential_repo.is_dir():
print(f"Skipping {potential_repo} as it is not a directory.")
continue
if potential_repo.name in excluded_repositories:
print(f"Skipping {potential_repo} as it is excluded from this script.")
continue
print(f"Entering repository {potential_repo}...")
potential_testsuites_one = list(potential_repo.rglob("evaluation/*.yaml"))
potential_testsuites_two = list(potential_repo.rglob("evaluation/*.yml"))
potential_testsuites_one.extend(potential_testsuites_two)
potential_testsuites = sorted(potential_testsuites_one)
print(f" Found {len(potential_testsuites)} suites")
changed = []
for potential_suite in potential_testsuites:
print(f" [{i}] Migrating {potential_suite}...")
with open(potential_suite, "r") as sources:
lines = sources.readlines()
new_lines = []
for line in lines:
nl = re.sub("return: *([\"'])+", "return: !expression \1", line)
nl = re.sub("return: *$", "return: !oracle", nl)
nl = re.sub("return: {", "return: !oracle", nl)
nl = nl.replace("return: !value", "return:")
nl = nl.replace("return: !v", "return:")
if nl != line:
print(f" Converted {line!r}")
print(f" To: {nl!r}")
new_lines.append(nl)
if new_lines != lines:
inp = input("Press enter to continue... ")
if inp != "":
print(
f"Aborted. Restore repo before running again and set start index to {i-1}"
)
exit()
changed.append(potential_suite)
with open(potential_suite, "w") as destination:
destination.write("\n".join(new_lines))
if changed:
print(f" {len(changed)} files were changed...")
choice = input(
"Ready to commit and push? Leave empty to confirm, type something otherwise"
)
if choice == "":
subprocess.run(["git", "pull"], check=True, cwd=potential_repo)
s = " ".join(
[shlex.quote(str(x.relative_to(potential_repo))) for x in changed]
)
command = f"git add {s}"
print(command)
subprocess.run(command, shell=True, check=True, cwd=potential_repo)
subprocess.run(
[
"git",
"commit",
"-m",
"Migrate to new syntax for returns",
"-m",
"See https://github.com/dodona-edu/universal-judge/pull/457 for more information",
"--no-verify",
],
cwd=potential_repo,
check=True,
)
subprocess.run(["git", "push"], check=True, cwd=potential_repo)
else:
print(
"Aborting commit. Next time, update the starting index to prevent duplicate processing"
)
exit() |
niknetniko
added a commit
to dodona-edu/exercise-template-repository
that referenced
this pull request
Nov 19, 2023
niknetniko
added a commit
to dodona-edu/dodona-edu.github.io
that referenced
this pull request
Nov 19, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
YAML strings and objects are now interpreted as literal YAML values by default.
We introduce
!expression
and!oracle
to "cast" strings and objects to expressions and oracles respectively. The list of arguments in an oracle uses the same logic: YAML types by default, expressions when tagged as such.Using the same logic for arguments is not that obvious: we could also force the use of the expression syntax, as we do with actual expressions and statements. However, it felt more natural to be consistent with the return value (which is in the same YAML object) than with the expressions and statements.
This is basically a reversal of the previous behaviour, where strings and objects needed a
!v
tag. This tag has now been removed.Fixes #447. Related: #427.
Not to be merged until the migrations in the repositories are ready (or there is time at least).
After merging and migration, we need to update the docs and the template repository.