Skip to content
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

Support both Python 3.12 and 3.13 in eval #3179

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions bot/exts/utils/snekbox/_cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def print_last_line():
REDO_EMOJI = "\U0001f501" # :repeat:
REDO_TIMEOUT = 30

SupportedPythonVersions = Literal["3.12"]
SupportedPythonVersions = Literal["3.12", "3.13"]


class FilteredFiles(NamedTuple):
Expand Down Expand Up @@ -181,18 +181,16 @@ def build_python_version_switcher_view(
) -> interactions.ViewWithUserAndRoleCheck:
"""Return a view that allows the user to change what version of Python their code is run on."""
alt_python_version: SupportedPythonVersions
if current_python_version == "3.10":
alt_python_version = "3.11"
if current_python_version == "3.12":
alt_python_version = "3.13"
else:
alt_python_version = "3.10" # noqa: F841
alt_python_version = "3.12"

view = interactions.ViewWithUserAndRoleCheck(
allowed_users=(ctx.author.id,),
allowed_roles=MODERATION_ROLES,
)
# Temp disabled until snekbox multi-version support is complete
# https://github.com/python-discord/snekbox/issues/158
# view.add_item(PythonVersionSwitcherButton(alt_python_version, self, ctx, job))
view.add_item(PythonVersionSwitcherButton(alt_python_version, self, ctx, job))
view.add_item(interactions.DeleteMessageButton())

return view
Expand Down
8 changes: 8 additions & 0 deletions bot/exts/utils/snekbox/_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,16 @@ def to_dict(self) -> dict[str, list[str | dict[str, str]]]:
return {
"args": self.args,
"files": [file.to_dict() for file in self.files],
"binary_path": self.binary_path(),
}

def binary_path(self) -> str:
if self.version == "3.12":
return "/snekbin/python/3.12/bin/python"
if self.version == "3.13":
return "/snekbin/python/3.13/bin/python"
return "/snekbin/python/default/bin/python"


@dataclass(frozen=True)
class EvalResult:
Expand Down
5 changes: 3 additions & 2 deletions tests/bot/exts/utils/snekbox/test_snekbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ async def test_post_job(self):
"files": [
{
"path": "main.py",
"content": b64encode(b"import random").decode()
"content": b64encode(b"import random").decode(),
}
]
],
"binary_path": "/snekbin/python/default/bin/python",
}
self.bot.http_session.post.assert_called_with(
constants.URLs.snekbox_eval_api,
Expand Down