Skip to content
Draft
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
26 changes: 26 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module.exports = {
env: {
node: true,
browser: true,
es6: true,
},
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
},
ignorePatterns: ['dist/', 'node_modules/', '*.gen.ts'],
plugins: ['@typescript-eslint', 'unused-imports', '@stylistic/ts'],
rules: {
'@typescript-eslint/member-ordering': 'error',
'@typescript-eslint/ban-ts-comment': 'off', // "move fast" mode
'@typescript-eslint/no-explicit-any': 'off', // "move fast" mode
'linebreak-style': ['error', 'unix'],
'unused-imports/no-unused-imports': 'error',
// No double quotes
quotes: ['error', 'single', { avoidEscape: true }],
// No extra semicolon
'@stylistic/ts/semi': ['error', 'never'],
},
}
70 changes: 70 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: Lint

on:
pull_request:

jobs:
lint:
name: Lint
runs-on: ubuntu-latest

steps:
- name: Checkout Repo
uses: actions/checkout@v4

- uses: pnpm/action-setup@v4
with:
version: 9.15.5

- name: Setup Node.js 20
uses: actions/setup-node@v4
with:
node-version: '20.x'
registry-url: https://registry.npmjs.org
cache: pnpm

- name: Configure pnpm
run: |
pnpm config set auto-install-peers true
pnpm config set exclude-links-from-lockfile true

- name: Install JS dependencies
run: |
pnpm install --frozen-lockfile

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'

- name: Install and configure Poetry
uses: snok/install-poetry@v1
with:
version: 1.5.1
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true

- name: Install Python dependencies
working-directory: python
run: |
poetry install

- name: Run linting
run: |
pnpm run lint

- name: Run formatting
run: |
pnpm run format

- name: Check for uncommitted changes
run: |
if [[ -n $(git status --porcelain) ]]; then
echo "❌ Files are not formatted properly:"
git status --short
git diff
exit 1
else
echo "✅ No changes detected."
fi
1 change: 0 additions & 1 deletion chart_data_extractor/e2b_charts/charts/bars.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ def _extract_info(self, ax: Axes) -> None:
labels = [label.get_text() for label in ax.get_xticklabels()]
values = heights
for label, value in zip(labels, values):

bar = BarData(label=label, value=value, group=group_label)
self.elements.append(bar)

Expand Down
9 changes: 8 additions & 1 deletion chart_data_extractor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
"test": "poetry run pytest -n 4 --verbose -x",
"example": "poetry run python3 example.py",
"postVersion": "poetry version $(pnpm pkg get version --workspaces=false | tr -d \\\")",
"pretest": "poetry install"
"pretest": "poetry install",
"lint": "ruff check .",
"format": "ruff format ."
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^7.11.0",
"@typescript-eslint/parser": "^7.11.0",
"eslint": "^8.57.1"
}
}
3 changes: 3 additions & 0 deletions chart_data_extractor/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry.urls]
"Bug Tracker" = "https://github.com/e2b-dev/code-interpreter/issues"

[tool.ruff.lint]
ignore = ["F401", "F403"]
1 change: 0 additions & 1 deletion chart_data_extractor/tests/charts/test_blank.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import matplotlib.pyplot as plt

from e2b_charts import chart_figure_to_chart
from e2b_charts.charts import BarChart, ChartType


def test_blank_chart():
Expand Down
2 changes: 0 additions & 2 deletions chart_data_extractor/tests/charts/test_categorical_scale.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import numpy as np
import matplotlib.pyplot as plt
import datetime

from e2b_charts import chart_figure_to_chart
from e2b_charts.charts import LineChart
Expand Down
2 changes: 1 addition & 1 deletion chart_data_extractor/tests/charts/test_log_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def test_log_chart():
assert chart.x_label == "X-axis"
assert chart.y_label == "Y-axis (log scale)"

assert chart.x_unit == None
assert chart.x_unit is None
assert chart.y_unit == "log scale"

assert chart.x_scale == "linear"
Expand Down
4 changes: 4 additions & 0 deletions js/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
root: true,
extends: '../.eslintrc.cjs',
}
53 changes: 25 additions & 28 deletions js/example.mts
Original file line number Diff line number Diff line change
@@ -1,38 +1,35 @@
import dotenv from 'dotenv'
import { config } from 'dotenv'

import { Sandbox } from './dist'

dotenv.config()
function log(...args: any[]) {
console.log(...args)
}

const code = `
import matplotlib.pyplot as plt
import numpy as np
config()

x = np.linspace(0, 20, 100)
y = np.sin(x)
const sbx = await Sandbox.create('bwyvo5fk343pbvxst536')
log('ℹ️ sandbox created', sbx.sandboxId)

plt.plot(x, y)
plt.show()
await sbx.runCode('x = 1')
log('Sandbox code executed')

x = np.linspace(0, 10, 100)
plt.plot(x, y)
plt.show()
const sandboxId = await sbx.betaPause()
log('Sandbox paused', sandboxId)

import pandas
pandas.DataFrame({"a": [1, 2, 3]})
`
// Resume the sandbox from the same state
const sameSbx = await Sandbox.connect(sbx.sandboxId)
log('Sandbox resumed', sameSbx.sandboxId)

const sandbox = await Sandbox.create()
console.log(sandbox.sandboxId)
const execution = await sameSbx.runCode('x+=1; x')
// Output result
log(execution.text)
log(execution.error)
if (execution.text !== '2') {
log('Test failed:', 'Failed to resume sandbox')
throw new Error('Failed to resume sandbox')
}
log('Sandbox resumed successfully')

const execution = await sandbox.runCode(code, {
onStdout(msg) {
console.log('stdout', msg)
},
onStderr(msg) {
console.log('stderr', msg)
},
})
console.log(execution.results[0].formats())
console.log(execution.results[0].data)
console.log(execution.results.length)
await sbx.kill()
log('Sandbox deleted')
4 changes: 3 additions & 1 deletion js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
"example": "npx tsx example.mts",
"test:bun": "bun test tests/runtimes/bun --env-file=.env",
"test:deno": "deno test tests/runtimes/deno/ --allow-net --allow-read --allow-env --unstable-sloppy-imports --trace-leaks",
"generate-ref": "./scripts/generate_sdk_ref.sh"
"generate-ref": "./scripts/generate_sdk_ref.sh",
"lint": "eslint src/ tests/",
"format": "prettier --write src/ tests/ example.mts"
},
"devDependencies": {
"@types/node": "^18.18.6",
Expand Down
24 changes: 12 additions & 12 deletions js/src/charts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,19 @@ export enum ChartType {
UNKNOWN = 'unknown',
}


/**
* Ax scale types
*/
export enum ScaleType {
LINEAR = "linear",
DATETIME = "datetime",
CATEGORICAL = "categorical",
LOG = "log",
SYMLOG = "symlog",
LOGIT = "logit",
FUNCTION = "function",
FUNCTIONLOG = "functionlog",
ASINH = "asinh",
LINEAR = 'linear',
DATETIME = 'datetime',
CATEGORICAL = 'categorical',
LOG = 'log',
SYMLOG = 'symlog',
LOGIT = 'logit',
FUNCTION = 'function',
FUNCTIONLOG = 'functionlog',
ASINH = 'asinh',
}

/**
Expand Down Expand Up @@ -127,13 +126,14 @@ export function deserializeChart(data: any): Chart {
return { ...data } as PieChart
case ChartType.BOX_AND_WHISKER:
return { ...data } as BoxAndWhiskerChart
case ChartType.SUPERCHART:
const charts = data.data.map((g: any) => deserializeChart(g))
case ChartType.SUPERCHART: {
const charts: Chart[] = data.data.map((g: any) => deserializeChart(g))
delete data.data
return {
...data,
data: charts,
} as SuperChart
}
default:
return { ...data, type: ChartType.UNKNOWN } as Chart
}
Expand Down
12 changes: 6 additions & 6 deletions js/src/messaging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class OutputMessage {
* Whether the output is an error.
*/
public readonly error: boolean
) { }
) {}

public toString() {
return this.line
Expand All @@ -60,15 +60,14 @@ export class ExecutionError {
* The raw traceback of the error.
**/
public traceback: string
) { }
) {}
}

/**
* Represents a MIME type.
*/
export type MIMEType = string


type E2BData = {
data: Record<string, unknown>
chart: ChartTypes
Expand Down Expand Up @@ -185,7 +184,7 @@ export class Result {
'data',
'chart',
'extra',
"text"
'text',
].includes(key)
) {
this.extra[key] = data[key]
Expand Down Expand Up @@ -293,7 +292,7 @@ export class Execution {
* Execution count of the cell.
*/
public executionCount?: number
) { }
) {}

/**
* Returns the text representation of the main result of the cell.
Expand Down Expand Up @@ -329,7 +328,7 @@ export async function parseOutput(
const msg = JSON.parse(line)

switch (msg.type) {
case 'result':
case 'result': {
const result = new Result(
{ ...msg, type: undefined, is_main_result: undefined },
msg.is_main_result
Expand All @@ -339,6 +338,7 @@ export async function parseOutput(
await onResult(result)
}
break
}
case 'stdout':
execution.logs.stdout.push(msg.text)
if (onStdout) {
Expand Down
12 changes: 6 additions & 6 deletions js/src/sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ export class Sandbox extends BaseSandbox {
protected static override readonly defaultTemplate: string =
'code-interpreter-v1'

protected get jupyterUrl(): string {
return `${this.connectionConfig.debug ? 'http' : 'https'}://${this.getHost(
JUPYTER_PORT
)}`
}

/**
* Run the code as Python.
*
Expand Down Expand Up @@ -314,10 +320,4 @@ export class Sandbox extends BaseSandbox {
throw formatRequestTimeoutError(error)
}
}

protected get jupyterUrl(): string {
return `${this.connectionConfig.debug ? 'http' : 'https'}://${this.getHost(
JUPYTER_PORT
)}`
}
}
Loading
Loading