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.

fix: package versions in envinfo (#1010)

Akshay Agrawalca254d6a168e
diff --git a/marimo/_utils/health.py b/marimo/_utils/health.py
index 46fafead2b..e34fed9e17 100644
--- a/marimo/_utils/health.py
+++ b/marimo/_utils/health.py
@@ -1,16 +1,12 @@
# Copyright 2024 Marimo. All rights reserved.
from __future__ import annotations
+import importlib.metadata
import subprocess
import sys
from typing import Optional
-# Stub for missing modules
-class _DefaultModule:
- __version__ = "missing"
-
-
def get_node_version() -> Optional[str]:
try:
process = subprocess.Popen(
@@ -28,9 +24,9 @@ def get_node_version() -> Optional[str]:
def get_required_modules_list() -> dict[str, str]:
- allowlist = [
+ packages = [
"click",
- "importlib_resources",
+ "importlib-resources",
"jedi",
"markdown",
"pymdown-extensions",
@@ -39,18 +35,21 @@ def get_required_modules_list() -> dict[str, str]:
"uvicorn",
"starlette",
"websocket",
- "typing_extensions",
+ "typing-extensions",
"black",
]
+
+ package_versions: dict[str, str] = {}
# Consider listing all installed modules and their versions
# Submodules and private modules are can be filtered with:
# if not ("." in m or m.startswith("_")):
- return {
- module: getattr(
- sys.modules.get(module, _DefaultModule), "__version__", "--"
- )
- for module in allowlist
- }
+ for package in packages:
+ try:
+ package_versions[package] = importlib.metadata.version(package)
+ except importlib.metadata.PackageNotFoundError:
+ package_versions[package] = "missing"
+
+ return package_versions
def get_chrome_version() -> Optional[str]:
diff --git a/tests/_cli/test_envinfo.py b/tests/_cli/test_envinfo.py
index 2c4d9ab19f..1da24332e0 100644
--- a/tests/_cli/test_envinfo.py
+++ b/tests/_cli/test_envinfo.py
@@ -13,14 +13,18 @@ def test_get_node_version() -> None:
assert node_version is None or isinstance(node_version, str)
-def test_get_pip_list() -> None:
+def test_get_package_versions() -> None:
system_info = get_system_info()
assert "Requirements" in system_info
- pip_list = system_info["Requirements"]
-
- assert isinstance(pip_list, dict)
- assert "click" in pip_list
- assert "starlette" in pip_list
+ package_versions = system_info["Requirements"]
+
+ assert isinstance(package_versions, dict)
+ assert "click" in package_versions
+ assert "starlette" in package_versions
+ assert (
+ "pymdown-extensions" in package_versions
+ and package_versions["pymdown-extensions"] != "missing"
+ )
def test_get_system_info() -> None: