Skip to content

Commit dee4ce7

Browse files
committed
🪓 fix localbox
1 parent 1c505f8 commit dee4ce7

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

codeboxapi/box/codebox.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,15 @@ class CodeBox(BaseBox):
5151
"""
5252

5353
def __new__(cls, *args, **kwargs):
54-
if settings.CODEBOX_API_KEY is None:
54+
if (
55+
settings.CODEBOX_API_KEY is None
56+
or settings.CODEBOX_API_KEY == "local"
57+
or kwargs.pop("local", False)
58+
):
5559
from .localbox import LocalBox
5660

5761
return LocalBox(*args, **kwargs)
62+
5863
return super().__new__(cls, *args, **kwargs)
5964

6065
def __init__(self, *args, **kwargs) -> None:

codeboxapi/box/localbox.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
import json
1010
import os
1111
import subprocess
12+
import sys
1213
import time
1314
from asyncio.subprocess import Process
15+
from pathlib import Path
1416
from typing import List, Optional, Union
1517
from uuid import uuid4
1618

@@ -67,8 +69,11 @@ def start(self) -> CodeBoxStatus:
6769
else:
6870
out = subprocess.PIPE
6971
try:
72+
python = Path(sys.executable).absolute()
7073
self.jupyter = subprocess.Popen(
7174
[
75+
python,
76+
"-m",
7277
"jupyter",
7378
"kernelgateway",
7479
"--KernelGatewayApp.ip='0.0.0.0'",
@@ -127,7 +132,10 @@ async def astart(self) -> CodeBoxStatus:
127132
out = None
128133
else:
129134
out = asyncio.subprocess.PIPE
135+
python = Path(sys.executable).absolute()
130136
self.jupyter = await asyncio.create_subprocess_exec(
137+
python,
138+
"-m",
131139
"jupyter",
132140
"kernelgateway",
133141
"--KernelGatewayApp.ip='0.0.0.0'",
@@ -307,11 +315,6 @@ def run(
307315
print("Error:\n", error)
308316
return CodeBoxOutput(type="error", content=error)
309317

310-
return CodeBoxOutput(
311-
type="error",
312-
content="Unknown message",
313-
)
314-
315318
async def arun(
316319
self,
317320
code: str,

0 commit comments

Comments
 (0)