Skip to content

Commit

Permalink
Support Dodona debug information
Browse files Browse the repository at this point in the history
This outputs metadata for the Python Tutor in Dodona for Python.
  • Loading branch information
niknetniko committed Oct 19, 2023
1 parent bbfbda8 commit af6947f
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 4 deletions.
9 changes: 9 additions & 0 deletions tested/dodona.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ class ExtendedMessage:
permission: Permission | None = None


@define
class Metadata:
"""Currently only used for the Python tutor"""

statements: str | None
stdin: str | None


Message = ExtendedMessage | str

BadgeCount = int
Expand Down Expand Up @@ -177,6 +185,7 @@ class CloseContext:
"""

accepted: bool | None = None
data: Metadata | None = None
command: Literal["close-context"] = "close-context"


Expand Down
47 changes: 45 additions & 2 deletions tested/judge/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
CloseContext,
CloseJudgement,
CloseTab,
Metadata,
StartContext,
StartJudgement,
StartTab,
Expand Down Expand Up @@ -38,7 +39,13 @@
)
from tested.judge.utils import copy_from_paths_to_path
from tested.languages.conventionalize import submission_file
from tested.languages.generation import generate_execution, generate_selector
from tested.languages.generation import (
generate_execution,
generate_selector,
generate_statement,
)
from tested.serialisation import Statement
from tested.testsuite import LanguageLiterals, MainInput, TextData

_logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -324,7 +331,43 @@ def _process_results(
compilation_results=compilation_results,
)

collector.add(CloseContext(), planned.context_index)
# TODO: this is currently very Python-specific
# See if we need a callback to the language modules in the future.
# TODO: we could probably re-use the "readable_input" function here,
# since it only differs a bit.
meta_statements = []
meta_stdin = None
for case in planned.context.testcases:
if case.is_main_testcase():
assert isinstance(case.input, MainInput)
if isinstance(case.input.stdin, TextData):
meta_stdin = case.input.stdin.get_data_as_string(
bundle.config.resources
)
elif isinstance(case.input, Statement):
stmt = generate_statement(bundle, case.input)
meta_statements.append(stmt)
elif isinstance(case.input, LanguageLiterals):
stmt = case.input.get_for(bundle.config.programming_language)
meta_statements.append(stmt)
else:
raise AssertionError(f"Found unknown case input type: {case.input}")

if meta_statements:
meta_statements = "\n".join(meta_statements)
else:
# Don't add empty statements
meta_statements = None

collector.add(
CloseContext(
data=Metadata(
statements=meta_statements,
stdin=meta_stdin,
)
),
planned.context_index,
)
if continue_ in (Status.TIME_LIMIT_EXCEEDED, Status.MEMORY_LIMIT_EXCEEDED):
return continue_, currently_open_tab

Expand Down
10 changes: 8 additions & 2 deletions tested/languages/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,19 @@ def initial_dependencies(self) -> list[str]:
@abstractmethod
def needs_selector(self) -> bool:
"""
Return if the language needs a selector for batch compilation or not. This
is a mandatory option in the config.json file.
Return if the language needs a selector for batch compilation or not.
:return: True if a selector is needed, false otherwise.
"""
raise NotImplementedError

def supports_debug_information(self) -> bool:
"""
If the language supports Dodona debug information for the Python tutor.
:return: True if yes, false otherwise.
"""
return False

def supported_constructs(self) -> set[Construct]:
"""
Callback to get the supported constructs for a language. By default, no
Expand Down
3 changes: 3 additions & 0 deletions tested/languages/python/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ def initial_dependencies(self) -> list[str]:
def needs_selector(self):
return False

def supports_debug_information(self) -> bool:
return True

def file_extension(self) -> str:
return "py"

Expand Down

0 comments on commit af6947f

Please sign in to comment.