Skip to content

Commit

Permalink
fix: marimoPath usage, more integration tests (#72)
Browse files Browse the repository at this point in the history
* fix: marimoPath usage, more integration tests

* test

* install

* fix commend regex
  • Loading branch information
mscolnick authored Jan 27, 2025
1 parent dbdc50c commit 1b4eb50
Show file tree
Hide file tree
Showing 21 changed files with 508 additions and 110 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: CI

env:
MARIMO_SKIP_UPDATE_CHECK: true

on:
push:
branches: [main]
Expand Down Expand Up @@ -58,3 +61,41 @@ jobs:

- name: ʦ Typecheck
run: pnpm typecheck

test:
runs-on: ubuntu-latest
steps:
- name: 🛑 Cancel Previous Runs
uses: styfle/[email protected]

- name: ⬇️ Checkout repo
uses: actions/checkout@v4

- name: ⎔ Setup pnpm
uses: pnpm/action-setup@v2
with:
version: 8

- name: 🐍 Setup uv
uses: astral-sh/setup-uv@v5

- name: 🐍 Setup Python
uses: actions/setup-python@v5
with:
python-version: 3.12

- name: ⎔ Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: pnpm

- name: 📥 Install dependencies
run: |
uv pip install marimo --system
pnpm install
- name: 🧪 Run tests
run: pnpm test


50 changes: 34 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,46 +46,64 @@ This feature is experimental and may have some limitations. Some known limitatio

To ensure marimo works correctly with your Python environment, you have several options:

> [!TIP]
> The extension will use the Python interpreter from the Python extension by default. Make sure you have the [Python extension](https://marketplace.visualstudio.com/items?itemName=ms-python.python) installed and configured.
1. **Workspace Settings (Recommended)**
Create or edit `.vscode/settings.json` in your workspace:
Create or edit `.vscode/settings.json` in your workspace. You can set the default Python interpreter for your entire workspace, or just for marimo.

For setting the workspace Python interpreter, you can set:

```json
{
"python.defaultInterpreterPath": "${workspaceFolder}/.venv/bin/python"
}
```

For setting the Python interpreter only for marimo, you can set:

```json
{
"python.defaultInterpreterPath": "${workspaceFolder}/.venv/bin/python",
"marimo.marimoPath": "${workspaceFolder}/.venv/bin/marimo"
"marimo.pythonPath": "${workspaceFolder}/.venv/bin/python"
}
```

If you set `marimo.pythonPath`, the extension will use that interpreter with `-m marimo` to invoke marimo.

2. **Global Settings**
You can also configure these settings globally in VS Code's settings:

- Set `python.defaultInterpreterPath` to your preferred Python interpreter
- (Likely not needed) Set `marimo.marimoPath` to the path of your marimo installation
- Verify that marimo is available in your Python interpreter: `value/of/defaultInterpreterPath -m marimo`
- Verify that marimo is available in your Python interpreter: `/value/of/defaultInterpreterPath -m marimo`
- (Likely not needed) Set `marimo.marimoPath` to the path of your marimo installation. When set, the extension will use this path directly `/path/to/marimo` instead of `python -m marimo`.

3. **Virtual Environments**
If using a virtual environment:
- Create and activate your virtual environment
- Install marimo: `pip install marimo`
- VS Code should automatically detect the Python interpreter

4. **uv and package environment sandboxes**
You can use `uvx` with `marimo edit --sandbox` to run marimo in a sandbox.
4. **uv projects and package environment sandboxes**
If you are using `uv` to manage your Python project (e.g. with a `pyproject.toml` file). You can run `uv add marimo` to install marimo in your project's environment. Then update your settings to use:

```json
{
"marimo.pythonPath": "uv run python",
"marimo.marimoPath": "marimo",
"marimo.sandbox": true
"marimo.marimoPath": "uv run marimo",
"marimo.sandbox": true // optional
}
```

> [!TIP]
> The extension will use the Python interpreter from the Python extension by default. Make sure you have the [Python extension](https://marketplace.visualstudio.com/items?itemName=ms-python.python) installed and configured.
5. **uvx and package environment sandboxes**
If you are not creating Python projects and don't want to create virtual environments, you can use `uvx` with `marimo edit --sandbox` to run marimo in a sandbox.

## Extension Settings
```json
{
"marimo.marimoPath": "uvx marimo",
"marimo.sandbox": true
}
```

You can configure the extension using the following settings:
## Configuration

- `marimo.browserType`: Browser to open marimo app (`system` or `embedded`, default: `embedded`)
- `marimo.port`: Default port for marimo server (default: `2818`)
Expand All @@ -97,8 +115,8 @@ You can configure the extension using the following settings:
- `marimo.tokenPassword`: Token password (default: _empty_)
- `marimo.showTerminal`: Open the terminal when the server starts (default: `false`)
- `marimo.debug`: Enable debug logging (default: `false`)
- `marimo.pythonPath`: Path to python interpreter (default: the one from python extension)
- `marimo.marimoPath`: Path to marimo executable (default: `marimo`)
- `marimo.pythonPath`: Path to python interpreter (default: the one from python extension). Will be used with `/path/to/python -m marimo` to invoke marimo.
- `marimo.marimoPath`: Path to a marimo executable (default: None). This will override use of the `pythonPath` setting, and instead invoke commands like `/path/to/marimo edit` instead of `python -m marimo edit`.

## Troubleshooting

Expand Down
22 changes: 17 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,27 @@
"vscode": "^1.95.0"
},
"private": true,
"categories": ["Notebooks", "Machine Learning", "Data Science"],
"categories": [
"Notebooks",
"Machine Learning",
"Data Science"
],
"icon": "resources/marimo.png",
"activationEvents": ["onLanguage"],
"activationEvents": [
"onLanguage"
],
"repository": {
"type": "git",
"url": "https://github.com/marimo-team/vscode-marimo"
},
"bugs": {
"url": "https://github.com/marimo-team/vscode-marimo/issues"
},
"files": ["dist", "resources", "LICENSE"],
"files": [
"dist",
"resources",
"LICENSE"
],
"main": "./dist/extension.js",
"contributes": {
"commands": [
Expand Down Expand Up @@ -317,7 +327,10 @@
"properties": {
"marimo.browserType": {
"type": "string",
"enum": ["embedded", "system"],
"enum": [
"embedded",
"system"
],
"default": "embedded",
"description": "The type of browser to use for opening marimo apps."
},
Expand Down Expand Up @@ -385,7 +398,6 @@
"lint": "biome check --apply .",
"pack": "vsce package --no-dependencies",
"codegen": "npx openapi-typescript https://raw.githubusercontent.com/marimo-team/marimo/0.8.22/openapi/api.yaml --immutable -o ./src/generated/api.ts",
"pretest": "pnpm run build && pnpm run lint",
"publish": "vsce publish --no-dependencies",
"publish:pre-release": "vsce publish --no-dependencies --pre-release",
"openvsx:publish": "npx ovsx publish --pat",
Expand Down
64 changes: 64 additions & 0 deletions src/__integration__/exec.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
import { createVSCodeMock } from "../__mocks__/vscode";

vi.mock("vscode", () => createVSCodeMock(vi));
vi.mock("@vscode/python-extension", () => ({}));

import { workspace } from "vscode";
import { execMarimoCommand, execPythonModule } from "../utils/exec";

beforeEach(() => {
workspace.getConfiguration().reset();
});

describe("execMarimoCommand integration tests", () => {
it("should work out of the box", async () => {
const output = await execMarimoCommand(["--version"]);
expect(output.toString()).toMatch(/\d+\.\d+\.\d+/);
});

it.each(["python", "uv run python"])(
"should run marimo --version with %s",
async (interpreter) => {
workspace.getConfiguration().set("marimo.pythonPath", interpreter);
const output = await execMarimoCommand(["--version"]);
expect(output.toString()).toMatch(/\d+\.\d+\.\d+/);
},
);

it.each(["uv run marimo", "uvx marimo", "uv tool run marimo"])(
"should run marimo --version with %s",
async (interpreter) => {
workspace.getConfiguration().set("marimo.marimoPath", interpreter);
const output = await execMarimoCommand(["--version"]);
expect(output.toString()).toMatch(/\d+\.\d+\.\d+/);
},
);

it("path path gets overridden by marimoPath", async () => {
workspace.getConfiguration().set("marimo.pythonPath", "doesnotexist");
expect(() => execMarimoCommand(["--version"])).rejects.toThrow(
/doesnotexist/,
);

workspace.getConfiguration().set("marimo.marimoPath", "uv run marimo");
const output = await execMarimoCommand(["--version"]);
expect(output.toString()).toMatch(/\d+\.\d+\.\d+/);
});
});

describe("execPythonModule integration tests", () => {
it("should work out of the box", async () => {
const output = await execPythonModule(["marimo", "--version"]);
expect(output.toString()).toMatch(/\d+\.\d+\.\d+/);
});

it.each(["python", "uv run python"])(
"should run python -m marimo --version with %s",
async (interpreter) => {
workspace.getConfiguration().set("marimo.pythonPath", interpreter);
const output = await execPythonModule(["marimo", "--version"]);
expect(output.toString()).toMatch(/\d+\.\d+\.\d+/);
},
);
});
Loading

0 comments on commit 1b4eb50

Please sign in to comment.