Skip to content

Commit 9de4bab

Browse files
committed
Use uv for Modal package overlays
1 parent d4f6b8f commit 9de4bab

3 files changed

Lines changed: 55 additions & 1 deletion

File tree

changelog.d/1531.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Use uv-compatible package overlays for Modal code-only worker deploys.

policyengine_household_api/modal_release/images.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def household_api_worker_image() -> modal.Image:
2323
)
2424
package_specs = country_package_install_specs()
2525
if package_specs:
26-
image = image.pip_install(*package_specs)
26+
image = image.uv_pip_install(*package_specs)
2727
return (
2828
image.add_local_python_source("policyengine_household_api", copy=True)
2929
.add_local_dir("config", remote_path="/app/config", copy=True)

tests/unit/modal_release/test_image_setup.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,59 @@
11
from policyengine_household_api.modal_release import _image_setup
22

33

4+
def test_worker_image_uses_uv_for_package_version_overlays(monkeypatch):
5+
from policyengine_household_api.modal_release import images
6+
7+
calls = []
8+
9+
class FakeImage:
10+
def uv_sync(self, *args, **kwargs):
11+
calls.append(("uv_sync", args, kwargs))
12+
return self
13+
14+
def uv_pip_install(self, *packages):
15+
calls.append(("uv_pip_install", packages, {}))
16+
return self
17+
18+
def pip_install(self, *packages):
19+
raise AssertionError(
20+
f"worker image should use uv_pip_install, got {packages}"
21+
)
22+
23+
def add_local_python_source(self, *args, **kwargs):
24+
calls.append(("add_local_python_source", args, kwargs))
25+
return self
26+
27+
def add_local_dir(self, *args, **kwargs):
28+
calls.append(("add_local_dir", args, kwargs))
29+
return self
30+
31+
def run_function(self, *args, **kwargs):
32+
calls.append(("run_function", args, kwargs))
33+
return self
34+
35+
def debian_slim(*args, **kwargs):
36+
calls.append(("debian_slim", args, kwargs))
37+
return FakeImage()
38+
39+
monkeypatch.setenv(
40+
images.PACKAGE_VERSIONS_ENV,
41+
'{"uk":"2.31.0","us":"1.691.1"}',
42+
)
43+
monkeypatch.setattr(images.modal.Image, "debian_slim", debian_slim)
44+
45+
images.household_api_worker_image()
46+
47+
assert (
48+
"uv_pip_install",
49+
(
50+
"policyengine_uk==2.31.0",
51+
"policyengine_us==1.691.1",
52+
),
53+
{},
54+
) in calls
55+
56+
457
def test_snapshot_tax_benefit_systems_preloads_all_country_packages(
558
monkeypatch,
659
):

0 commit comments

Comments
 (0)