Skip to content

Commit

Permalink
Back to add
Browse files Browse the repository at this point in the history
  • Loading branch information
freider committed Nov 19, 2024
1 parent 1e1bc97 commit 286db82
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions modal/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ def _assert_no_mount_layers(self):
my_image = (
Image.debian_slim()
.attach_local_python_packages("mypak", copy=True)
.add_local_python_packages("mypak", copy=True)
.run_commands("python -m mypak") # this now works!
)
"""
Expand Down Expand Up @@ -624,7 +624,7 @@ def build_dockerfile(version: ImageBuilderVersion) -> DockerfileSpec:
context_mount=mount,
)

def attach_local_python_packages(self, *packages: Union[str, Path], copy: bool = False) -> "_Image":
def add_local_python_packages(self, *packages: Union[str, Path], copy: bool = False) -> "_Image":
"""Attaches local Python packages to the container running the image
Packages are added to the /root directory which is on the PYTHONPATH of any
Expand Down
18 changes: 9 additions & 9 deletions test/image_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1228,13 +1228,13 @@ def hydrate_image(img, client):

def test_attach_local_lazy_vs_copy(client, servicer, set_env_client, supports_on_path):
deb = Image.debian_slim()
image_with_mount = deb.attach_local_python_packages("pkg_a")
image_with_mount = deb.add_local_python_packages("pkg_a")

hydrate_image(image_with_mount, client)
assert image_with_mount.object_id == deb.object_id
assert len(image_with_mount._mount_layers) == 1

image_additional_mount = image_with_mount.attach_local_python_packages("pkg_b")
image_additional_mount = image_with_mount.add_local_python_packages("pkg_b")
hydrate_image(image_additional_mount, client)
assert len(image_additional_mount._mount_layers) == 2 # another mount added to lazy layer
assert len(image_with_mount._mount_layers) == 1 # original image should not be affected
Expand All @@ -1245,12 +1245,12 @@ def test_attach_local_lazy_vs_copy(client, servicer, set_env_client, supports_on
# error about using non-copy add commands before other build steps
hydrate_image(image_non_mount, client)

image_with_copy = deb.attach_local_python_packages("pkg_a", copy=True)
image_with_copy = deb.add_local_python_packages("pkg_a", copy=True)
hydrate_image(image_with_copy, client)
assert len(image_with_copy._mount_layers) == 0

# do the same exact image using copy=True
image_with_copy_and_commands = deb.attach_local_python_packages("pkg_a", copy=True).run_commands("echo 'hello'")
image_with_copy_and_commands = deb.add_local_python_packages("pkg_a", copy=True).run_commands("echo 'hello'")
hydrate_image(image_with_copy_and_commands, client)
assert len(image_with_copy_and_commands._mount_layers) == 0

Expand All @@ -1268,7 +1268,7 @@ def test_attach_local_lazy_vs_copy(client, servicer, set_env_client, supports_on

def test_attach_locals_are_attached_to_functions(servicer, client, supports_on_path):
deb_slim = Image.debian_slim()
img = deb_slim.attach_local_python_packages("pkg_a")
img = deb_slim.add_local_python_packages("pkg_a")
app = App("my-app")
control_fun: modal.Function = app.function(serialized=True, image=deb_slim, name="control")(
dummy
Expand All @@ -1285,7 +1285,7 @@ def test_attach_locals_are_attached_to_functions(servicer, client, supports_on_p

def test_attach_locals_are_attached_to_classes(servicer, client, supports_on_path, set_env_client):
deb_slim = Image.debian_slim()
img = deb_slim.attach_local_python_packages("pkg_a")
img = deb_slim.add_local_python_packages("pkg_a")
app = App("my-app")
control_fun: modal.Function = app.function(serialized=True, image=deb_slim, name="control")(
dummy
Expand Down Expand Up @@ -1316,7 +1316,7 @@ class A:
@skip_windows("servicer sandbox implementation not working on windows")
def test_attach_locals_are_attached_to_sandboxes(servicer, client, supports_on_path):
deb_slim = Image.debian_slim()
img = deb_slim.attach_local_python_packages("pkg_a")
img = deb_slim.add_local_python_packages("pkg_a")
app = App("my-app")
with app.run(client=client):
modal.Sandbox.create(image=img, app=app, client=client)
Expand All @@ -1335,15 +1335,15 @@ def empty_fun():

def test_attach_locals_build_function(servicer, client, supports_on_path):
deb_slim = Image.debian_slim()
img = deb_slim.attach_local_python_packages("pkg_a")
img = deb_slim.add_local_python_packages("pkg_a")
img_with_build_function = img.run_function(empty_fun)
with pytest.raises(InvalidError):
# build functions could still potentially rewrite mount contents,
# so we still require them to use copy=True
# TODO(elias): what if someone wants do use an equivalent of `run_function(..., mounts=[...]) ?
hydrate_image(img_with_build_function, client)

img_with_copy = deb_slim.attach_local_python_packages("pkg_a", copy=True)
img_with_copy = deb_slim.add_local_python_packages("pkg_a", copy=True)
hydrate_image(img_with_copy, client) # this is fine


Expand Down
2 changes: 1 addition & 1 deletion test/watcher_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def dummy():

def test_add_local_mount_included_in_serve_watchers(servicer, client, supports_on_path, disable_auto_mount):
deb_slim = modal.Image.debian_slim()
img = deb_slim.attach_local_python_packages("pkg_a")
img = deb_slim.add_local_python_packages("pkg_a")
app = modal.App()

@app.function(serialized=True, image=img)
Expand Down

0 comments on commit 286db82

Please sign in to comment.