Skip to content

Commit

Permalink
Temporarily remove suport for evaling under 3.10 (#2618)
Browse files Browse the repository at this point in the history
* Temporarily remove suport for evaling under 3.10

This is until snekbox supports multi-version natively
python-discord/snekbox#158

* Remove special case 3.11 snekbox container

3.11 is the default in snekbox:latest now, so no need to have a special container. This also removes all notion of there being diferent containers for different snekbox versions
  • Loading branch information
ChrisLovering authored May 30, 2023
1 parent ec47f94 commit 0cef9e7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 33 deletions.
3 changes: 1 addition & 2 deletions bot/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,8 +477,7 @@ class _BaseURLs(EnvConfig):
EnvConfig.Config.env_prefix = "urls_"

# Snekbox endpoints
snekbox_eval_api = "http://snekbox-310.default.svc.cluster.local/eval"
snekbox_311_eval_api = "http://snekbox.default.svc.cluster.local/eval"
snekbox_eval_api = "http://snekbox.default.svc.cluster.local/eval"

# Discord API
discord_api = "https://discordapp.com/api/v7/"
Expand Down
25 changes: 11 additions & 14 deletions bot/exts/utils/snekbox/_cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def print_last_line():
REDO_EMOJI = "\U0001f501" # :repeat:
REDO_TIMEOUT = 30

PythonVersion = Literal["3.10", "3.11"]
SupportedPythonVersions = Literal["3.11"]

class FilteredFiles(NamedTuple):
allowed: list[FileAttachment]
Expand Down Expand Up @@ -137,7 +137,7 @@ class PythonVersionSwitcherButton(ui.Button):

def __init__(
self,
version_to_switch_to: PythonVersion,
version_to_switch_to: SupportedPythonVersions,
snekbox_cog: Snekbox,
ctx: Context,
job: EvalJob,
Expand Down Expand Up @@ -176,36 +176,33 @@ def __init__(self, bot: Bot):

def build_python_version_switcher_view(
self,
current_python_version: PythonVersion,
current_python_version: SupportedPythonVersions,
ctx: Context,
job: EvalJob,
) -> interactions.ViewWithUserAndRoleCheck:
"""Return a view that allows the user to change what version of Python their code is run on."""
alt_python_version: PythonVersion
alt_python_version: SupportedPythonVersions
if current_python_version == "3.10":
alt_python_version = "3.11"
else:
alt_python_version = "3.10"
alt_python_version = "3.10" # noqa: F841

view = interactions.ViewWithUserAndRoleCheck(
allowed_users=(ctx.author.id,),
allowed_roles=MODERATION_ROLES,
)
view.add_item(PythonVersionSwitcherButton(alt_python_version, self, ctx, job))
# 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(interactions.DeleteMessageButton())

return view

async def post_job(self, job: EvalJob) -> EvalResult:
"""Send a POST request to the Snekbox API to evaluate code and return the results."""
if job.version == "3.10":
url = URLs.snekbox_eval_api
else:
url = URLs.snekbox_311_eval_api

data = job.to_dict()

async with self.bot.http_session.post(url, json=data, raise_for_status=True) as resp:
async with self.bot.http_session.post(URLs.snekbox_eval_api, json=data, raise_for_status=True) as resp:
return EvalResult.from_dict(await resp.json())

@staticmethod
Expand Down Expand Up @@ -544,7 +541,7 @@ async def run_job(
async def eval_command(
self,
ctx: Context,
python_version: PythonVersion | None,
python_version: SupportedPythonVersions | None,
*,
code: CodeblockConverter
) -> None:
Expand Down Expand Up @@ -583,7 +580,7 @@ async def eval_command(
async def timeit_command(
self,
ctx: Context,
python_version: PythonVersion | None,
python_version: SupportedPythonVersions | None,
*,
code: CodeblockConverter
) -> None:
Expand Down
6 changes: 3 additions & 3 deletions bot/exts/utils/snekbox/_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from bot.log import get_logger

if TYPE_CHECKING:
from bot.exts.utils.snekbox._cog import PythonVersion
from bot.exts.utils.snekbox._cog import SupportedPythonVersions

log = get_logger(__name__)

Expand All @@ -26,7 +26,7 @@ class EvalJob:
args: list[str]
files: list[FileAttachment] = field(default_factory=list)
name: str = "eval"
version: PythonVersion = "3.11"
version: SupportedPythonVersions = "3.11"

@classmethod
def from_code(cls, code: str, path: str = "main.py") -> EvalJob:
Expand All @@ -36,7 +36,7 @@ def from_code(cls, code: str, path: str = "main.py") -> EvalJob:
files=[FileAttachment(path, code.encode())],
)

def as_version(self, version: PythonVersion) -> EvalJob:
def as_version(self, version: SupportedPythonVersions) -> EvalJob:
"""Return a copy of the job with a different Python version."""
return EvalJob(
args=self.args,
Expand Down
15 changes: 1 addition & 14 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,6 @@ services:
ports:
- "127.0.0.1:8060:8060"
privileged: true
profiles:
- "3.10"

snekbox-311:
logging : *default-logging
restart: unless-stopped
image: ghcr.io/python-discord/snekbox:3.11-dev
init: true
ipc: none
ports:
- "127.0.0.1:8065:8060"
privileged: true

web:
logging : *default-logging
Expand Down Expand Up @@ -101,13 +89,12 @@ services:
depends_on:
- web
- redis
- snekbox-311
- snekbox
env_file:
- .env
environment:
API_KEYS_SITE_API: "badbot13m0n8f570f942013fc818f234916ca531"
URLS_SITE_API: "http://web:8000/api"
URLS_SNEKBOX_EVAL_API: "http://snekbox:8060/eval"
URLS_SNEKBOX_311_EVAL_API: "http://snekbox-311:8060/eval"
REDIS_HOST: "redis"
STATS_STATSD_HOST: "http://localhost"

0 comments on commit 0cef9e7

Please sign in to comment.