Skip to content

Commit

Permalink
Adds test etc
Browse files Browse the repository at this point in the history
  • Loading branch information
freider committed Jan 10, 2025
1 parent 631fd54 commit a887cf1
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 3 deletions.
6 changes: 3 additions & 3 deletions modal/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,9 +512,9 @@ def from_local(
if warn_missing_modules:
python_stringified_modules = ", ".join(f'"{mod}"' for mod in sorted(warn_missing_modules))
deprecation_warning(
(2024, 12, 16),
(2024, 1, 10),
(
"Automatic mounting of imported python packages will be deprecated in the future.\n"
"Automatic adding of local python source will be deprecated in the future.\n"
f"Make sure you have explicitly added the source for the following modules to the image "
f"used by `{info.function_name}`:\n"
)
Expand All @@ -525,7 +525,7 @@ def from_local(
f"image.add_local_python_source({python_stringified_modules})\n\n"
"If you have added the packages by this or other means and you want to get rid of this "
"warning, you can set\n"
"@app.function(..., automount=False)\n"
"@app.function(..., autoadd_local_source=False)\n"
"\n"
"This will become the default in the future."
),
Expand Down
9 changes: 9 additions & 0 deletions modal/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,15 @@ async def _load(self: _Image, resolver: Resolver, existing_object_id: Optional[s
img.force_build = force_build
return img

def _extend(self, **kwargs) -> "_Image":
"""Internal use only - helper method to create a new Image with self as base
Transfers required static attributes to the new layer as expected.
"""
img = _Image._from_args(base_images={"base": self}, **kwargs)
img._added_python_source_set = self._added_python_source_set
return img

def copy_mount(self, mount: _Mount, remote_path: Union[str, Path] = ".") -> "_Image":
"""Copy the entire contents of a `modal.Mount` into an image.
Useful when files only available locally are required during the image
Expand Down
30 changes: 30 additions & 0 deletions test/mount_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import os
import platform
import pytest
import re
from pathlib import Path, PurePosixPath
from test.helpers import deploy_app_externally

from modal import App, FilePatternMatcher
from modal._utils.blob_utils import LARGE_FILE_LIMIT
Expand Down Expand Up @@ -198,3 +200,31 @@ def test_mount_from_local_dir_ignore(test_dir, tmp_path_with_content):

file_names = [file.mount_filename for file in Mount._get_files(entries=mount.entries)]
assert set(file_names) == expected


def test_missing_python_source_warning(servicer, credentials, supports_dir):
# should warn if function doesn't have an imported non-third-party package attached
# either through add OR copy mode, unless automount=False mode is used
def has_warning(output: str):
return re.match(r".*added the source for the following modules.*:\npkg_d\n.*", output, re.DOTALL)

output = deploy_app_externally(servicer, credentials, "pkg_d.main", cwd=supports_dir, capture_output=True)
assert has_warning(output)

# adding the source to the image should make the warning disappear
output = deploy_app_externally(
servicer, credentials, "pkg_d.main", cwd=supports_dir, capture_output=True, env={"ADD_SOURCE": "add"}
)
assert not has_warning(output)

# copying the source to the image should make the warning disappear
output = deploy_app_externally(
servicer, credentials, "pkg_d.main", cwd=supports_dir, capture_output=True, env={"ADD_SOURCE": "copy"}
)
assert not has_warning(output)

# disabling auto-mount explicitly should make warning disappear
output = deploy_app_externally(
servicer, credentials, "pkg_d.main", cwd=supports_dir, capture_output=True, env={"MODAL_AUTOMOUNT": "0"}
)
assert not has_warning(output)
Empty file added test/supports/pkg_d/__init__.py
Empty file.
20 changes: 20 additions & 0 deletions test/supports/pkg_d/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import os

import modal

from . import sibling # noqa # warn if sibling source isn't attached

app = modal.App()

image = modal.Image.debian_slim()

if os.environ.get("ADD_SOURCE") == "add":
image = image.add_local_python_source("pkg_d")

elif os.environ.get("ADD_SOURCE") == "copy":
image = image.add_local_python_source("pkg_d", copy=True)


@app.function(image=image)
def f():
pass
Empty file added test/supports/pkg_d/sibling.py
Empty file.

0 comments on commit a887cf1

Please sign in to comment.