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.

feat: convert handle `uv pip install` (#7179)

Dylan Madisetti88e1b314f449
diff --git a/marimo/_convert/ipynb.py b/marimo/_convert/ipynb.py
index 6af5f4b0c4..ff74b4d8d1 100644
--- a/marimo/_convert/ipynb.py
+++ b/marimo/_convert/ipynb.py
@@ -453,8 +453,12 @@ def _handle_exclamation_command(
if not command_tokens:
return ExclamationCommandResult(f"# !{command_line}", [], False)
- if command_tokens[0].startswith("pip"):
- return _extract_pip_install(command_line, command_tokens)
+ # scrub past tokens until pip
+ # For instance in the case `uv pip install ...`
+ for i, token in enumerate(command_tokens):
+ if token.startswith("pip"):
+ return _extract_pip_install(command_line, command_tokens[i:])
+
# Replace with subprocess.call()
return _shlex_to_subprocess_call(command_line, command_tokens)
diff --git a/tests/_convert/test_ipynb.py b/tests/_convert/test_ipynb.py
index f22be0cca9..77241e0e62 100644
--- a/tests/_convert/test_ipynb.py
+++ b/tests/_convert/test_ipynb.py
@@ -388,6 +388,8 @@ def test_transform_exclamation_mark_complex():
"!ls -l",
"!echo 'Hello, World!'",
"!python script.py arg1 arg2",
+ "!python -m pip3 install package1 package2",
+ "!uv pip install package1 package2",
]
result = transform_exclamation_mark(sources)
assert result.transformed_sources == [
@@ -395,6 +397,8 @@ def test_transform_exclamation_mark_complex():
"#! ls -l\nsubprocess.call(['ls', '-l'])",
"#! echo 'Hello, World!'\nsubprocess.call(['echo', 'Hello, World!'])",
"#! python script.py arg1 arg2\nsubprocess.call(['python', 'script.py', 'arg1', 'arg2'])",
+ "# packages added via marimo's package management: package1 package2 !python -m pip3 install package1 package2",
+ "# packages added via marimo's package management: package1 package2 !uv pip install package1 package2",
]