Skip to content

Commit

Permalink
Support both Python 3.12 and 3.13 in eval
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisLovering committed Oct 6, 2024
1 parent bfacf0d commit 60e29b1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
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

0 comments on commit 60e29b1

Please sign in to comment.