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

Merged
merged 1 commit into from
Oct 7, 2024
Merged
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
1 change: 1 addition & 0 deletions bot/exts/utils/snekbox/_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def to_dict(self) -> dict[str, list[str | dict[str, str]]]:
return {
"args": self.args,
"files": [file.to_dict() for file in self.files],
"executable_path": f"/snekbin/python/{self.version}/bin/python",
}


Expand Down
9 changes: 5 additions & 4 deletions tests/bot/exts/utils/snekbox/test_snekbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,19 @@ async def test_post_job(self):
context_manager = MagicMock()
context_manager.__aenter__.return_value = resp
self.bot.http_session.post.return_value = context_manager

job = EvalJob.from_code("import random").as_version("3.10")
py_version = "3.12"
job = EvalJob.from_code("import random").as_version(py_version)
self.assertEqual(await self.cog.post_job(job), EvalResult("Hi", 137))

expected = {
"args": ["main.py"],
"files": [
{
"path": "main.py",
"content": b64encode(b"import random").decode()
"content": b64encode(b"import random").decode(),
}
]
],
"executable_path": f"/snekbin/python/{py_version}/bin/python",
}
self.bot.http_session.post.assert_called_with(
constants.URLs.snekbox_eval_api,
Expand Down