|
1 | 1 | from e2b import ReadyCmd, Template, wait_for_url |
2 | 2 |
|
3 | 3 |
|
4 | | -# `--no-editable` builds `charts` (via uv's built-in `uv_build` backend) instead |
| 4 | +# The cache lives on the image disk, not /tmp (which `--no-cache` would use and |
| 5 | +# which is too small for the kernel packages), and is removed in the same step. |
| 6 | +# `--no-editable` builds `charts` with uv's built-in `uv_build` backend instead |
5 | 7 | # of linking the copied sources. |
6 | | -UV_SYNC_FLAGS = ( |
7 | | - "--locked --no-dev --no-editable --compile-bytecode --no-cache" |
8 | | - " --no-python-downloads" |
9 | | -) |
| 8 | +UV_CACHE_DIR = "/root/.cache/uv" |
| 9 | + |
| 10 | + |
| 11 | +def uv_sync(project: str, flags: str = "") -> str: |
| 12 | + return ( |
| 13 | + f"UV_CACHE_DIR={UV_CACHE_DIR} uv sync --project {project} --locked --no-dev" |
| 14 | + f" --no-editable --compile-bytecode --no-python-downloads{flags}" |
| 15 | + f" && rm -rf {UV_CACHE_DIR}" |
| 16 | + ) |
10 | 17 |
|
11 | 18 |
|
12 | 19 | def make_template( |
@@ -62,9 +69,11 @@ def make_template( |
62 | 69 | .copy(["pyproject.toml", "uv.lock"], ".python-env/") |
63 | 70 | .copy("charts", ".python-env/charts") |
64 | 71 | .run_cmd( |
65 | | - "UV_PROJECT_ENVIRONMENT=/usr/local uv sync --project .python-env" |
66 | | - f" {UV_SYNC_FLAGS} --inexact" |
67 | | - + (" --group bash" if "bash" in enabled_kernels else "") |
| 72 | + "UV_PROJECT_ENVIRONMENT=/usr/local " |
| 73 | + + uv_sync( |
| 74 | + ".python-env", |
| 75 | + " --inexact" + (" --group bash" if "bash" in enabled_kernels else ""), |
| 76 | + ) |
68 | 77 | ) |
69 | 78 | ) |
70 | 79 |
|
@@ -110,7 +119,7 @@ def make_template( |
110 | 119 | template = ( |
111 | 120 | template |
112 | 121 | # Create server virtual environment |
113 | | - .copy("server", ".server").run_cmd(f"uv sync --project .server {UV_SYNC_FLAGS}") |
| 122 | + .copy("server", ".server").run_cmd(uv_sync(".server")) |
114 | 123 | ) |
115 | 124 |
|
116 | 125 | # Copy configuration files |
|
0 commit comments