Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

improvement: add Upgrade action to package manager UI (#5106)

Myles Scolnick18cbcc1d1a0f
diff --git a/examples/third_party/great_tables/great_tables_example.py b/examples/third_party/great_tables/great_tables_example.py
index 768fa830f2..f44735d49b 100644
--- a/examples/third_party/great_tables/great_tables_example.py
+++ b/examples/third_party/great_tables/great_tables_example.py
@@ -1,32 +1,32 @@
# /// script
# requires-python = ">=3.9"
# dependencies = [
-# "great-tables==0.11.1",
+# "great-tables==0.17.0",
# "marimo",
-# "polars==1.8.2",
+# "polars==1.30.0",
# ]
# ///
import marimo
-__generated_with = "0.8.19"
+__generated_with = "0.13.13"
app = marimo.App(width="medium")
@app.cell(hide_code=True)
-def __(mo):
+def _(mo):
mo.md(
r"""
- # [Great-tables](https://github.com/posit-dev/great-tables) + marimo
+ # [Great-tables](https://github.com/posit-dev/great-tables) + marimo
- Adapted from https://github.com/machow/coffee-sales-data
- """
+ Adapted from https://github.com/machow/coffee-sales-data
+ """
)
return
@app.cell
-def __(__file__):
+def _():
import polars as pl
import polars.selectors as cs
import os
@@ -38,17 +38,17 @@ def __(__file__):
coffee_sales = pl.DataFrame.deserialize(
Path(current_dir) / "coffee-sales.json", format="json"
)
- return GT, Path, coffee_sales, cs, current_dir, loc, mo, os, pl, style
+ return GT, coffee_sales, cs, loc, mo, pl, style
@app.cell
-def __(coffee_sales, mo):
+def _(coffee_sales, mo):
revenue = mo.ui.range_slider.from_series(coffee_sales["revenue_dollars"])
return (revenue,)
@app.cell(hide_code=True)
-def __(mo, revenue):
+def _(mo, revenue):
mo.hstack(
[revenue, f"${revenue.value[0]:,.0f} - ${revenue.value[1]:,.0f}"]
).left()
@@ -56,18 +56,18 @@ def __(mo, revenue):
@app.cell(hide_code=True)
-def __(coffee_sales, revenue):
+def _(coffee_sales, revenue):
lower = revenue.value[0]
upper = revenue.value[1]
filterered_coffee_sales = coffee_sales.filter(
(coffee_sales["revenue_dollars"] >= lower)
& (coffee_sales["revenue_dollars"] <= upper)
)
- return filterered_coffee_sales, lower, upper
+ return (filterered_coffee_sales,)
@app.cell(hide_code=True)
-def __(GT, cs, filterered_coffee_sales, loc, pl, style):
+def _(GT, cs, filterered_coffee_sales, loc, pl, style):
sel_rev = cs.starts_with("revenue")
sel_prof = cs.starts_with("profit")
@@ -111,7 +111,7 @@ def __(GT, cs, filterered_coffee_sales, loc, pl, style):
)
coffee_table
- return coffee_table, sel_prof, sel_rev
+ return
if __name__ == "__main__":
diff --git a/frontend/src/components/editor/chrome/panels/packages-panel.tsx b/frontend/src/components/editor/chrome/panels/packages-panel.tsx
index 16fabca7b8..75ebd16863 100644
--- a/frontend/src/components/editor/chrome/panels/packages-panel.tsx
+++ b/frontend/src/components/editor/chrome/panels/packages-panel.tsx
@@ -31,6 +31,110 @@ import { PACKAGES_INPUT_ID } from "./constants";
import { useOpenSettingsToTab } from "@/components/app-config/state";
import { packagesToInstallAtom } from "./packages-state";
import { useAtomValue, useSetAtom } from "jotai";
+import { isWasm } from "@/core/wasm/utils";
+
+const showAddPackageToast = (packageName: string, error?: string | null) => {
+ if (error) {
+ toast({
+ title: "Failed to add package",
+ description: error,
+ variant: "danger",
+ });
+ } else {
+ toast({
+ title: "Package added",
+ description: (
+ <div>
+ <div>
+ The package <Kbd className="inline">{packageName}</Kbd> and its
+ dependencies has been added to your environment.
+ </div>
+ <div className="text-xs text-muted-foreground mt-1">
+ Some Python packages may require a kernel restart to see changes.
+ </div>
+ </div>
+ ),
+ });
+ }
+};
+
+const showUpgradePackageToast = (
+ packageName: string,
+ error?: string | null,
+) => {
+ if (error) {
+ toast({
+ title: "Failed to upgrade package",
+ description: error,
+ variant: "danger",
+ });
+ } else {
+ toast({
+ title: "Package upgraded",
+ description: (
+ <div>
+ <div>
+ The package <Kbd className="inline">{packageName}</Kbd> has been
+ upgraded.
+ </div>
+ <div className="text-xs text-muted-foreground mt-1">
+ Some Python packages may require a kernel restart to see changes.
+ </div>
+ </div>
+ ),
+ });
+ }
+};
+
+const showRemovePackageToast = (packageName: string, error?: string | null) => {
+ if (error) {
+ toast({
+ title: "Failed to remove package",
+ description: error,
+ variant: "danger",
+ });
+ } else {
+ toast({
+ title: "Package removed",
+ description: (
+ <div>
+ <div>
+ The package <Kbd className="inline">{packageName}</Kbd> has been
+ removed from your environment.
+ </div>
+ <div className="text-xs text-muted-foreground mt-1">
+ Some Python packages may require a kernel restart to see changes.
+ </div>
+ </div>
+ ),
+ });
+ }
+};
+
+const PackageActionButton: React.FC<{
+ onClick: () => void;
+ loading: boolean;
+ children: React.ReactNode;
+ className?: string;
+}> = ({ onClick, loading, children, className }) => {
+ if (loading) {
+ return <Spinner size="small" className="h-4 w-4 shrink-0 opacity-50" />;
+ }
+
+ return (
+ <button
+ type="button"
+ className={cn(
+ "px-2 h-full text-xs text-muted-foreground hover:text-foreground",
+ "invisible group-hover:visible",
+ className,
+ )}
+ onClick={Events.stopPropagation(onClick)}
+ >
+ {children}
+ </button>
+ );
+};
export const PackagesPanel: React.FC = () => {
const [config] = useResolvedMarimoConfig();
@@ -86,21 +190,9 @@ const InstallPackageForm: React.FC<{
const response = await addPackage({ package: input });
if (response.success) {
onSuccess();
- toast({
- title: "Package added",
- description: (
- <span>
- The package <Kbd className="inline">{input}</Kbd> and its
- dependencies has been added to your environment.
- </span>
- ),
- });
+ showAddPackageToast(input);
} else {
- toast({
- title: "Failed to add package",
- description: response.error,
- variant: "danger",
- });
+ showAddPackageToast(input, response.error);
}
} finally {
setInput("");
@@ -246,7 +338,8 @@ const PackagesList: React.FC<{
>
<TableCell>{item.name}</TableCell>
<TableCell>{item.version}</TableCell>
- <TableCell>
+ <TableCell className="flex justify-end">
+ <UpgradeButton packageName={item.name} onSuccess={onSuccess} />
<RemoveButton packageName={item.name} onSuccess={onSuccess} />
</TableCell>
</TableRow>
@@ -256,6 +349,42 @@ const PackagesList: React.FC<{
);
};
+const UpgradeButton: React.FC<{
+ packageName: string;
+ onSuccess: () => void;
+}> = ({ packageName, onSuccess }) => {
+ const [loading, setLoading] = React.useState(false);
+
+ // Hide upgrade button in WASM
+ if (isWasm()) {
+ return null;
+ }
+
+ const handleUpgradePackage = async () => {
+ try {
+ setLoading(true);
+ const response = await addPackage({
+ package: packageName,
+ upgrade: true,
+ });
+ if (response.success) {
+ onSuccess();
+ showUpgradePackageToast(packageName);
+ } else {
+ showUpgradePackageToast(packageName, response.error);
+ }
+ } finally {
+ setLoading(false);
+ }
+ };
+
+ return (
+ <PackageActionButton onClick={handleUpgradePackage} loading={loading}>
+ Upgrade
+ </PackageActionButton>
+ );
+};
+
const RemoveButton: React.FC<{
packageName: string;
onSuccess: () => void;
@@ -268,46 +397,18 @@ const RemoveButton: React.FC<{
const response = await removePackage({ package: packageName });
if (response.success) {
onSuccess();
- toast({
- title: "Package removed",
- description: (
- <span>
- The package <Kbd className="inline">{packageName}</Kbd> has been
- removed from your environment.
- </span>
- ),
- });
+ showRemovePackageToast(packageName);
} else {
- toast({
- title: "Failed to add package",
- description: response.error,
- variant: "danger",
- });
+ showRemovePackageToast(packageName, response.error);
}
} finally {
setLoading(false);
}
};
- if (loading) {
- return (
- <Spinner
- size="small"
- className="float-right mr-2 h-4 w-4 shrink-0 opacity-50"
- />
- );
- }
-
return (
- <button
- type="button"
- className={cn(
- "float-right px-2 h-full text-xs text-muted-foreground hover:text-foreground",
- "invisible group-hover:visible",
- )}
- onClick={Events.stopPropagation(handleRemovePackage)}
- >
+ <PackageActionButton onClick={handleRemovePackage} loading={loading}>
Remove
- </button>
+ </PackageActionButton>
);
};
diff --git a/marimo/_runtime/packages/conda_package_manager.py b/marimo/_runtime/packages/conda_package_manager.py
index 2509933dda..e4bf8c6c9c 100644
--- a/marimo/_runtime/packages/conda_package_manager.py
+++ b/marimo/_runtime/packages/conda_package_manager.py
@@ -22,8 +22,11 @@ class CondaPackageManager(CanonicalizingPackageManager):
class PixiPackageManager(CondaPackageManager):
name = "pixi"
- async def _install(self, package: str) -> bool:
- return self.run(["pixi", "add", *split_packages(package)])
+ async def _install(self, package: str, *, upgrade: bool) -> bool:
+ if upgrade:
+ return self.run(["pixi", "upgrade", *split_packages(package)])
+ else:
+ return self.run(["pixi", "add", *split_packages(package)])
async def uninstall(self, package: str) -> bool:
return self.run(["pixi", "remove", *split_packages(package)])
diff --git a/marimo/_runtime/packages/package_manager.py b/marimo/_runtime/packages/package_manager.py
index 1f2740d26d..1969c56258 100644
--- a/marimo/_runtime/packages/package_manager.py
+++ b/marimo/_runtime/packages/package_manager.py
@@ -50,17 +50,21 @@ class PackageManager(abc.ABC):
return False
@abc.abstractmethod
- async def _install(self, package: str) -> bool:
+ async def _install(self, package: str, *, upgrade: bool) -> bool:
"""Installation logic."""
...
- async def install(self, package: str, version: Optional[str]) -> bool:
+ async def install(
+ self, package: str, version: Optional[str], upgrade: bool = False
+ ) -> bool:
"""Attempt to install a package that makes this module available.
Returns True if installation succeeded, else False.
"""
self._attempted_packages.add(package)
- return await self._install(append_version(package, version))
+ return await self._install(
+ append_version(package, version), upgrade=upgrade
+ )
@abc.abstractmethod
async def uninstall(self, package: str) -> bool:
@@ -92,6 +96,7 @@ class PackageManager(abc.ABC):
packages_to_remove: Optional[list[str]] = None,
import_namespaces_to_add: Optional[list[str]] = None,
import_namespaces_to_remove: Optional[list[str]] = None,
+ upgrade: bool,
) -> None:
del (
filepath,
@@ -99,6 +104,7 @@ class PackageManager(abc.ABC):
packages_to_remove,
import_namespaces_to_add,
import_namespaces_to_remove,
+ upgrade,
)
"""
Add or remove inline script metadata metadata
diff --git a/marimo/_runtime/packages/pypi_package_manager.py b/marimo/_runtime/packages/pypi_package_manager.py
index 98393ce69b..ce9100bacd 100644
--- a/marimo/_runtime/packages/pypi_package_manager.py
+++ b/marimo/_runtime/packages/pypi_package_manager.py
@@ -52,11 +52,13 @@ class PipPackageManager(PypiPackageManager):
name = "pip"
docs_url = "https://pip.pypa.io/"
- async def _install(self, package: str) -> bool:
+ async def _install(self, package: str, *, upgrade: bool) -> bool:
LOGGER.info(f"Installing {package} with pip")
- return self.run(
- ["pip", "--python", PY_EXE, "install", *split_packages(package)]
- )
+ cmd = ["pip", "--python", PY_EXE, "install"]
+ if upgrade:
+ cmd.append("--upgrade")
+ cmd.extend(split_packages(package))
+ return self.run(cmd)
async def uninstall(self, package: str) -> bool:
LOGGER.info(f"Uninstalling {package} with pip")
@@ -86,10 +88,18 @@ class MicropipPackageManager(PypiPackageManager):
def is_manager_installed(self) -> bool:
return is_pyodide()
- async def _install(self, package: str) -> bool:
+ async def _install(self, package: str, *, upgrade: bool) -> bool:
assert is_pyodide()
import micropip # type: ignore
+ # If we're upgrading, we need to uninstall the package first
+ # to avoid conflicts
+ if upgrade:
+ try:
+ await micropip.uninstall(split_packages(package))
+ except ValueError:
+ pass
+
try:
await micropip.install(split_packages(package))
return True
@@ -125,7 +135,7 @@ class UvPackageManager(PypiPackageManager):
name = "uv"
docs_url = "https://docs.astral.sh/uv/"
- async def _install(self, package: str) -> bool:
+ async def _install(self, package: str, *, upgrade: bool) -> bool:
install_cmd: list[str]
if self.is_in_uv_project:
LOGGER.info(f"Installing in {package} with 'uv add'")
@@ -134,6 +144,9 @@ class UvPackageManager(PypiPackageManager):
LOGGER.info(f"Installing in {package} with 'uv pip install'")
install_cmd = ["uv", "pip", "install"]
+ if upgrade:
+ install_cmd.append("--upgrade")
+
return self.run(
# trade installation time for faster start time
install_cmd + ["--compile", *split_packages(package), "-p", PY_EXE]
@@ -147,6 +160,7 @@ class UvPackageManager(PypiPackageManager):
packages_to_remove: Optional[list[str]] = None,
import_namespaces_to_add: Optional[list[str]] = None,
import_namespaces_to_remove: Optional[list[str]] = None,
+ upgrade: bool,
) -> None:
"""Update the notebook's script metadata with the packages to add/remove.
@@ -156,6 +170,7 @@ class UvPackageManager(PypiPackageManager):
packages_to_remove: List of packages to remove from the script metadata
import_namespaces_to_add: List of import namespaces to add
import_namespaces_to_remove: List of import namespaces to remove
+ upgrade: Whether to upgrade the packages
"""
packages_to_add = packages_to_add or []
packages_to_remove = packages_to_remove or []
@@ -200,10 +215,10 @@ class UvPackageManager(PypiPackageManager):
if filepath.endswith(".md") or filepath.endswith(".qmd"):
# md and qmd require writing to a faux python file first.
return self._process_md_changes(
- filepath, packages_to_add, packages_to_remove
+ filepath, packages_to_add, packages_to_remove, upgrade=upgrade
)
return self._process_changes_for_script_metadata(
- filepath, packages_to_add, packages_to_remove
+ filepath, packages_to_add, packages_to_remove, upgrade=upgrade
)
def _process_md_changes(
@@ -211,6 +226,7 @@ class UvPackageManager(PypiPackageManager):
filepath: str,
packages_to_add: list[str],
packages_to_remove: list[str],
+ upgrade: bool,
) -> None:
from marimo._cli.convert.markdown import extract_frontmatter
from marimo._utils import yaml
@@ -241,6 +257,7 @@ class UvPackageManager(PypiPackageManager):
temp_file.name,
packages_to_add,
packages_to_remove,
+ upgrade=upgrade,
)
with open(temp_file.name, encoding="utf-8") as f:
header = f.read()
@@ -271,12 +288,14 @@ class UvPackageManager(PypiPackageManager):
filepath: str,
packages_to_add: list[str],
packages_to_remove: list[str],
+ upgrade: bool,
) -> None:
if packages_to_add:
- self.run(
- ["uv", "--quiet", "add", "--script", filepath]
- + packages_to_add
- )
+ cmd = ["uv", "--quiet", "add", "--script", filepath]
+ if upgrade:
+ cmd.append("--upgrade")
+ cmd.extend(packages_to_add)
+ self.run(cmd)
if packages_to_remove:
self.run(
["uv", "--quiet", "remove", "--script", filepath]
@@ -343,7 +362,11 @@ class RyePackageManager(PypiPackageManager):
name = "rye"
docs_url = "https://rye.astral.sh/"
- async def _install(self, package: str) -> bool:
+ async def _install(self, package: str, *, upgrade: bool) -> bool:
+ if upgrade:
+ return self.run(
+ ["rye", "sync", "--update", *split_packages(package)]
+ )
return self.run(["rye", "add", *split_packages(package)])
async def uninstall(self, package: str) -> bool:
@@ -358,7 +381,17 @@ class PoetryPackageManager(PypiPackageManager):
name = "poetry"
docs_url = "https://python-poetry.org/docs/"
- async def _install(self, package: str) -> bool:
+ async def _install(self, package: str, *, upgrade: bool) -> bool:
+ if upgrade:
+ return self.run(
+ [
+ "poetry",
+ "update",
+ "--no-interaction",
+ *split_packages(package),
+ ]
+ )
+
return self.run(
["poetry", "add", "--no-interaction", *split_packages(package)]
)
diff --git a/marimo/_runtime/runtime.py b/marimo/_runtime/runtime.py
index c81a2c6c70..8489a6cf34 100644
--- a/marimo/_runtime/runtime.py
+++ b/marimo/_runtime/runtime.py
@@ -2572,6 +2572,7 @@ class PackagesCallbacks:
self.package_manager.update_notebook_script_metadata(
filepath=filename,
import_namespaces_to_add=import_namespaces_to_add,
+ upgrade=False,
)
except Exception as e:
LOGGER.error("Failed to add script metadata to notebook: %s", e)
diff --git a/marimo/_server/api/endpoints/packages.py b/marimo/_server/api/endpoints/packages.py
index f67e8ec09c..2696700d94 100644
--- a/marimo/_server/api/endpoints/packages.py
+++ b/marimo/_server/api/endpoints/packages.py
@@ -53,7 +53,10 @@ async def add_package(request: Request) -> PackageOperationResponse:
f"Check out the docs for installation instructions: {package_manager.docs_url}" # noqa: E501
)
- success = await package_manager.install(body.package, version=None)
+ upgrade = body.upgrade or False
+ success = await package_manager.install(
+ body.package, version=None, upgrade=upgrade
+ )
# Update the script metadata
filename = _get_filename(request)
@@ -61,6 +64,7 @@ async def add_package(request: Request) -> PackageOperationResponse:
package_manager.update_notebook_script_metadata(
filepath=filename,
packages_to_add=split_packages(body.package),
+ upgrade=upgrade,
)
if success:
@@ -106,6 +110,7 @@ async def remove_package(request: Request) -> PackageOperationResponse:
package_manager.update_notebook_script_metadata(
filepath=filename,
packages_to_remove=split_packages(body.package),
+ upgrade=False,
)
if success:
diff --git a/marimo/_server/models/packages.py b/marimo/_server/models/packages.py
index b253375cec..e78fe088d7 100644
--- a/marimo/_server/models/packages.py
+++ b/marimo/_server/models/packages.py
@@ -23,6 +23,7 @@ class AddPackageRequest:
"""
package: str
+ upgrade: Optional[bool] = False
@dataclass
diff --git a/openapi/api.yaml b/openapi/api.yaml
index 99b8efe605..d4f2991b85 100644
--- a/openapi/api.yaml
+++ b/openapi/api.yaml
@@ -4,8 +4,11 @@ components:
properties:
package:
type: string
+ upgrade:
+ nullable: true
+ type: boolean
required:
- - package
+ - package
type: object
AiCompletionContext:
properties:
@@ -16,12 +19,12 @@ components:
variables:
items:
oneOf:
- - $ref: '#/components/schemas/VariableContext'
- - type: string
+ - $ref: '#/components/schemas/VariableContext'
+ - type: string
type: array
required:
- - schema
- - variables
+ - schema
+ - variables
type: object
AiCompletionRequest:
properties:
@@ -34,9 +37,9 @@ components:
type: string
language:
enum:
- - python
- - markdown
- - sql
+ - python
+ - markdown
+ - sql
type: string
prompt:
type: string
@@ -44,27 +47,27 @@ components:
nullable: true
type: string
required:
- - prompt
- - includeOtherCode
- - code
- - language
+ - prompt
+ - includeOtherCode
+ - code
+ - language
type: object
AiInlineCompletionRequest:
properties:
language:
enum:
- - python
- - markdown
- - sql
+ - python
+ - markdown
+ - sql
type: string
prefix:
type: string
suffix:
type: string
required:
- - prefix
- - suffix
- - language
+ - prefix
+ - suffix
+ - language
type: object
Alert:
properties:
@@ -72,61 +75,61 @@ components:
type: string
name:
enum:
- - alert
+ - alert
type: string
title:
type: string
variant:
enum:
- - danger
+ - danger
nullable: true
type: string
required:
- - title
- - description
- - name
+ - title
+ - description
+ - name
type: object
Banner:
properties:
action:
enum:
- - restart
+ - restart
nullable: true
type: string
description:
type: string
name:
enum:
- - banner
+ - banner
type: string
title:
type: string
variant:
enum:
- - danger
+ - danger
nullable: true
type: string
required:
- - title
- - description
- - name
+ - title
+ - description
+ - name
type: object
BaseResponse:
properties:
success:
type: boolean
required:
- - success
+ - success
type: object
CellChannel:
enum:
- - stdout
- - stderr
- - stdin
- - pdb
- - output
- - marimo-error
- - media
+ - stdout
+ - stderr
+ - stdin
+ - pdb
+ - output
+ - marimo-error
+ - media
type: string
CellConfig:
properties:
@@ -138,8 +141,8 @@ components:
hide_code:
type: boolean
required:
- - disabled
- - hide_code
+ - disabled
+ - hide_code
type: object
CellOp:
properties:
@@ -148,13 +151,13 @@ components:
console:
nullable: true
oneOf:
- - $ref: '#/components/schemas/CellOutput'
- - items:
- $ref: '#/components/schemas/CellOutput'
- type: array
+ - $ref: '#/components/schemas/CellOutput'
+ - items:
+ $ref: '#/components/schemas/CellOutput'
+ type: array
name:
enum:
- - cell-op
+ - cell-op
type: string
output:
$ref: '#/components/schemas/CellOutput'
@@ -174,9 +177,9 @@ components:
timestamp:
type: number
required:
- - cell_id
- - timestamp
- - name
+ - cell_id
+ - timestamp
+ - name
type: object
CellOutput:
properties:
@@ -184,21 +187,21 @@ components:
$ref: '#/components/schemas/CellChannel'
data:
oneOf:
- - type: string
- - items:
- $ref: '#/components/schemas/Error'
- type: array
- - additionalProperties: {}
- type: object
+ - type: string
+ - items:
+ $ref: '#/components/schemas/Error'
+ type: array
+ - additionalProperties: {}
+ type: object
mimetype:
$ref: '#/components/schemas/MimeType'
timestamp:
type: number
required:
- - channel
- - mimetype
- - data
- - timestamp
+ - channel
+ - mimetype
+ - data
+ - timestamp
type: object
ChatRequest:
properties:
@@ -220,8 +223,8 @@ components:
url:
type: string
required:
- - url
- - name
+ - url
+ - name
type: object
nullable: true
type: array
@@ -230,13 +233,13 @@ components:
type: object
role:
enum:
- - user
- - assistant
- - system
+ - user
+ - assistant
+ - system
type: string
required:
- - role
- - content
+ - role
+ - content
type: object
type: array
model:
@@ -245,14 +248,14 @@ components:
variables:
items:
oneOf:
- - $ref: '#/components/schemas/VariableContext'
- - type: string
+ - $ref: '#/components/schemas/VariableContext'
+ - type: string
nullable: true
type: array
required:
- - context
- - includeOtherCode
- - messages
+ - context
+ - includeOtherCode
+ - messages
type: object
CodeCompletionRequest:
properties:
@@ -263,9 +266,9 @@ components:
id:
type: string
required:
- - id
- - document
- - cellId
+ - id
+ - document
+ - cellId
type: object
ColumnStats:
properties:
@@ -316,10 +319,10 @@ components:
properties:
name:
enum:
- - completed-run
+ - completed-run
type: string
required:
- - name
+ - name
type: object
CompletionResult:
properties:
@@ -327,7 +330,7 @@ components:
type: string
name:
enum:
- - completion-result
+ - completion-result
type: string
options:
items:
@@ -340,17 +343,17 @@ components:
type:
type: string
required:
- - name
- - type
+ - name
+ - type
type: object
type: array
prefix_length:
type: integer
required:
- - completion_id
- - prefix_length
- - options
- - name
+ - completion_id
+ - prefix_length
+ - options
+ - name
type: object
CopyNotebookRequest:
properties:
@@ -359,8 +362,8 @@ components:
source:
type: string
required:
- - source
- - destination
+ - source
+ - destination
type: object
CreateSecretRequest:
properties:
@@ -370,36 +373,36 @@ components:
type: string
provider:
enum:
- - env
- - dotenv
+ - env
+ - dotenv
type: string
value:
type: string
required:
- - key
- - value
- - provider
- - name
+ - key
+ - value
+ - provider
+ - name
type: object
CycleError:
properties:
edges_with_vars:
items:
prefixItems:
- - type: string
- - items:
- type: string
- type: array
- - type: string
+ - type: string
+ - items:
+ type: string
+ type: array
+ - type: string
type: array
type: array
type:
enum:
- - cycle
+ - cycle
type: string
required:
- - edges_with_vars
- - type
+ - edges_with_vars
+ - type
type: object
DataColumnPreview:
properties:
@@ -423,7 +426,7 @@ components:
type: array
name:
enum:
- - data-column-preview
+ - data-column-preview
type: string
stats:
$ref: '#/components/schemas/ColumnStats'
@@ -431,10 +434,10 @@ components:
table_name:
type: string
required:
- - chart_max_rows_errors
- - table_name
- - column_name
- - name
+ - chart_max_rows_errors
+ - table_name
+ - column_name
+ - name
type: object
DataSourceConnection:
properties:
@@ -458,14 +461,14 @@ components:
$ref: '#/components/schemas/DataTable'
type: array
required:
- - name
- - tables
+ - name
+ - tables
type: object
type: array
required:
- - name
- - dialect
- - schemas
+ - name
+ - dialect
+ - schemas
type: object
type: array
default_database:
@@ -483,11 +486,11 @@ components:
source:
type: string
required:
- - source
- - dialect
- - name
- - display_name
- - databases
+ - source
+ - dialect
+ - name
+ - display_name
+ - databases
type: object
DataSourceConnections:
properties:
@@ -497,11 +500,11 @@ components:
type: array
name:
enum:
- - data-source-connections
+ - data-source-connections
type: string
required:
- - connections
- - name
+ - connections
+ - name
type: object
DataTable:
properties:
@@ -534,25 +537,25 @@ components:
type: string
source_type:
enum:
- - local
- - duckdb
- - connection
- - catalog
+ - local
+ - duckdb
+ - connection
+ - catalog
type: string
type:
enum:
- - table
- - view
+ - table
+ - view
type: string
variable_name:
nullable: true
type: string
required:
- - source_type
- - source
- - name
- - columns
- - type
+ - source_type
+ - source
+ - name
+ - columns
+ - type
type: object
DataTableColumn:
properties:
@@ -566,21 +569,21 @@ components:
type:
$ref: '#/components/schemas/DataType'
required:
- - name
- - type
- - external_type
- - sample_values
+ - name
+ - type
+ - external_type
+ - sample_values
type: object
DataType:
enum:
- - string
- - boolean
- - integer
- - number
- - date
- - datetime
- - time
- - unknown
+ - string
+ - boolean
+ - integer
+ - number
+ - date
+ - datetime
+ - time
+ - unknown
type: string
Database:
properties:
@@ -596,38 +599,38 @@ components:
$ref: '#/components/schemas/Schema'
type: array
required:
- - name
- - dialect
- - schemas
+ - name
+ - dialect
+ - schemas
type: object
Datasets:
properties:
clear_channel:
enum:
- - local
- - duckdb
- - connection
- - catalog
+ - local
+ - duckdb
+ - connection
+ - catalog
nullable: true
type: string
name:
enum:
- - datasets
+ - datasets
type: string
tables:
items:
$ref: '#/components/schemas/DataTable'
type: array
required:
- - tables
- - name
+ - tables
+ - name
type: object
DeleteCellRequest:
properties:
cellId:
type: string
required:
- - cellId
+ - cellId
type: object
DeleteNonlocalError:
properties:
@@ -639,35 +642,35 @@ components:
type: string
type:
enum:
- - delete-nonlocal
+ - delete-nonlocal
type: string
required:
- - name
- - cells
- - type
+ - name
+ - cells
+ - type
type: object
DeleteSecretRequest:
properties:
key:
type: string
required:
- - key
+ - key
type: object
Error:
oneOf:
- - $ref: '#/components/schemas/SetupRootError'
- - $ref: '#/components/schemas/CycleError'
- - $ref: '#/components/schemas/MultipleDefinitionError'
- - $ref: '#/components/schemas/ImportStarError'
- - $ref: '#/components/schemas/DeleteNonlocalError'
- - $ref: '#/components/schemas/MarimoAncestorStoppedError'
- - $ref: '#/components/schemas/MarimoAncestorPreventedError'
- - $ref: '#/components/schemas/MarimoExceptionRaisedError'
- - $ref: '#/components/schemas/MarimoStrictExecutionError'
- - $ref: '#/components/schemas/MarimoInterruptionError'
- - $ref: '#/components/schemas/MarimoSyntaxError'
- - $ref: '#/components/schemas/MarimoInternalError'
- - $ref: '#/components/schemas/UnknownError'
+ - $ref: '#/components/schemas/SetupRootError'
+ - $ref: '#/components/schemas/CycleError'
+ - $ref: '#/components/schemas/MultipleDefinitionError'
+ - $ref: '#/components/schemas/ImportStarError'
+ - $ref: '#/components/schemas/DeleteNonlocalError'
+ - $ref: '#/components/schemas/MarimoAncestorStoppedError'
+ - $ref: '#/components/schemas/MarimoAncestorPreventedError'
+ - $ref: '#/components/schemas/MarimoExceptionRaisedError'
+ - $ref: '#/components/schemas/MarimoStrictExecutionError'
+ - $ref: '#/components/schemas/MarimoInterruptionError'
+ - $ref: '#/components/schemas/MarimoSyntaxError'
+ - $ref: '#/components/schemas/MarimoInternalError'
+ - $ref: '#/components/schemas/UnknownError'
ExecuteMultipleRequest:
properties:
cellIds:
@@ -684,9 +687,9 @@ components:
timestamp:
type: number
required:
- - cellIds
- - codes
- - timestamp
+ - cellIds
+ - codes
+ - timestamp
type: object
ExecuteScratchpadRequest:
properties:
@@ -696,7 +699,7 @@ components:
$ref: '#/components/schemas/HTTPRequest'
nullable: true
required:
- - code
+ - code
type: object
ExecuteStaleRequest:
properties:
@@ -716,9 +719,9 @@ components:
timestamp:
type: number
required:
- - cellId
- - code
- - timestamp
+ - cellId
+ - code
+ - timestamp
type: object
ExportAsHTMLRequest:
properties:
@@ -734,30 +737,30 @@ components:
includeCode:
type: boolean
required:
- - download
- - files
- - includeCode
+ - download
+ - files
+ - includeCode
type: object
ExportAsIPYNBRequest:
properties:
download:
type: boolean
required:
- - download
+ - download
type: object
ExportAsMarkdownRequest:
properties:
download:
type: boolean
required:
- - download
+ - download
type: object
ExportAsScriptRequest:
properties:
download:
type: boolean
required:
- - download
+ - download
type: object
FileCreateRequest:
properties:
@@ -770,13 +773,13 @@ components:
type: string
type:
enum:
- - file
- - directory
+ - file
+ - directory
type: string
required:
- - path
- - type
- - name
+ - path
+ - type
+ - name
type: object
FileCreateResponse:
properties:
@@ -789,14 +792,14 @@ components:
success:
type: boolean
required:
- - success
+ - success
type: object
FileDeleteRequest:
properties:
path:
type: string
required:
- - path
+ - path
type: object
FileDeleteResponse:
properties:
@@ -806,14 +809,14 @@ components:
success:
type: boolean
required:
- - success
+ - success
type: object
FileDetailsRequest:
properties:
path:
type: string
required:
- - path
+ - path
type: object
FileDetailsResponse:
properties:
@@ -826,7 +829,7 @@ components:
nullable: true
type: string
required:
- - file
+ - file
type: object
FileInfo:
properties:
@@ -848,12 +851,12 @@ components:
path:
type: string
required:
- - id
- - path
- - name
- - isDirectory
- - isMarimoFile
- - children
+ - id
+ - path
+ - name
+ - isDirectory
+ - isMarimoFile
+ - children
type: object
FileListRequest:
properties:
@@ -870,8 +873,8 @@ components:
root:
type: string
required:
- - files
- - root
+ - files
+ - root
type: object
FileMoveRequest:
properties:
@@ -880,8 +883,8 @@ components:
path:
type: string
required:
- - path
- - newPath
+ - path
+ - newPath
type: object
FileMoveResponse:
properties:
@@ -894,14 +897,14 @@ components:
success:
type: boolean
required:
- - success
+ - success
type: object
FileOpenRequest:
properties:
path:
type: string
required:
- - path
+ - path
type: object
FileUpdateRequest:
properties:
@@ -910,8 +913,8 @@ components:
path:
type: string
required:
- - path
- - contents
+ - path
+ - contents
type: object
FileUpdateResponse:
properties:
@@ -924,7 +927,7 @@ components:
success:
type: boolean
required:
- - success
+ - success
type: object
FocusCell:
properties:
@@ -932,11 +935,11 @@ components:
type: string
name:
enum:
- - focus-cell
+ - focus-cell
type: string
required:
- - cell_id
- - name
+ - cell_id
+ - name
type: object
FormatRequest:
properties:
@@ -947,8 +950,8 @@ components:
lineLength:
type: integer
required:
- - codes
- - lineLength
+ - codes
+ - lineLength
type: object
FormatResponse:
properties:
@@ -957,7 +960,7 @@ components:
type: string
type: object
required:
- - codes
+ - codes
type: object
FunctionCallRequest:
properties:
@@ -971,10 +974,10 @@ components:
namespace:
type: string
required:
- - functionCallId
- - namespace
- - functionName
- - args
+ - functionCallId
+ - namespace
+ - functionName
+ - args
type: object
FunctionCallResult:
properties:
@@ -982,30 +985,30 @@ components:
type: string
name:
enum:
- - function-call-result
+ - function-call-result
type: string
return_value:
nullable: true
oneOf:
- - additionalProperties:
- $ref: '#/components/schemas/JSONType'
- type: object
- - items:
- $ref: '#/components/schemas/JSONType'
- type: array
- - type: string
- - type: integer
- - type: number
- - type: boolean
- - additionalProperties: true
- type: object
- - $ref: '#/components/schemas/MIME'
+ - additionalProperties:
+ $ref: '#/components/schemas/JSONType'
+ type: object
+ - items:
+ $ref: '#/components/schemas/JSONType'
+ type: array
+ - type: string
+ - type: integer
+ - type: number
+ - type: boolean
+ - additionalProperties: true
+ type: object
+ - $ref: '#/components/schemas/MIME'
status:
$ref: '#/components/schemas/HumanReadableStatus'
required:
- - function_call_id
- - status
- - name
+ - function_call_id
+ - status
+ - name
type: object
HTTPRequest:
type: 'null'
@@ -1013,8 +1016,8 @@ components:
properties:
code:
enum:
- - ok
- - error
+ - ok
+ - error
type: string
message:
nullable: true
@@ -1023,7 +1026,7 @@ components:
nullable: true
type: string
required:
- - code
+ - code
type: object
ImportStarError:
properties:
@@ -1031,11 +1034,11 @@ components:
type: string
type:
enum:
- - import-star
+ - import-star
type: string
required:
- - msg
- - type
+ - msg
+ - type
type: object
InstallMissingPackagesRequest:
properties:
@@ -1046,27 +1049,27 @@ components:
type: string
type: object
required:
- - manager
- - versions
+ - manager
+ - versions
type: object
InstallingPackageAlert:
properties:
name:
enum:
- - installing-package-alert
+ - installing-package-alert
type: string
packages:
additionalProperties:
enum:
- - queued
- - installing
- - installed
- - failed
+ - queued
+ - installing
+ - installed
+ - failed
type: string
type: object
required:
- - packages
- - name
+ - packages
+ - name
type: object
InstantiateRequest:
properties:
@@ -1080,27 +1083,27 @@ components:
items: {}
type: array
required:
- - objectIds
- - values
- - autoRun
+ - objectIds
+ - values
+ - autoRun
type: object
Interrupted:
properties:
name:
enum:
- - interrupted
+ - interrupted
type: string
required:
- - name
+ - name
type: object
JSONType:
oneOf:
- - type: string
- - type: number
- - type: object
- - type: array
- - type: boolean
- - type: 'null'
+ - type: string
+ - type: number
+ - type: object
+ - type: array
+ - type: boolean
+ - type: 'null'
KernelReady:
properties:
app_config:
@@ -1111,8 +1114,8 @@ components:
auto_download:
items:
enum:
- - html
- - markdown
+ - html
+ - markdown
type: string
type: array
css_file:
@@ -1126,24 +1129,24 @@ components:
type: string
sql_output:
enum:
- - polars
- - lazy-polars
- - pandas
- - native
- - auto
+ - polars
+ - lazy-polars
+ - pandas
+ - native
+ - auto
type: string
width:
enum:
- - normal
- - compact
- - medium
- - full
- - columns
+ - normal
+ - compact
+ - medium
+ - full
+ - columns
type: string
required:
- - width
- - auto_download
- - sql_output
+ - width
+ - auto_download
+ - sql_output
type: object
capabilities:
properties:
@@ -1152,8 +1155,8 @@ components:
terminal:
type: boolean
required:
- - terminal
- - pylsp
+ - terminal
+ - pylsp
type: object
cell_ids:
items:
@@ -1188,12 +1191,12 @@ components:
type:
type: string
required:
- - type
- - data
+ - type
+ - data
type: object
name:
enum:
- - kernel-ready
+ - kernel-ready
type: string
names:
items:
@@ -1205,59 +1208,59 @@ components:
additionalProperties:
nullable: true
oneOf:
- - additionalProperties:
- nullable: true
- oneOf:
- - additionalProperties:
- $ref: '#/components/schemas/JSONType'
- type: object
- - items:
- $ref: '#/components/schemas/JSONType'
- type: array
- - type: string
- - type: integer
- - type: number
- - type: boolean
- - additionalProperties: true
- type: object
- - $ref: '#/components/schemas/MIME'
- type: object
- - items:
- nullable: true
- oneOf:
- - additionalProperties:
- $ref: '#/components/schemas/JSONType'
- type: object
- - items:
- $ref: '#/components/schemas/JSONType'
- type: array
- - type: string
- - type: integer
- - type: number
- - type: boolean
- - additionalProperties: true
- type: object
- - $ref: '#/components/schemas/MIME'
- type: array
- - type: string
- - type: integer
- - type: number
- - type: boolean
- - additionalProperties: true
- type: object
- - $ref: '#/components/schemas/MIME'
+ - additionalProperties:
+ nullable: true
+ oneOf:
+ - additionalProperties:
+ $ref: '#/components/schemas/JSONType'
+ type: object
+ - items:
+ $ref: '#/components/schemas/JSONType'
+ type: array
+ - type: string
+ - type: integer
+ - type: number
+ - type: boolean
+ - additionalProperties: true
+ type: object
+ - $ref: '#/components/schemas/MIME'
+ type: object
+ - items:
+ nullable: true
+ oneOf:
+ - additionalProperties:
+ $ref: '#/components/schemas/JSONType'
+ type: object
+ - items:
+ $ref: '#/components/schemas/JSONType'
+ type: array
+ - type: string
+ - type: integer
+ - type: number
+ - type: boolean
+ - additionalProperties: true
+ type: object
+ - $ref: '#/components/schemas/MIME'
+ type: array
+ - type: string
+ - type: integer
+ - type: number
+ - type: boolean
+ - additionalProperties: true
+ type: object
+ - $ref: '#/components/schemas/MIME'
nullable: true
type: object
required:
- - cell_ids
- - codes
- - names
- - configs
- - resumed
- - app_config
- - kiosk
- - capabilities
- - name
+ - cell_ids
+ - codes
+ - names
+ - configs
+ - resumed
+ - app_config
+ - kiosk
+ - capabilities
+ - name
type: object
ListPackagesResponse:
properties:
@@ -1266,14 +1269,14 @@ components:
$ref: '#/components/schemas/PackageDescription'
type: array
required:
- - packages
+ - packages
type: object
ListSecretKeysRequest:
properties:
requestId:
type: string
required:
- - requestId
+ - requestId
type: object
ListSecretKeysResponse:
properties:
@@ -1282,7 +1285,7 @@ components:
$ref: '#/components/schemas/SecretKeysWithProvider'
type: array
required:
- - keys
+ - keys
type: object
MIME:
properties: {}
@@ -1298,12 +1301,12 @@ components:
type: string
type:
enum:
- - ancestor-prevented
+ - ancestor-prevented
type: string
required:
- - msg
- - raising_cell
- - type
+ - msg
+ - raising_cell
+ - type
type: object
MarimoAncestorStoppedError:
properties:
@@ -1313,12 +1316,12 @@ components:
type: string
type:
enum:
- - ancestor-stopped
+ - ancestor-stopped
type: string
required:
- - msg
- - raising_cell
- - type
+ - msg
+ - raising_cell
+ - type
type: object
MarimoConfig:
properties:
@@ -1380,39 +1383,39 @@ components:
type: string
copilot:
oneOf:
- - type: boolean
- - enum:
- - github
- - codeium
- - custom
- type: string
+ - type: boolean
+ - enum:
+ - github
+ - codeium
+ - custom
+ type: string
model:
nullable: true
type: string
required:
- - activate_on_typing
- - copilot
+ - activate_on_typing
+ - copilot
type: object
datasources:
properties:
auto_discover_columns:
oneOf:
- - type: boolean
- - enum:
- - auto
- type: string
+ - type: boolean
+ - enum:
+ - auto
+ type: string
auto_discover_schemas:
oneOf:
- - type: boolean
- - enum:
- - auto
- type: string
+ - type: boolean
+ - enum:
+ - auto
+ type: string
auto_discover_tables:
oneOf:
- - type: boolean
- - enum:
- - auto
- type: string
+ - type: boolean
+ - enum:
+ - auto
+ type: string
type: object
diagnostics:
properties:
@@ -1423,8 +1426,8 @@ components:
properties:
cell_output:
enum:
- - above
- - below
+ - above
+ - below
type: string
code_editor_font_size:
type: integer
@@ -1434,32 +1437,32 @@ components:
type: array
dataframes:
enum:
- - rich
- - plain
+ - rich
+ - plain
type: string
default_table_page_size:
type: integer
default_width:
enum:
- - normal
- - compact
- - medium
- - full
- - columns
+ - normal
+ - compact
+ - medium
+ - full
+ - columns
type: string
theme:
enum:
- - light
- - dark
- - system
+ - light
+ - dark
+ - system
type: string
required:
- - theme
- - code_editor_font_size
- - cell_output
- - default_width
- - dataframes
- - default_table_page_size
+ - theme
+ - code_editor_font_size
+ - cell_output
+ - default_width
+ - dataframes
+ - default_table_page_size
type: object
experimental:
additionalProperties: {}
@@ -1469,7 +1472,7 @@ components:
line_length:
type: integer
required:
- - line_length
+ - line_length
type: object
keymap:
properties:
@@ -1479,14 +1482,14 @@ components:
type: object
preset:
enum:
- - default
- - vim
+ - default
+ - vim
type: string
vimrc:
nullable: true
type: string
required:
- - preset
+ - preset
type: object
language_servers:
properties:
@@ -1512,14 +1515,14 @@ components:
properties:
manager:
enum:
- - pip
- - rye
- - uv
- - poetry
- - pixi
+ - pip
+ - rye
+ - uv
+ - poetry
+ - pixi
type: string
required:
- - manager
+ - manager
type: object
runtime:
properties:
@@ -1527,17 +1530,17 @@ components:
type: boolean
auto_reload:
enum:
- - 'off'
- - lazy
- - autorun
+ - 'off'
+ - lazy
+ - autorun
type: string
default_sql_output:
enum:
- - polars
- - lazy-polars
- - pandas
- - native
- - auto
+ - polars
+ - lazy-polars
+ - pandas
+ - native
+ - auto
type: string
dotenv:
items:
@@ -1545,8 +1548,8 @@ components:
type: array
on_cell_change:
enum:
- - lazy
- - autorun
+ - lazy
+ - autorun
type: string
output_max_bytes:
type: integer
@@ -1560,48 +1563,48 @@ components:
type: integer
watcher_on_save:
enum:
- - lazy
- - autorun
+ - lazy
+ - autorun
type: string
required:
- - auto_instantiate
- - auto_reload
- - reactive_tests
- - on_cell_change
- - watcher_on_save
- - output_max_bytes
- - std_stream_max_bytes
- - default_sql_output
+ - auto_instantiate
+ - auto_reload
+ - reactive_tests
+ - on_cell_change
+ - watcher_on_save
+ - output_max_bytes
+ - std_stream_max_bytes
+ - default_sql_output
type: object
save:
properties:
autosave:
enum:
- - 'off'
- - after_delay
+ - 'off'
+ - after_delay
type: string
autosave_delay:
type: integer
format_on_save:
type: boolean
required:
- - autosave
- - autosave_delay
- - format_on_save
+ - autosave
+ - autosave_delay
+ - format_on_save
type: object
server:
properties:
browser:
oneOf:
- - enum:
- - default
- type: string
- - type: string
+ - enum:
+ - default
+ type: string
+ - type: string
follow_symlink:
type: boolean
required:
- - browser
- - follow_symlink
+ - browser
+ - follow_symlink
type: object
snippets:
properties:
@@ -1613,14 +1616,14 @@ components:
type: boolean
type: object
required:
- - completion
- - display
- - formatting
- - keymap
- - runtime
- - save
- - server
- - package_management
+ - completion
+ - display
+ - formatting
+ - keymap
+ - runtime
+ - save
+ - server
+ - package_management
type: object
MarimoExceptionRaisedError:
properties:
@@ -1633,12 +1636,12 @@ components:
type: string
type:
enum:
- - exception
+ - exception
type: string
required:
- - msg
- - exception_type
- - type
+ - msg
+ - exception_type
+ - type
type: object
MarimoFile:
properties:
@@ -1656,8 +1659,8 @@ components:
nullable: true
type: string
required:
- - name
- - path
+ - name
+ - path
type: object
MarimoInternalError:
properties:
@@ -1667,21 +1670,21 @@ components:
type: string
type:
enum:
- - internal
+ - internal
type: string
required:
- - error_id
- - type
- - msg
+ - error_id
+ - type
+ - msg
type: object
MarimoInterruptionError:
properties:
type:
enum:
- - interruption
+ - interruption
type: string
required:
- - type
+ - type
type: object
MarimoStrictExecutionError:
properties:
@@ -1694,12 +1697,12 @@ components:
type: string
type:
enum:
- - strict-exception
+ - strict-exception
type: string
required:
- - msg
- - ref
- - type
+ - msg
+ - ref
+ - type
type: object
MarimoSyntaxError:
properties:
@@ -1707,65 +1710,65 @@ components:
type: string
type:
enum:
- - syntax
+ - syntax
type: string
required:
- - msg
- - type
+ - msg
+ - type
type: object
MessageOperation:
oneOf:
- - $ref: '#/components/schemas/CellOp'
- - $ref: '#/components/schemas/FunctionCallResult'
- - $ref: '#/components/schemas/SendUIElementMessage'
- - $ref: '#/components/schemas/RemoveUIElements'
- - $ref: '#/components/schemas/Reload'
- - $ref: '#/components/schemas/Reconnected'
- - $ref: '#/components/schemas/Interrupted'
- - $ref: '#/components/schemas/CompletedRun'
- - $ref: '#/components/schemas/KernelReady'
- - $ref: '#/components/schemas/CompletionResult'
- - $ref: '#/components/schemas/Alert'
- - $ref: '#/components/schemas/Banner'
- - $ref: '#/components/schemas/MissingPackageAlert'
- - $ref: '#/components/schemas/InstallingPackageAlert'
- - $ref: '#/components/schemas/Variables'
- - $ref: '#/components/schemas/VariableValues'
- - $ref: '#/components/schemas/QueryParamsSet'
- - $ref: '#/components/schemas/QueryParamsAppend'
- - $ref: '#/components/schemas/QueryParamsDelete'
- - $ref: '#/components/schemas/QueryParamsClear'
- - $ref: '#/components/schemas/Datasets'
- - $ref: '#/components/schemas/DataColumnPreview'
- - $ref: '#/components/schemas/SQLTablePreview'
- - $ref: '#/components/schemas/SQLTableListPreview'
- - $ref: '#/components/schemas/DataSourceConnections'
- - $ref: '#/components/schemas/SecretKeysResult'
- - $ref: '#/components/schemas/FocusCell'
- - $ref: '#/components/schemas/UpdateCellCodes'
- - $ref: '#/components/schemas/UpdateCellIdsRequest'
+ - $ref: '#/components/schemas/CellOp'
+ - $ref: '#/components/schemas/FunctionCallResult'
+ - $ref: '#/components/schemas/SendUIElementMessage'
+ - $ref: '#/components/schemas/RemoveUIElements'
+ - $ref: '#/components/schemas/Reload'
+ - $ref: '#/components/schemas/Reconnected'
+ - $ref: '#/components/schemas/Interrupted'
+ - $ref: '#/components/schemas/CompletedRun'
+ - $ref: '#/components/schemas/KernelReady'
+ - $ref: '#/components/schemas/CompletionResult'
+ - $ref: '#/components/schemas/Alert'
+ - $ref: '#/components/schemas/Banner'
+ - $ref: '#/components/schemas/MissingPackageAlert'
+ - $ref: '#/components/schemas/InstallingPackageAlert'
+ - $ref: '#/components/schemas/Variables'
+ - $ref: '#/components/schemas/VariableValues'
+ - $ref: '#/components/schemas/QueryParamsSet'
+ - $ref: '#/components/schemas/QueryParamsAppend'
+ - $ref: '#/components/schemas/QueryParamsDelete'
+ - $ref: '#/components/schemas/QueryParamsClear'
+ - $ref: '#/components/schemas/Datasets'
+ - $ref: '#/components/schemas/DataColumnPreview'
+ - $ref: '#/components/schemas/SQLTablePreview'
+ - $ref: '#/components/schemas/SQLTableListPreview'
+ - $ref: '#/components/schemas/DataSourceConnections'
+ - $ref: '#/components/schemas/SecretKeysResult'
+ - $ref: '#/components/schemas/FocusCell'
+ - $ref: '#/components/schemas/UpdateCellCodes'
+ - $ref: '#/components/schemas/UpdateCellIdsRequest'
MimeType:
enum:
- - application/json
- - application/vnd.marimo+error
- - application/vnd.marimo+traceback
- - application/vnd.marimo+mimebundle
- - application/vnd.vega.v5+json
- - application/vnd.vegalite.v5+json
- - image/png
- - image/svg+xml
- - image/tiff
- - image/avif
- - image/bmp
- - image/gif
- - image/jpeg
- - video/mp4
- - video/mpeg
- - text/html
- - text/plain
- - text/markdown
- - text/latex
- - text/csv
+ - application/json
+ - application/vnd.marimo+error
+ - application/vnd.marimo+traceback
+ - application/vnd.marimo+mimebundle
+ - application/vnd.vega.v5+json
+ - application/vnd.vegalite.v5+json
+ - image/png
+ - image/svg+xml
+ - image/tiff
+ - image/avif
+ - image/bmp
+ - image/gif
+ - image/jpeg
+ - video/mp4
+ - video/mpeg
+ - text/html
+ - text/plain
+ - text/markdown
+ - text/latex
+ - text/csv
type: string
MissingPackageAlert:
properties:
@@ -1773,16 +1776,16 @@ components:
type: boolean
name:
enum:
- - missing-package-alert
+ - missing-package-alert
type: string
packages:
items:
type: string
type: array
required:
- - packages
- - isolated
- - name
+ - packages
+ - isolated
+ - name
type: object
MultipleDefinitionError:
properties:
@@ -1794,49 +1797,49 @@ components:
type: string
type:
enum:
- - multiple-defs
+ - multiple-defs
type: string
required:
- - name
- - cells
- - type
+ - name
+ - cells
+ - type
type: object
NonNestedLiteral:
oneOf:
- - type: integer
- - type: number
- - format: date
- type: string
- - format: time
- type: string
- - format: date-time
- type: string
- - format: duration
- type: string
- - type: string
- - type: boolean
- - format: byte
- type: string
+ - type: integer
+ - type: number
+ - format: date
+ type: string
+ - format: time
+ type: string
+ - format: date-time
+ type: string
+ - format: duration
+ type: string
+ - type: string
+ - type: boolean
+ - format: byte
+ type: string
OpenTutorialRequest:
properties:
tutorialId:
oneOf:
- - enum:
- - intro
- - dataflow
- - ui
- - markdown
- - plots
- - sql
- - layout
- - fileformat
- - for-jupyter-users
- type: string
- - enum:
- - markdown-format
- type: string
+ - enum:
+ - intro
+ - dataflow
+ - ui
+ - markdown
+ - plots
+ - sql
+ - layout
+ - fileformat
+ - for-jupyter-users
+ type: string
+ - enum:
+ - markdown-format
+ type: string
required:
- - tutorialId
+ - tutorialId
type: object
PackageDescription:
properties:
@@ -1845,8 +1848,8 @@ components:
version:
type: string
required:
- - name
- - version
+ - name
+ - version
type: object
PackageOperationResponse:
properties:
@@ -1856,7 +1859,7 @@ components:
success:
type: boolean
required:
- - success
+ - success
type: object
PdbRequest:
properties:
@@ -1866,14 +1869,14 @@ components:
$ref: '#/components/schemas/HTTPRequest'
nullable: true
required:
- - cellId
+ - cellId
type: object
PreviewDataSourceConnectionRequest:
properties:
engine:
type: string
required:
- - engine
+ - engine
type: object
PreviewDatasetColumnRequest:
properties:
@@ -1886,18 +1889,18 @@ components:
type: string
sourceType:
enum:
- - local
- - duckdb
- - connection
- - catalog
+ - local
+ - duckdb
+ - connection
+ - catalog
type: string
tableName:
type: string
required:
- - sourceType
- - source
- - tableName
- - columnName
+ - sourceType
+ - source
+ - tableName
+ - columnName
type: object
PreviewSQLTableListRequest:
properties:
@@ -1910,10 +1913,10 @@ components:
schema:
type: string
required:
- - requestId
- - engine
- - database
- - schema
+ - requestId
+ - engine
+ - database
+ - schema
type: object
PreviewSQLTableRequest:
properties:
@@ -1928,11 +1931,11 @@ components:
tableName:
type: string
required:
- - requestId
- - engine
- - database
- - schema
- - tableName
+ - requestId
+ - engine
+ - database
+ - schema
+ - tableName
type: object
QueryParamsAppend:
properties:
@@ -1940,23 +1943,23 @@ components:
type: string
name:
enum:
- - query-params-append
+ - query-params-append
type: string
value:
type: string
required:
- - key
- - value
- - name
+ - key
+ - value
+ - name
type: object
QueryParamsClear:
properties:
name:
enum:
- - query-params-clear
+ - query-params-clear
type: string
required:
- - name
+ - name
type: object
QueryParamsDelete:
properties:
@@ -1964,14 +1967,14 @@ components:
type: string
name:
enum:
- - query-params-delete
+ - query-params-delete
type: string
value:
nullable: true
type: string
required:
- - key
- - name
+ - key
+ - name
type: object
QueryParamsSet:
properties:
@@ -1979,25 +1982,25 @@ components:
type: string
name:
enum:
- - query-params-set
+ - query-params-set
type: string
value:
oneOf:
- - type: string
- - items:
- type: string
- type: array
+ - type: string
+ - items:
+ type: string
+ type: array
required:
- - key
- - value
- - name
+ - key
+ - value
+ - name
type: object
ReadCodeResponse:
properties:
contents:
type: string
required:
- - contents
+ - contents
type: object
RecentFilesResponse:
properties:
@@ -2006,32 +2009,32 @@ components:
$ref: '#/components/schemas/MarimoFile'
type: array
required:
- - files
+ - files
type: object
Reconnected:
properties:
name:
enum:
- - reconnected
+ - reconnected
type: string
required:
- - name
+ - name
type: object
Reload:
properties:
name:
enum:
- - reload
+ - reload
type: string
required:
- - name
+ - name
type: object
RemovePackageRequest:
properties:
package:
type: string
required:
- - package
+ - package
type: object
RemoveUIElements:
properties:
@@ -2039,25 +2042,25 @@ components:
type: string
name:
enum:
- - remove-ui-elements
+ - remove-ui-elements
type: string
required:
- - cell_id
- - name
+ - cell_id
+ - name
type: object
RenameFileRequest:
properties:
filename:
type: string
required:
- - filename
+ - filename
type: object
RenameRequest:
properties:
filename:
type: string
required:
- - filename
+ - filename
type: object
RunRequest:
properties:
@@ -2073,8 +2076,8 @@ components:
$ref: '#/components/schemas/HTTPRequest'
nullable: true
required:
- - cellIds
- - codes
+ - cellIds
+ - codes
type: object
RunningNotebooksResponse:
properties:
@@ -2083,14 +2086,14 @@ components:
$ref: '#/components/schemas/MarimoFile'
type: array
required:
- - files
+ - files
type: object
RuntimeState:
enum:
- - idle
- - queued
- - running
- - disabled-transitively
+ - idle
+ - queued
+ - running
+ - disabled-transitively
type: string
SQLTableListPreview:
properties:
@@ -2099,7 +2102,7 @@ components:
type: string
name:
enum:
- - sql-table-list-preview
+ - sql-table-list-preview
type: string
request_id:
type: string
@@ -2108,9 +2111,9 @@ components:
$ref: '#/components/schemas/DataTable'
type: array
required:
- - request_id
- - tables
- - name
+ - request_id
+ - tables
+ - name
type: object
SQLTablePreview:
properties:
@@ -2119,7 +2122,7 @@ components:
type: string
name:
enum:
- - sql-table-preview
+ - sql-table-preview
type: string
request_id:
type: string
@@ -2127,8 +2130,8 @@ components:
$ref: '#/components/schemas/DataTable'
nullable: true
required:
- - request_id
- - name
+ - request_id
+ - name
type: object
SaveAppConfigurationRequest:
properties:
@@ -2136,7 +2139,7 @@ components:
additionalProperties: {}
type: object
required:
- - config
+ - config
type: object
SaveNotebookRequest:
properties:
@@ -2165,19 +2168,19 @@ components:
persist:
type: boolean
required:
- - cellIds
- - codes
- - names
- - configs
- - filename
- - persist
+ - cellIds
+ - codes
+ - names
+ - configs
+ - filename
+ - persist
type: object
SaveUserConfigurationRequest:
properties:
config:
$ref: '#/components/schemas/MarimoConfig'
required:
- - config
+ - config
type: object
Schema:
properties:
@@ -2188,8 +2191,8 @@ components:
$ref: '#/components/schemas/DataTable'
type: array
required:
- - name
- - tables
+ - name
+ - tables
type: object
SchemaColumn:
properties:
@@ -2201,9 +2204,9 @@ components:
type:
type: string
required:
- - name
- - type
- - sampleValues
+ - name
+ - type
+ - sampleValues
type: object
SchemaTable:
properties:
@@ -2214,14 +2217,14 @@ components:
name:
type: string
required:
- - name
- - columns
+ - name
+ - columns
type: object
SecretKeysResult:
properties:
name:
enum:
- - secret-keys-result
+ - secret-keys-result
type: string
request_id:
type: string
@@ -2230,9 +2233,9 @@ components:
$ref: '#/components/schemas/SecretKeysWithProvider'
type: array
required:
- - request_id
- - secrets
- - name
+ - request_id
+ - secrets
+ - name
type: object
SecretKeysWithProvider:
properties:
@@ -2244,13 +2247,13 @@ components:
type: string
provider:
enum:
- - env
- - dotenv
+ - env
+ - dotenv
type: string
required:
- - provider
- - name
- - keys
+ - provider
+ - name
+ - keys
type: object
SendUIElementMessage:
properties:
@@ -2267,14 +2270,14 @@ components:
type: string
name:
enum:
- - send-ui-element-message
+ - send-ui-element-message
type: string
ui_element:
nullable: true
type: string
required:
- - message
- - name
+ - message
+ - name
type: object
SetCellConfigRequest:
properties:
@@ -2284,7 +2287,7 @@ components:
type: object
type: object
required:
- - configs
+ - configs
type: object
SetModelMessageRequest:
properties:
@@ -2299,22 +2302,22 @@ components:
items:
items:
oneOf:
- - type: string
- - type: integer
+ - type: string
+ - type: integer
type: array
type: array
state:
additionalProperties: {}
type: object
required:
- - state
- - bufferPaths
+ - state
+ - bufferPaths
type: object
modelId:
type: string
required:
- - modelId
- - message
+ - modelId
+ - message
type: object
SetUIElementValueRequest:
properties:
@@ -2331,43 +2334,43 @@ components:
items: {}
type: array
required:
- - objectIds
- - values
- - token
+ - objectIds
+ - values
+ - token
type: object
SetUserConfigRequest:
properties:
config:
$ref: '#/components/schemas/MarimoConfig'
required:
- - config
+ - config
type: object
SetupRootError:
properties:
edges_with_vars:
items:
prefixItems:
- - type: string
- - items:
- type: string
- type: array
- - type: string
+ - type: string
+ - items:
+ type: string
+ type: array
+ - type: string
type: array
type: array
type:
enum:
- - setup-refs
+ - setup-refs
type: string
required:
- - edges_with_vars
- - type
+ - edges_with_vars
+ - type
type: object
ShutdownSessionRequest:
properties:
sessionId:
type: string
required:
- - sessionId
+ - sessionId
type: object
Snippet:
properties:
@@ -2378,8 +2381,8 @@ components:
title:
type: string
required:
- - title
- - sections
+ - title
+ - sections
type: object
SnippetSection:
properties:
@@ -2392,7 +2395,7 @@ components:
id:
type: string
required:
- - id
+ - id
type: object
Snippets:
properties:
@@ -2401,14 +2404,14 @@ components:
$ref: '#/components/schemas/Snippet'
type: array
required:
- - snippets
+ - snippets
type: object
StdinRequest:
properties:
text:
type: string
required:
- - text
+ - text
type: object
StopRequest:
properties: {}
@@ -2418,7 +2421,7 @@ components:
success:
type: boolean
required:
- - success
+ - success
type: object
UnknownError:
properties:
@@ -2426,11 +2429,11 @@ components:
type: string
type:
enum:
- - unknown
+ - unknown
type: string
required:
- - msg
- - type
+ - msg
+ - type
type: object
UpdateCellCodes:
properties:
@@ -2446,13 +2449,13 @@ components:
type: array
name:
enum:
- - update-cell-codes
+ - update-cell-codes
type: string
required:
- - cell_ids
- - codes
- - code_is_stale
- - name
+ - cell_ids
+ - codes
+ - code_is_stale
+ - name
type: object
UpdateCellIdsRequest:
properties:
@@ -2462,11 +2465,11 @@ components:
type: array
name:
enum:
- - update-cell-ids
+ - update-cell-ids
type: string
required:
- - cell_ids
- - name
+ - cell_ids
+ - name
type: object
UpdateComponentValuesRequest:
properties:
@@ -2478,8 +2481,8 @@ components:
items: {}
type: array
required:
- - objectIds
- - values
+ - objectIds
+ - values
type: object
VariableContext:
properties:
@@ -2489,9 +2492,9 @@ components:
valueType:
type: string
required:
- - name
- - valueType
- - previewValue
+ - name
+ - valueType
+ - previewValue
type: object
VariableDeclaration:
properties:
@@ -2506,9 +2509,9 @@ components:
type: string
type: array
required:
- - name
- - declared_by
- - used_by
+ - name
+ - declared_by
+ - used_by
type: object
VariableValue:
properties:
@@ -2521,42 +2524,42 @@ components:
nullable: true
type: string
required:
- - name
+ - name
type: object
VariableValues:
properties:
name:
enum:
- - variable-values
+ - variable-values
type: string
variables:
items:
$ref: '#/components/schemas/VariableValue'
type: array
required:
- - variables
- - name
+ - variables
+ - name
type: object
Variables:
properties:
name:
enum:
- - variables
+ - variables
type: string
variables:
items:
$ref: '#/components/schemas/VariableDeclaration'
type: array
required:
- - variables
- - name
+ - variables
+ - name
type: object
WorkspaceFilesRequest:
properties:
includeMarkdown:
type: boolean
required:
- - includeMarkdown
+ - includeMarkdown
type: object
WorkspaceFilesResponse:
properties:
@@ -2567,8 +2570,8 @@ components:
root:
type: string
required:
- - root
- - files
+ - root
+ - files
type: object
info:
title: marimo API
@@ -2578,12 +2581,12 @@ paths:
/@file/{filename_and_length}:
get:
parameters:
- - description: The filename and byte length of the virtual file
- in: path
- name: filename_and_length
- required: true
- schema:
- type: string
+ - description: The filename and byte length of the virtual file
+ in: path
+ name: filename_and_length
+ required: true
+ schema:
+ type: string
responses:
200:
content:
@@ -3403,7 +3406,7 @@ paths:
percent:
type: number
required:
- - percent
+ - percent
type: object
gpu:
items:
@@ -3421,17 +3424,17 @@ paths:
used:
type: integer
required:
- - total
- - used
- - free
- - percent
+ - total
+ - used
+ - free
+ - percent
type: object
name:
type: string
required:
- - index
- - memory
- - name
+ - index
+ - memory
+ - name
type: object
type: array
kernel:
@@ -3452,22 +3455,22 @@ paths:
used:
type: integer
required:
- - total
- - available
- - percent
- - used
- - free
+ - total
+ - available
+ - percent
+ - used
+ - free
type: object
server:
properties:
memory:
type: integer
required:
- - memory
+ - memory
type: object
required:
- - memory
- - cpu
+ - memory
+ - cpu
type: object
description: Get the current memory and CPU usage of the application
/api/version:
@@ -3505,5 +3508,4 @@ paths:
type: string
summary: Submit login form
tags:
- - auth
-
+ - auth
diff --git a/openapi/src/api.ts b/openapi/src/api.ts
index ed69036f71..04af119bc0 100644
--- a/openapi/src/api.ts
+++ b/openapi/src/api.ts
@@ -2462,6 +2462,7 @@ export interface components {
schemas: {
AddPackageRequest: {
package: string;
+ upgrade?: boolean | null;
};
AiCompletionContext: {
schema: components["schemas"]["SchemaTable"][];
diff --git a/tests/_runtime/packages/test_package_managers.py b/tests/_runtime/packages/test_package_managers.py
index df22e57208..adedf15f27 100644
--- a/tests/_runtime/packages/test_package_managers.py
+++ b/tests/_runtime/packages/test_package_managers.py
@@ -38,7 +38,10 @@ def test_update_script_metadata() -> None:
pm = MockUvPackageManager()
pm.update_notebook_script_metadata(
- "nb.py", packages_to_add=["foo"], packages_to_remove=["bar"]
+ "nb.py",
+ packages_to_add=["foo"],
+ packages_to_remove=["bar"],
+ upgrade=False,
)
assert runs_calls == [
["uv", "--quiet", "add", "--script", "nb.py", "foo==1.0"],
@@ -62,11 +65,15 @@ def test_update_script_metadata_with_version_map() -> None:
pm = MockUvPackageManager()
# It should ignore when not in the version map
# as this implies it failed to install
- pm.update_notebook_script_metadata("nb.py", packages_to_add=["baz"])
+ pm.update_notebook_script_metadata(
+ "nb.py", packages_to_add=["baz"], upgrade=False
+ )
assert runs_calls == []
# It will attempt to uninstall even if not in the version map
- pm.update_notebook_script_metadata("nb.py", packages_to_remove=["baz"])
+ pm.update_notebook_script_metadata(
+ "nb.py", packages_to_remove=["baz"], upgrade=False
+ )
assert runs_calls == [
["uv", "--quiet", "remove", "--script", "nb.py", "baz"],
]
@@ -85,7 +92,9 @@ def test_update_script_metadata_with_mapping() -> None:
pm = MockUvPackageManager()
# It should not canonicalize when passed explicitly
- pm.update_notebook_script_metadata("nb.py", packages_to_add=["ibis"])
+ pm.update_notebook_script_metadata(
+ "nb.py", packages_to_add=["ibis"], upgrade=False
+ )
assert runs_calls == [
["uv", "--quiet", "add", "--script", "nb.py", "ibis==2.0"],
]
@@ -94,7 +103,7 @@ def test_update_script_metadata_with_mapping() -> None:
# It should not canonicalize when passed as an import name
# case-insensitive
pm.update_notebook_script_metadata(
- "nb.py", import_namespaces_to_add=["yaml"]
+ "nb.py", import_namespaces_to_add=["yaml"], upgrade=False
)
assert runs_calls == [
["uv", "--quiet", "add", "--script", "nb.py", "PyYAML==1.0"],
@@ -104,7 +113,7 @@ def test_update_script_metadata_with_mapping() -> None:
# It should not canonicalize when passed as an import name
# and works with brackets
pm.update_notebook_script_metadata(
- "nb.py", import_namespaces_to_add=["ibis"]
+ "nb.py", import_namespaces_to_add=["ibis"], upgrade=False
)
assert runs_calls == [
[
@@ -142,6 +151,7 @@ def test_update_script_metadata_marimo_packages() -> None:
"marimo-ai", # Should have version (different package)
"pandas", # Should have version
],
+ upgrade=False,
)
assert runs_calls == [
[
@@ -164,6 +174,7 @@ def test_update_script_metadata_marimo_packages() -> None:
"marimo[sql]",
"pandas",
],
+ upgrade=False,
)
assert runs_calls == [
[
@@ -188,6 +199,7 @@ def test_update_script_metadata_marimo_packages() -> None:
"marimo[recommended]",
"pandas",
],
+ upgrade=False,
)
assert runs_calls == [
[
@@ -211,6 +223,7 @@ def test_update_script_metadata_marimo_packages() -> None:
"marimo",
"pandas",
],
+ upgrade=False,
)
assert runs_calls == [
[
@@ -225,6 +238,25 @@ def test_update_script_metadata_marimo_packages() -> None:
]
runs_calls.clear()
+ # Test 5: Upgrade
+ pm.update_notebook_script_metadata(
+ filepath="nb.py",
+ packages_to_add=["pandas"],
+ upgrade=True,
+ )
+ assert runs_calls == [
+ [
+ "uv",
+ "--quiet",
+ "add",
+ "--script",
+ "nb.py",
+ "--upgrade",
+ "pandas==2.0.0",
+ ],
+ ]
+ runs_calls.clear()
+
async def test_uv_pip_install() -> None:
runs_calls: list[list[str]] = []
@@ -235,7 +267,7 @@ async def test_uv_pip_install() -> None:
return True
pm = MockUvPackageManager()
- await pm._install("foo")
+ await pm._install("foo", upgrade=False)
assert runs_calls == [
["uv", "pip", "install", "--compile", "foo", "-p", PY_EXE],
]
diff --git a/tests/_runtime/packages/test_pypi_package_manager.py b/tests/_runtime/packages/test_pypi_package_manager.py
index d7cc996b32..978d822ca7 100644
--- a/tests/_runtime/packages/test_pypi_package_manager.py
+++ b/tests/_runtime/packages/test_pypi_package_manager.py
@@ -44,7 +44,7 @@ manager = PipPackageManager()
async def test_install(mock_run: MagicMock):
mock_run.return_value = MagicMock(returncode=0)
- result = await manager._install("package1 package2")
+ result = await manager._install("package1 package2", upgrade=False)
mock_run.assert_called_once_with(
["pip", "--python", PY_EXE, "install", "package1", "package2"],
@@ -56,7 +56,7 @@ async def test_install(mock_run: MagicMock):
async def test_install_failure(mock_run: MagicMock):
mock_run.return_value = MagicMock(returncode=1)
- result = await manager._install("nonexistent-package")
+ result = await manager._install("nonexistent-package", upgrade=False)
assert result is False
@@ -199,7 +199,7 @@ async def test_uv_install_not_in_project(mock_run: MagicMock):
mock_run.return_value = MagicMock(returncode=0)
mgr = UvPackageManager()
- result = await mgr._install("package1 package2")
+ result = await mgr._install("package1 package2", upgrade=False)
mock_run.assert_called_once_with(
[
@@ -223,7 +223,7 @@ async def test_uv_install_in_project(mock_run: MagicMock):
mock_run.return_value = MagicMock(returncode=0)
mgr = UvPackageManager()
- result = await mgr._install("package1 package2")
+ result = await mgr._install("package1 package2", upgrade=False)
mock_run.assert_called_once_with(
["uv", "add", "--compile", "package1", "package2", "-p", PY_EXE],
@@ -283,3 +283,74 @@ def test_uv_list_packages(mock_run: MagicMock):
assert len(packages) == 2
assert packages[0] == PackageDescription(name="package1", version="1.0.0")
assert packages[1] == PackageDescription(name="package2", version="2.1.0")
+
+
+@patch("subprocess.run")
[email protected](PipPackageManager, "is_manager_installed", return_value=True)
+async def test_install_with_upgrade(
+ mock_is_installed: MagicMock, mock_run: MagicMock
+):
+ del mock_is_installed
+ mock_run.return_value = MagicMock(returncode=0)
+
+ result = await manager._install("package1", upgrade=True)
+
+ mock_run.assert_called_once_with(
+ ["pip", "--python", PY_EXE, "install", "--upgrade", "package1"],
+ )
+ assert result is True
+
+
+@patch("subprocess.run")
[email protected](PipPackageManager, "is_manager_installed", return_value=True)
+async def test_install_without_upgrade(
+ mock_is_installed: MagicMock, mock_run: MagicMock
+):
+ del mock_is_installed
+ mock_run.return_value = MagicMock(returncode=0)
+
+ result = await manager._install("package1", upgrade=False)
+
+ mock_run.assert_called_once_with(
+ ["pip", "--python", PY_EXE, "install", "package1"],
+ )
+ assert result is True
+
+
+@patch("subprocess.run")
[email protected](UvPackageManager, "is_in_uv_project", False)
+async def test_uv_install_with_upgrade_not_in_project(mock_run: MagicMock):
+ """Test UV install with upgrade uses pip subcommand when not in UV project"""
+ mock_run.return_value = MagicMock(returncode=0)
+ mgr = UvPackageManager()
+
+ result = await mgr._install("package1", upgrade=True)
+
+ mock_run.assert_called_once_with(
+ [
+ "uv",
+ "pip",
+ "install",
+ "--upgrade",
+ "--compile",
+ "package1",
+ "-p",
+ PY_EXE,
+ ]
+ )
+ assert result is True
+
+
+@patch("subprocess.run")
[email protected](UvPackageManager, "is_in_uv_project", True)
+async def test_uv_install_with_upgrade_in_project(mock_run: MagicMock):
+ """Test UV install with upgrade uses add subcommand when in UV project"""
+ mock_run.return_value = MagicMock(returncode=0)
+ mgr = UvPackageManager()
+
+ result = await mgr._install("package1", upgrade=True)
+
+ mock_run.assert_called_once_with(
+ ["uv", "add", "--upgrade", "--compile", "package1", "-p", PY_EXE]
+ )
+ assert result is True
diff --git a/tests/_server/api/endpoints/test_packages.py b/tests/_server/api/endpoints/test_packages.py
index 84da5df98e..e32f58b18a 100644
--- a/tests/_server/api/endpoints/test_packages.py
+++ b/tests/_server/api/endpoints/test_packages.py
@@ -51,7 +51,7 @@ def test_add_package(client: TestClient, mock_package_manager: Mock) -> None:
assert response.status_code == 200
assert response.json() == {"success": True, "error": None}
mock_package_manager.install.assert_called_once_with(
- "test-package", version=None
+ "test-package", version=None, upgrade=False
)
@@ -134,3 +134,35 @@ def test_remove_package_failure(
"success": False,
"error": "Failed to uninstall test-package. See terminal for error logs.", # noqa: E501
}
+
+
+def test_add_package_with_upgrade(
+ client: TestClient, mock_package_manager: Mock
+) -> None:
+ assert isinstance(mock_package_manager, MagicMock)
+ response = client.post(
+ "/api/packages/add",
+ headers=HEADERS,
+ json={"package": "test-package", "upgrade": True},
+ )
+ assert response.status_code == 200
+ assert response.json() == {"success": True, "error": None}
+ mock_package_manager.install.assert_called_once_with(
+ "test-package", version=None, upgrade=True
+ )
+
+
+def test_add_package_without_upgrade(
+ client: TestClient, mock_package_manager: Mock
+) -> None:
+ assert isinstance(mock_package_manager, MagicMock)
+ response = client.post(
+ "/api/packages/add",
+ headers=HEADERS,
+ json={"package": "test-package", "upgrade": False},
+ )
+ assert response.status_code == 200
+ assert response.json() == {"success": True, "error": None}
+ mock_package_manager.install.assert_called_once_with(
+ "test-package", version=None, upgrade=False
+ )