Skip to content

Require keywords for some auxiliary parameters #3046

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions modal/_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1129,6 +1129,7 @@ def from_name(
cls: type["_Function"],
app_name: str,
name: str,
*,
namespace=api_pb2.DEPLOYMENT_NAMESPACE_WORKSPACE,
environment_name: Optional[str] = None,
) -> "_Function":
Expand Down
2 changes: 2 additions & 0 deletions modal/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ def description(self) -> Optional[str]:
@renamed_parameter((2024, 12, 18), "label", "name")
async def lookup(
name: str,
*,
client: Optional[_Client] = None,
environment_name: Optional[str] = None,
create_if_missing: bool = False,
Expand Down Expand Up @@ -327,6 +328,7 @@ async def _set_local_app(self, client: _Client, running_app: RunningApp) -> Asyn
@asynccontextmanager
async def run(
self,
*,
client: Optional[_Client] = None,
show_progress: Optional[bool] = None,
detach: bool = False,
Expand Down
2 changes: 2 additions & 0 deletions modal/cls.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,7 @@ def from_name(
cls: type["_Cls"],
app_name: str,
name: str,
*,
namespace=api_pb2.DEPLOYMENT_NAMESPACE_WORKSPACE,
environment_name: Optional[str] = None,
workspace: Optional[str] = None, # Deprecated and unused
Expand Down Expand Up @@ -601,6 +602,7 @@ async def _load_remote(self: _Cls, resolver: Resolver, existing_object_id: Optio
@warn_on_renamed_autoscaler_settings
def with_options(
self: "_Cls",
*,
cpu: Optional[Union[float, tuple[float, float]]] = None,
memory: Optional[Union[int, tuple[int, int]]] = None,
gpu: GPU_T = None,
Expand Down
1 change: 1 addition & 0 deletions modal/dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ async def ephemeral(
def from_name(
name: str,
data: Optional[dict] = None,
*,
namespace=api_pb2.DEPLOYMENT_NAMESPACE_WORKSPACE,
environment_name: Optional[str] = None,
create_if_missing: bool = False,
Expand Down
1 change: 1 addition & 0 deletions modal/environments.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def _hydrate_metadata(self, metadata: Message):
@renamed_parameter((2024, 12, 18), "label", "name")
def from_name(
name: str,
*,
create_if_missing: bool = False,
):
if name:
Expand Down
27 changes: 10 additions & 17 deletions modal/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -1236,20 +1236,17 @@ def build_dockerfile(version: ImageBuilderVersion) -> DockerfileSpec:
def poetry_install_from_file(
self,
poetry_pyproject_toml: str,
# Path to the lockfile. If not provided, uses poetry.lock in the same directory.
poetry_lockfile: Optional[str] = None,
# If set to True, it will not use poetry.lock
ignore_lockfile: bool = False,
poetry_lockfile: Optional[str] = None, # Path to lockfile. If not provided, uses poetry.lock in same directory.
*,
ignore_lockfile: bool = False, # If set to True, do not use poetry.lock, even when present
# If set to True, use old installer. See https://github.com/python-poetry/poetry/issues/3336
old_installer: bool = False,
force_build: bool = False, # Ignore cached builds, similar to 'docker build --no-cache'
# Selected optional dependency groups to install (See https://python-poetry.org/docs/cli/#install)
with_: list[str] = [],
# Selected optional dependency groups to exclude (See https://python-poetry.org/docs/cli/#install)
without: list[str] = [],
# Only install dependency groups specifed in this list.
only: list[str] = [],
*,
only: list[str] = [], # Only install dependency groups specifed in this list.
secrets: Sequence[_Secret] = [],
gpu: GPU_T = None,
) -> "_Image":
Expand Down Expand Up @@ -1556,8 +1553,8 @@ def _registry_setup_commands(
@staticmethod
def from_registry(
tag: str,
*,
secret: Optional[_Secret] = None,
*,
setup_dockerfile_commands: list[str] = [],
force_build: bool = False, # Ignore cached builds, similar to 'docker build --no-cache'
add_python: Optional[str] = None,
Expand Down Expand Up @@ -1714,12 +1711,10 @@ def from_aws_ecr(

@staticmethod
def from_dockerfile(
# Filepath to Dockerfile.
path: Union[str, Path],
context_mount: Optional[_Mount] = None, # Deprecated: the context is now inferred
# Ignore cached builds, similar to 'docker build --no-cache'
force_build: bool = False,
path: Union[str, Path], # Filepath to Dockerfile.
*,
context_mount: Optional[_Mount] = None, # Deprecated: the context is now inferred
force_build: bool = False, # Ignore cached builds, similar to 'docker build --no-cache'
context_dir: Optional[Union[Path, str]] = None, # Context for relative COPY commands
secrets: Sequence[_Secret] = [],
gpu: GPU_T = None,
Expand Down Expand Up @@ -1901,10 +1896,9 @@ def build_dockerfile(version: ImageBuilderVersion) -> DockerfileSpec:
def run_function(
self,
raw_f: Callable[..., Any],
*,
secrets: Sequence[_Secret] = (), # Optional Modal Secret objects with environment variables for the container
gpu: Union[
GPU_T, list[GPU_T]
] = None, # GPU request as string ("any", "T4", ...), object (`modal.GPU.A100()`, ...), or a list of either
gpu: Union[GPU_T, list[GPU_T]] = None, # Requested GPU or or list of acceptable GPUs( e.g. ["A10", "A100"])
mounts: Sequence[_Mount] = (), # Mounts attached to the function
volumes: dict[Union[str, PurePosixPath], Union[_Volume, _CloudBucketMount]] = {}, # Volume mount paths
network_file_systems: dict[Union[str, PurePosixPath], _NetworkFileSystem] = {}, # NFS mount paths
Expand All @@ -1916,7 +1910,6 @@ def run_function(
region: Optional[Union[str, Sequence[str]]] = None, # Region or regions to run the function on.
args: Sequence[Any] = (), # Positional arguments to the function.
kwargs: dict[str, Any] = {}, # Keyword arguments to the function.
*,
include_source: Optional[bool] = None,
) -> "_Image":
"""Run user-defined function `raw_f` as an image build step. The function runs just like an ordinary Modal
Expand Down
1 change: 1 addition & 0 deletions modal/mount.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,7 @@ def converted_condition(path: Path) -> bool:
@renamed_parameter((2024, 12, 18), "label", "name")
def from_name(
name: str,
*,
namespace=api_pb2.DEPLOYMENT_NAMESPACE_WORKSPACE,
environment_name: Optional[str] = None,
) -> "_Mount":
Expand Down
1 change: 1 addition & 0 deletions modal/network_file_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def g():
@renamed_parameter((2024, 12, 18), "label", "name")
def from_name(
name: str,
*,
namespace=api_pb2.DEPLOYMENT_NAMESPACE_WORKSPACE,
environment_name: Optional[str] = None,
create_if_missing: bool = False,
Expand Down
2 changes: 2 additions & 0 deletions modal/parallel_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ async def _for_each_async(self, *input_iterators, kwargs={}, ignore_exceptions:
async def _starmap_async(
self,
input_iterator: typing.Union[typing.Iterable[typing.Sequence[Any]], typing.AsyncIterable[typing.Sequence[Any]]],
*,
kwargs={},
order_outputs: bool = True,
return_exceptions: bool = False,
Expand All @@ -529,6 +530,7 @@ async def feed_queue():
def _starmap_sync(
self,
input_iterator: typing.Iterable[typing.Sequence[Any]],
*,
kwargs={},
order_outputs: bool = True,
return_exceptions: bool = False,
Expand Down
1 change: 1 addition & 0 deletions modal/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class _Proxy(_Object, type_prefix="pr"):
@staticmethod
def from_name(
name: str,
*,
environment_name: Optional[str] = None,
) -> "_Proxy":
"""Reference a Proxy by its name.
Expand Down
1 change: 1 addition & 0 deletions modal/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ async def ephemeral(
@renamed_parameter((2024, 12, 18), "label", "name")
def from_name(
name: str,
*,
namespace=api_pb2.DEPLOYMENT_NAMESPACE_WORKSPACE,
environment_name: Optional[str] = None,
create_if_missing: bool = False,
Expand Down
1 change: 1 addition & 0 deletions modal/schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def f():

def __init__(
self,
*,
years: int = 0,
months: int = 0,
weeks: int = 0,
Expand Down
1 change: 1 addition & 0 deletions modal/secret.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ async def _load(self: _Secret, resolver: Resolver, existing_object_id: Optional[
@renamed_parameter((2024, 12, 18), "label", "name")
def from_name(
name: str,
*,
namespace=api_pb2.DEPLOYMENT_NAMESPACE_WORKSPACE,
environment_name: Optional[str] = None,
required_keys: list[
Expand Down
1 change: 1 addition & 0 deletions modal/volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ async def _get_lock(self):
@renamed_parameter((2024, 12, 18), "label", "name")
def from_name(
name: str,
*,
namespace=api_pb2.DEPLOYMENT_NAMESPACE_WORKSPACE,
environment_name: Optional[str] = None,
create_if_missing: bool = False,
Expand Down
2 changes: 1 addition & 1 deletion test/cli_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,7 @@ async def stalling_function_get_output(servicer, req):
@pytest.fixture
def app(client):
app = App()
with app.run(client):
with app.run(client=client):
yield app


Expand Down
4 changes: 2 additions & 2 deletions test/image_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,15 @@ def test_python_version(builder_version, servicer, client, python_version):
expected_dockerhub_python = _dockerhub_python_version(builder_version, expected_python)
expected_dockerhub_debian = _base_image_config("debian", builder_version)
assert expected_dockerhub_python.startswith(expected_python)
with app.run(client):
with app.run(client=client):
commands = get_all_dockerfile_commands(image.object_id, servicer)
assert re.match(rf"FROM python:{expected_dockerhub_python}-slim-{expected_dockerhub_debian}", commands)

image = Image.micromamba() if python_version is None else Image.micromamba(python_version)
app.function(image=image)(dummy)
if python_version is None and builder_version == "2023.12":
expected_python = "3.9"
with app.run(client):
with app.run(client=client):
commands = get_all_dockerfile_commands(image.object_id, servicer)
assert re.search(rf"install.* python={expected_python}", commands)

Expand Down
6 changes: 3 additions & 3 deletions test/sandbox_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
@pytest.fixture
def app(client):
app = App()
with app.run(client):
with app.run(client=client):
yield app


Expand Down Expand Up @@ -269,7 +269,7 @@ def test_app_sandbox(client, servicer):
Sandbox.create("bash", "-c", "echo bye >&2 && echo hi", image=image, secrets=[secret])

app = App()
with app.run(client):
with app.run(client=client):
# Create sandbox
with pytest.raises(DeprecationError, match="`App.spawn_sandbox` is deprecated"):
app.spawn_sandbox("bash", "-c", "echo bye >&2 && echo hi", image=image, secrets=[secret])
Expand Down Expand Up @@ -350,7 +350,7 @@ def test_sandbox_list_app(client, servicer):

app = App()

with app.run(client):
with app.run(client=client):
# Create sandbox
sb = Sandbox.create("bash", "-c", "sleep 10000", image=image, secrets=[secret], app=app)
assert len(list(Sandbox.list(app_id=app.app_id, client=client))) == 1
Expand Down
2 changes: 1 addition & 1 deletion test/scheduler_placement_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def test_fn_scheduler_placement(servicer, client):

@skip_windows("needs subprocess")
def test_sandbox_scheduler_placement(client, servicer):
with app.run(client):
with app.run(client=client):
Sandbox.create(
"bash",
"-c",
Expand Down
Loading