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.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
fix: dont autoinstall pkgs we already tried installing (#1828)
Akshay Agrawalc67a2cb44f66
diff --git a/marimo/_runtime/packages/conda_package_manager.py b/marimo/_runtime/packages/conda_package_manager.pyindex 0ededdfdac..b6e45cbd25 100644--- a/marimo/_runtime/packages/conda_package_manager.py+++ b/marimo/_runtime/packages/conda_package_manager.py@@ -17,5 +17,5 @@ class CondaPackageManager(CanonicalizingPackageManager):class PixiPackageManager(CondaPackageManager):name = "pixi"- async def install(self, package: str) -> bool:+ async def _install(self, package: str) -> bool:return self.run(["pixi", "add", package])diff --git a/marimo/_runtime/packages/package_manager.py b/marimo/_runtime/packages/package_manager.pyindex 5696733132..66fc2af034 100644--- a/marimo/_runtime/packages/package_manager.py+++ b/marimo/_runtime/packages/package_manager.py@@ -11,6 +11,9 @@ class PackageManager(abc.ABC):name: str+ def __init__(self) -> None:+ self._attempted_packages: set[str] = set()+@abc.abstractmethoddef module_to_package(self, module_name: str) -> str:"""Canonicalizes a module name to a package name."""@@ -26,12 +29,21 @@ class PackageManager(abc.ABC):return shutil.which(self.name) is not None@abc.abstractmethod+ async def _install(self, package: str) -> bool:+ """Installation logic."""+ ...+async def install(self, package: str) -> 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(package)++ def attempted_to_install(self, package: str) -> bool:+ """True iff package installation was previously attempted."""+ return package in self._attempted_packagesdef should_auto_install(self) -> bool:"""Should this package manager auto-install packages"""@@ -56,6 +68,7 @@ class CanonicalizingPackageManager(PackageManager):# Initialized lazilyself._module_name_to_repo_name: dict[str, str] | None = Noneself._repo_name_to_module_name: dict[str, str] | None = None+ super().__init__()@abc.abstractmethoddef _construct_module_name_mapping(self) -> dict[str, str]: ...diff --git a/marimo/_runtime/packages/pypi_package_manager.py b/marimo/_runtime/packages/pypi_package_manager.pyindex 4eef27477f..af26567a5c 100644--- a/marimo/_runtime/packages/pypi_package_manager.py+++ b/marimo/_runtime/packages/pypi_package_manager.py@@ -18,7 +18,7 @@ class PypiPackageManager(CanonicalizingPackageManager):class PipPackageManager(PypiPackageManager):name = "pip"- async def install(self, package: str) -> bool:+ async def _install(self, package: str) -> bool:return self.run(["pip", "install", package])@@ -31,7 +31,7 @@ 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) -> bool:assert is_pyodide()import micropip # type: ignore@@ -45,19 +45,19 @@ class MicropipPackageManager(PypiPackageManager):class UvPackageManager(PypiPackageManager):name = "uv"- async def install(self, package: str) -> bool:+ async def _install(self, package: str) -> bool:return self.run(["uv", "pip", "install", package])class RyePackageManager(PypiPackageManager):name = "rye"- async def install(self, package: str) -> bool:+ async def _install(self, package: str) -> bool:return self.run(["rye", "add", package])class PoetryPackageManager(PypiPackageManager):name = "poetry"- async def install(self, package: str) -> bool:+ async def _install(self, package: str) -> bool:return self.run(["poetry", "add", package])diff --git a/marimo/_runtime/runtime.py b/marimo/_runtime/runtime.pyindex 5ae57e76ad..296ca98c2c 100644--- a/marimo/_runtime/runtime.py+++ b/marimo/_runtime/runtime.py@@ -673,8 +673,13 @@ class Kernel:MissingPackageAlert(packages=list(sorted(- self.package_manager.module_to_package(mod)+ pkgfor mod in missing_modules_after_deletion+ if not self.package_manager.attempted_to_install(+ pkg := self.package_manager.module_to_package(+ mod+ )+ ))),isolated=is_python_isolated(),@@ -949,8 +954,13 @@ class Kernel:and self.package_manager is not None):missing_packages = [- self.package_manager.module_to_package(mod)+ pkgfor mod in self.module_registry.missing_modules()+ # filter out packages that we already attempted to install+ # to prevent an infinite loop+ if not self.package_manager.attempted_to_install(+ pkg := self.package_manager.module_to_package(mod)+ )]if missing_packages:@@ -1504,6 +1514,10 @@ class Kernel:for mod in missing_modules:pkg = self.package_manager.module_to_package(mod)+ if self.package_manager.attempted_to_install(package=pkg):+ # Already attempted an installation; it must have failed.+ # Skip the installation.+ continuepackage_statuses[pkg] = "installing"InstallingPackageAlert(packages=package_statuses).broadcast()if await self.package_manager.install(pkg):