Skip to content

Commit e084501

Browse files
authored
fix: Installation flag (#5842)
## 📝 Summary `UV_TARGET` does not exist
1 parent 36be39b commit e084501

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

marimo/_runtime/packages/pypi_package_manager.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,14 @@ async def _install(self, package: str, *, upgrade: bool) -> bool:
152152
install_cmd = [self._uv_bin, "add"]
153153
else:
154154
LOGGER.info(f"Installing in {package} with 'uv pip install'")
155+
155156
install_cmd = [self._uv_bin, "pip", "install"]
156157

158+
# Allow for explicit site directory location if needed
159+
target = os.environ.get("MARIMO_UV_TARGET", None)
160+
if target:
161+
install_cmd.append(f"--target={target}")
162+
157163
if upgrade:
158164
install_cmd.append("--upgrade")
159165

tests/_runtime/packages/test_pypi_package_manager.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,37 @@ async def test_uv_install_not_in_project(mock_run: MagicMock):
216216
assert result is True
217217

218218

219+
@patch("subprocess.run")
220+
@patch.object(UvPackageManager, "is_in_uv_project", False)
221+
async def test_uv_install_not_in_project_with_target(mock_run: MagicMock):
222+
"""Test UV install uses pip with target"""
223+
mock_run.return_value = MagicMock(returncode=0)
224+
mgr = UvPackageManager()
225+
226+
# Explicitly set environ, since patch doesn't work in an asynchronous
227+
# context.
228+
import os
229+
230+
os.environ["MARIMO_UV_TARGET"] = "target_path"
231+
result = await mgr._install("package1 package2", upgrade=False)
232+
del os.environ["MARIMO_UV_TARGET"]
233+
234+
mock_run.assert_called_once_with(
235+
[
236+
"uv",
237+
"pip",
238+
"install",
239+
"--target=target_path",
240+
"--compile",
241+
"package1",
242+
"package2",
243+
"-p",
244+
PY_EXE,
245+
],
246+
)
247+
assert result is True
248+
249+
219250
@patch("subprocess.run")
220251
@patch.object(UvPackageManager, "is_in_uv_project", True)
221252
async def test_uv_install_in_project(mock_run: MagicMock):

0 commit comments

Comments
 (0)