modal 1.0.6.dev32__py3-none-any.whl → 1.0.6.dev35__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of modal might be problematic. Click here for more details.
- modal/_functions.py +8 -6
- modal/_utils/auth_token_manager.py +114 -0
- modal/_utils/grpc_utils.py +0 -14
- modal/app.py +20 -4
- modal/app.pyi +40 -8
- modal/client.py +5 -1
- modal/client.pyi +5 -2
- modal/experimental/__init__.py +47 -1
- modal/sandbox.py +3 -1
- {modal-1.0.6.dev32.dist-info → modal-1.0.6.dev35.dist-info}/METADATA +1 -1
- {modal-1.0.6.dev32.dist-info → modal-1.0.6.dev35.dist-info}/RECORD +16 -15
- modal_version/__init__.py +1 -1
- {modal-1.0.6.dev32.dist-info → modal-1.0.6.dev35.dist-info}/WHEEL +0 -0
- {modal-1.0.6.dev32.dist-info → modal-1.0.6.dev35.dist-info}/entry_points.txt +0 -0
- {modal-1.0.6.dev32.dist-info → modal-1.0.6.dev35.dist-info}/licenses/LICENSE +0 -0
- {modal-1.0.6.dev32.dist-info → modal-1.0.6.dev35.dist-info}/top_level.txt +0 -0
modal/_functions.py
CHANGED
|
@@ -401,9 +401,7 @@ class _InputPlaneInvocation:
|
|
|
401
401
|
parent_input_id=current_input_id() or "",
|
|
402
402
|
input=input_item,
|
|
403
403
|
)
|
|
404
|
-
metadata
|
|
405
|
-
if input_plane_region and input_plane_region != "":
|
|
406
|
-
metadata.append(("x-modal-input-plane-region", input_plane_region))
|
|
404
|
+
metadata = await _InputPlaneInvocation._get_metadata(input_plane_region, client)
|
|
407
405
|
response = await retry_transient_errors(stub.AttemptStart, request, metadata=metadata)
|
|
408
406
|
attempt_token = response.attempt_token
|
|
409
407
|
|
|
@@ -419,9 +417,7 @@ class _InputPlaneInvocation:
|
|
|
419
417
|
timeout_secs=OUTPUTS_TIMEOUT,
|
|
420
418
|
requested_at=time.time(),
|
|
421
419
|
)
|
|
422
|
-
metadata
|
|
423
|
-
if self.input_plane_region and self.input_plane_region != "":
|
|
424
|
-
metadata.append(("x-modal-input-plane-region", self.input_plane_region))
|
|
420
|
+
metadata = await self._get_metadata(self.input_plane_region, self.client)
|
|
425
421
|
await_response: api_pb2.AttemptAwaitResponse = await retry_transient_errors(
|
|
426
422
|
self.stub.AttemptAwait,
|
|
427
423
|
await_request,
|
|
@@ -457,6 +453,12 @@ class _InputPlaneInvocation:
|
|
|
457
453
|
await_response.output.result, await_response.output.data_format, control_plane_stub, self.client
|
|
458
454
|
)
|
|
459
455
|
|
|
456
|
+
@staticmethod
|
|
457
|
+
async def _get_metadata(input_plane_region: str, client: _Client) -> list[tuple[str, str]]:
|
|
458
|
+
if not input_plane_region:
|
|
459
|
+
return []
|
|
460
|
+
token = await client._auth_token_manager.get_token()
|
|
461
|
+
return [("x-modal-input-plane-region", input_plane_region), ("x-modal-auth-token", token)]
|
|
460
462
|
|
|
461
463
|
# Wrapper type for api_pb2.FunctionStats
|
|
462
464
|
@dataclass(frozen=True)
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
# Copyright Modal Labs 2025
|
|
2
|
+
import asyncio
|
|
3
|
+
import base64
|
|
4
|
+
import json
|
|
5
|
+
import time
|
|
6
|
+
import typing
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
from modal.exception import ExecutionError
|
|
10
|
+
from modal_proto import api_pb2, modal_api_grpc
|
|
11
|
+
|
|
12
|
+
from .grpc_utils import retry_transient_errors
|
|
13
|
+
from .logger import logger
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class _AuthTokenManager:
|
|
17
|
+
"""Handles fetching and refreshing of the input plane auth token."""
|
|
18
|
+
|
|
19
|
+
# Start refreshing this many seconds before the token expires
|
|
20
|
+
REFRESH_WINDOW = 5 * 60
|
|
21
|
+
# If the token doesn't have an expiry field, default to current time plus this value (not expected).
|
|
22
|
+
DEFAULT_EXPIRY_OFFSET = 20 * 60
|
|
23
|
+
|
|
24
|
+
def __init__(self, stub: "modal_api_grpc.ModalClientModal"):
|
|
25
|
+
self._stub = stub
|
|
26
|
+
self._token = ""
|
|
27
|
+
self._expiry = 0.0
|
|
28
|
+
self._lock: typing.Union[asyncio.Lock, None] = None
|
|
29
|
+
|
|
30
|
+
async def get_token(self):
|
|
31
|
+
"""
|
|
32
|
+
When called, the AuthTokenManager can be in one of three states:
|
|
33
|
+
1. Has a valid cached token. It is returned to the caller.
|
|
34
|
+
2. Has no cached token, or the token is expired. We fetch a new one and cache it. If `get_token` is called
|
|
35
|
+
concurrently by multiple coroutines, all requests will block until the token has been fetched. But only one
|
|
36
|
+
coroutine will actually make a request to the control plane to fetch the new token. This ensures we do not hit
|
|
37
|
+
the control plane with more requests than needed.
|
|
38
|
+
3. Has a valid cached token, but it is going to expire in the next 5 minutes. In this case we fetch a new token
|
|
39
|
+
and cache it. If `get_token` is called concurrently, only one request will fetch the new token, and the others
|
|
40
|
+
will be given the old (but still valid) token - i.e. they will not block.
|
|
41
|
+
"""
|
|
42
|
+
if not self._token or self._is_expired():
|
|
43
|
+
# We either have no token or it is expired - block everyone until we get a new token
|
|
44
|
+
await self._refresh_token()
|
|
45
|
+
elif self._needs_refresh():
|
|
46
|
+
# The token hasn't expired yet, but will soon, so it needs a refresh.
|
|
47
|
+
lock = await self._get_lock()
|
|
48
|
+
if lock.locked():
|
|
49
|
+
# The lock is taken, so someone else is refreshing. Continue to use the old token.
|
|
50
|
+
return self._token
|
|
51
|
+
else:
|
|
52
|
+
# The lock is not taken, so we need to fetch a new token.
|
|
53
|
+
await self._refresh_token()
|
|
54
|
+
|
|
55
|
+
return self._token
|
|
56
|
+
|
|
57
|
+
async def _refresh_token(self):
|
|
58
|
+
"""
|
|
59
|
+
Fetch a new token from the control plane. If called concurrently, only one coroutine will make a request for a
|
|
60
|
+
new token. The others will block on a lock, until the first coroutine has fetched the new token.
|
|
61
|
+
"""
|
|
62
|
+
lock = await self._get_lock()
|
|
63
|
+
async with lock:
|
|
64
|
+
# Double check inside lock - maybe another coroutine refreshed already. This happens the first time we fetch
|
|
65
|
+
# the token. The first coroutine will fetch the token, while the others block on the lock, waiting for the
|
|
66
|
+
# new token. Once we have a new token, the other coroutines will unblock and return from here.
|
|
67
|
+
if self._token and not self._needs_refresh():
|
|
68
|
+
return
|
|
69
|
+
resp: api_pb2.AuthTokenGetResponse = await retry_transient_errors(
|
|
70
|
+
self._stub.AuthTokenGet, api_pb2.AuthTokenGetRequest()
|
|
71
|
+
)
|
|
72
|
+
if not resp.token:
|
|
73
|
+
# Not expected
|
|
74
|
+
raise ExecutionError(
|
|
75
|
+
"Internal error: Did not receive auth token from server. Please contact Modal support."
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
self._token = resp.token
|
|
79
|
+
if exp := self._decode_jwt(resp.token).get("exp"):
|
|
80
|
+
self._expiry = float(exp)
|
|
81
|
+
else:
|
|
82
|
+
# This should never happen.
|
|
83
|
+
logger.warning("x-modal-auth-token does not contain exp field")
|
|
84
|
+
# We'll use the token, and set the expiry to 20 min from now.
|
|
85
|
+
self._expiry = time.time() + self.DEFAULT_EXPIRY_OFFSET
|
|
86
|
+
|
|
87
|
+
async def _get_lock(self) -> asyncio.Lock:
|
|
88
|
+
# Note: this function runs no async code but is marked as async to ensure it's
|
|
89
|
+
# being run inside the synchronicity event loop and binds the lock to the
|
|
90
|
+
# correct event loop on Python 3.9 which eagerly assigns event loops on
|
|
91
|
+
# constructions of locks
|
|
92
|
+
if self._lock is None:
|
|
93
|
+
self._lock = asyncio.Lock()
|
|
94
|
+
return self._lock
|
|
95
|
+
|
|
96
|
+
@staticmethod
|
|
97
|
+
def _decode_jwt(token: str) -> dict[str, Any]:
|
|
98
|
+
"""
|
|
99
|
+
Decodes a JWT into a dict without verifying signature. We do this manually instead of using a library to avoid
|
|
100
|
+
adding another dependency to the client.
|
|
101
|
+
"""
|
|
102
|
+
try:
|
|
103
|
+
payload = token.split(".")[1]
|
|
104
|
+
padding = "=" * (-len(payload) % 4)
|
|
105
|
+
decoded_bytes = base64.urlsafe_b64decode(payload + padding)
|
|
106
|
+
return json.loads(decoded_bytes)
|
|
107
|
+
except Exception as e:
|
|
108
|
+
raise ValueError("Internal error: Cannot parse auth token. Please contact Modal support.") from e
|
|
109
|
+
|
|
110
|
+
def _needs_refresh(self):
|
|
111
|
+
return time.time() >= (self._expiry - self.REFRESH_WINDOW)
|
|
112
|
+
|
|
113
|
+
def _is_expired(self):
|
|
114
|
+
return time.time() >= self._expiry
|
modal/_utils/grpc_utils.py
CHANGED
|
@@ -149,21 +149,7 @@ def create_channel(
|
|
|
149
149
|
|
|
150
150
|
logger.debug(f"Sending request to {event.method_name}")
|
|
151
151
|
|
|
152
|
-
async def recv_initial_metadata(initial_metadata: grpclib.events.RecvInitialMetadata) -> None:
|
|
153
|
-
# If we receive an auth token from the server, include it in all future requests.
|
|
154
|
-
# TODO(nathan): This isn't perfect because the metadata isn't propagated when the
|
|
155
|
-
# process is forked and a new channel is created. This is OK for now since this
|
|
156
|
-
# token is only used by the experimental input plane
|
|
157
|
-
if token := initial_metadata.metadata.get("x-modal-auth-token"):
|
|
158
|
-
metadata["x-modal-auth-token"] = str(token)
|
|
159
|
-
|
|
160
|
-
async def recv_trailing_metadata(trailing_metadata: grpclib.events.RecvTrailingMetadata) -> None:
|
|
161
|
-
if token := trailing_metadata.metadata.get("x-modal-auth-token"):
|
|
162
|
-
metadata["x-modal-auth-token"] = str(token)
|
|
163
|
-
|
|
164
152
|
grpclib.events.listen(channel, grpclib.events.SendRequest, send_request)
|
|
165
|
-
grpclib.events.listen(channel, grpclib.events.RecvInitialMetadata, recv_initial_metadata)
|
|
166
|
-
grpclib.events.listen(channel, grpclib.events.RecvTrailingMetadata, recv_trailing_metadata)
|
|
167
153
|
|
|
168
154
|
return channel
|
|
169
155
|
|
modal/app.py
CHANGED
|
@@ -508,22 +508,38 @@ class _App:
|
|
|
508
508
|
|
|
509
509
|
@property
|
|
510
510
|
def registered_functions(self) -> dict[str, _Function]:
|
|
511
|
-
"""All modal.Function objects registered on the app.
|
|
511
|
+
"""All modal.Function objects registered on the app.
|
|
512
|
+
|
|
513
|
+
Note: this property is populated only during the build phase, and it is not
|
|
514
|
+
expected to work when a deplyoed App has been retrieved via `modal.App.lookup`.
|
|
515
|
+
"""
|
|
512
516
|
return self._functions
|
|
513
517
|
|
|
514
518
|
@property
|
|
515
519
|
def registered_classes(self) -> dict[str, _Cls]:
|
|
516
|
-
"""All modal.Cls objects registered on the app.
|
|
520
|
+
"""All modal.Cls objects registered on the app.
|
|
521
|
+
|
|
522
|
+
Note: this property is populated only during the build phase, and it is not
|
|
523
|
+
expected to work when a deplyoed App has been retrieved via `modal.App.lookup`.
|
|
524
|
+
"""
|
|
517
525
|
return self._classes
|
|
518
526
|
|
|
519
527
|
@property
|
|
520
528
|
def registered_entrypoints(self) -> dict[str, _LocalEntrypoint]:
|
|
521
|
-
"""All local CLI entrypoints registered on the app.
|
|
529
|
+
"""All local CLI entrypoints registered on the app.
|
|
530
|
+
|
|
531
|
+
Note: this property is populated only during the build phase, and it is not
|
|
532
|
+
expected to work when a deplyoed App has been retrieved via `modal.App.lookup`.
|
|
533
|
+
"""
|
|
522
534
|
return self._local_entrypoints
|
|
523
535
|
|
|
524
536
|
@property
|
|
525
537
|
def registered_web_endpoints(self) -> list[str]:
|
|
526
|
-
"""Names of web endpoint (ie. webhook) functions registered on the app.
|
|
538
|
+
"""Names of web endpoint (ie. webhook) functions registered on the app.
|
|
539
|
+
|
|
540
|
+
Note: this property is populated only during the build phase, and it is not
|
|
541
|
+
expected to work when a deplyoed App has been retrieved via `modal.App.lookup`.
|
|
542
|
+
"""
|
|
527
543
|
return self._web_endpoints
|
|
528
544
|
|
|
529
545
|
def local_entrypoint(
|
modal/app.pyi
CHANGED
|
@@ -299,22 +299,38 @@ class _App:
|
|
|
299
299
|
def _init_container(self, client: modal.client._Client, running_app: modal.running_app.RunningApp): ...
|
|
300
300
|
@property
|
|
301
301
|
def registered_functions(self) -> dict[str, modal._functions._Function]:
|
|
302
|
-
"""All modal.Function objects registered on the app.
|
|
302
|
+
"""All modal.Function objects registered on the app.
|
|
303
|
+
|
|
304
|
+
Note: this property is populated only during the build phase, and it is not
|
|
305
|
+
expected to work when a deplyoed App has been retrieved via `modal.App.lookup`.
|
|
306
|
+
"""
|
|
303
307
|
...
|
|
304
308
|
|
|
305
309
|
@property
|
|
306
310
|
def registered_classes(self) -> dict[str, modal.cls._Cls]:
|
|
307
|
-
"""All modal.Cls objects registered on the app.
|
|
311
|
+
"""All modal.Cls objects registered on the app.
|
|
312
|
+
|
|
313
|
+
Note: this property is populated only during the build phase, and it is not
|
|
314
|
+
expected to work when a deplyoed App has been retrieved via `modal.App.lookup`.
|
|
315
|
+
"""
|
|
308
316
|
...
|
|
309
317
|
|
|
310
318
|
@property
|
|
311
319
|
def registered_entrypoints(self) -> dict[str, _LocalEntrypoint]:
|
|
312
|
-
"""All local CLI entrypoints registered on the app.
|
|
320
|
+
"""All local CLI entrypoints registered on the app.
|
|
321
|
+
|
|
322
|
+
Note: this property is populated only during the build phase, and it is not
|
|
323
|
+
expected to work when a deplyoed App has been retrieved via `modal.App.lookup`.
|
|
324
|
+
"""
|
|
313
325
|
...
|
|
314
326
|
|
|
315
327
|
@property
|
|
316
328
|
def registered_web_endpoints(self) -> list[str]:
|
|
317
|
-
"""Names of web endpoint (ie. webhook) functions registered on the app.
|
|
329
|
+
"""Names of web endpoint (ie. webhook) functions registered on the app.
|
|
330
|
+
|
|
331
|
+
Note: this property is populated only during the build phase, and it is not
|
|
332
|
+
expected to work when a deplyoed App has been retrieved via `modal.App.lookup`.
|
|
333
|
+
"""
|
|
318
334
|
...
|
|
319
335
|
|
|
320
336
|
def local_entrypoint(
|
|
@@ -888,22 +904,38 @@ class App:
|
|
|
888
904
|
def _init_container(self, client: modal.client.Client, running_app: modal.running_app.RunningApp): ...
|
|
889
905
|
@property
|
|
890
906
|
def registered_functions(self) -> dict[str, modal.functions.Function]:
|
|
891
|
-
"""All modal.Function objects registered on the app.
|
|
907
|
+
"""All modal.Function objects registered on the app.
|
|
908
|
+
|
|
909
|
+
Note: this property is populated only during the build phase, and it is not
|
|
910
|
+
expected to work when a deplyoed App has been retrieved via `modal.App.lookup`.
|
|
911
|
+
"""
|
|
892
912
|
...
|
|
893
913
|
|
|
894
914
|
@property
|
|
895
915
|
def registered_classes(self) -> dict[str, modal.cls.Cls]:
|
|
896
|
-
"""All modal.Cls objects registered on the app.
|
|
916
|
+
"""All modal.Cls objects registered on the app.
|
|
917
|
+
|
|
918
|
+
Note: this property is populated only during the build phase, and it is not
|
|
919
|
+
expected to work when a deplyoed App has been retrieved via `modal.App.lookup`.
|
|
920
|
+
"""
|
|
897
921
|
...
|
|
898
922
|
|
|
899
923
|
@property
|
|
900
924
|
def registered_entrypoints(self) -> dict[str, LocalEntrypoint]:
|
|
901
|
-
"""All local CLI entrypoints registered on the app.
|
|
925
|
+
"""All local CLI entrypoints registered on the app.
|
|
926
|
+
|
|
927
|
+
Note: this property is populated only during the build phase, and it is not
|
|
928
|
+
expected to work when a deplyoed App has been retrieved via `modal.App.lookup`.
|
|
929
|
+
"""
|
|
902
930
|
...
|
|
903
931
|
|
|
904
932
|
@property
|
|
905
933
|
def registered_web_endpoints(self) -> list[str]:
|
|
906
|
-
"""Names of web endpoint (ie. webhook) functions registered on the app.
|
|
934
|
+
"""Names of web endpoint (ie. webhook) functions registered on the app.
|
|
935
|
+
|
|
936
|
+
Note: this property is populated only during the build phase, and it is not
|
|
937
|
+
expected to work when a deplyoed App has been retrieved via `modal.App.lookup`.
|
|
938
|
+
"""
|
|
907
939
|
...
|
|
908
940
|
|
|
909
941
|
def local_entrypoint(
|
modal/client.py
CHANGED
|
@@ -27,6 +27,7 @@ from modal_version import __version__
|
|
|
27
27
|
from ._traceback import print_server_warnings
|
|
28
28
|
from ._utils import async_utils
|
|
29
29
|
from ._utils.async_utils import TaskContext, synchronize_api
|
|
30
|
+
from ._utils.auth_token_manager import _AuthTokenManager
|
|
30
31
|
from ._utils.grpc_utils import ConnectionManager, retry_transient_errors
|
|
31
32
|
from .config import _check_config, _is_remote, config, logger
|
|
32
33
|
from .exception import AuthError, ClientClosed
|
|
@@ -78,6 +79,7 @@ class _Client:
|
|
|
78
79
|
_cancellation_context: TaskContext
|
|
79
80
|
_cancellation_context_event_loop: asyncio.AbstractEventLoop = None
|
|
80
81
|
_stub: Optional[api_grpc.ModalClientStub]
|
|
82
|
+
_auth_token_manager: _AuthTokenManager = None
|
|
81
83
|
_snapshotted: bool
|
|
82
84
|
|
|
83
85
|
def __init__(
|
|
@@ -96,6 +98,7 @@ class _Client:
|
|
|
96
98
|
self.version = version
|
|
97
99
|
self._closed = False
|
|
98
100
|
self._stub: Optional[modal_api_grpc.ModalClientModal] = None
|
|
101
|
+
self._auth_token_manager: Optional[_AuthTokenManager] = None
|
|
99
102
|
self._snapshotted = False
|
|
100
103
|
self._owner_pid = None
|
|
101
104
|
|
|
@@ -133,9 +136,9 @@ class _Client:
|
|
|
133
136
|
self._cancellation_context = TaskContext(grace=0.5) # allow running rpcs to finish in 0.5s when closing client
|
|
134
137
|
self._cancellation_context_event_loop = asyncio.get_running_loop()
|
|
135
138
|
await self._cancellation_context.__aenter__()
|
|
136
|
-
|
|
137
139
|
self._connection_manager = ConnectionManager(client=self, metadata=metadata)
|
|
138
140
|
self._stub = await self.get_stub(self.server_url)
|
|
141
|
+
self._auth_token_manager = _AuthTokenManager(self.stub)
|
|
139
142
|
self._owner_pid = os.getpid()
|
|
140
143
|
|
|
141
144
|
async def _close(self, prep_for_restore: bool = False):
|
|
@@ -424,3 +427,4 @@ class UnaryStreamWrapper(Generic[RequestType, ResponseType]):
|
|
|
424
427
|
self.wrapped_method.channel = await self.client._get_channel(self.server_url)
|
|
425
428
|
async for response in self.client._call_stream(self.wrapped_method, request, metadata=metadata):
|
|
426
429
|
yield response
|
|
430
|
+
|
modal/client.pyi
CHANGED
|
@@ -4,6 +4,7 @@ import collections.abc
|
|
|
4
4
|
import google.protobuf.message
|
|
5
5
|
import grpclib.client
|
|
6
6
|
import modal._utils.async_utils
|
|
7
|
+
import modal._utils.auth_token_manager
|
|
7
8
|
import modal_proto.api_grpc
|
|
8
9
|
import modal_proto.modal_api_grpc
|
|
9
10
|
import synchronicity.combined_types
|
|
@@ -24,6 +25,7 @@ class _Client:
|
|
|
24
25
|
_cancellation_context: modal._utils.async_utils.TaskContext
|
|
25
26
|
_cancellation_context_event_loop: asyncio.events.AbstractEventLoop
|
|
26
27
|
_stub: typing.Optional[modal_proto.api_grpc.ModalClientStub]
|
|
28
|
+
_auth_token_manager: modal._utils.auth_token_manager._AuthTokenManager
|
|
27
29
|
_snapshotted: bool
|
|
28
30
|
|
|
29
31
|
def __init__(
|
|
@@ -31,7 +33,7 @@ class _Client:
|
|
|
31
33
|
server_url: str,
|
|
32
34
|
client_type: int,
|
|
33
35
|
credentials: typing.Optional[tuple[str, str]],
|
|
34
|
-
version: str = "1.0.6.
|
|
36
|
+
version: str = "1.0.6.dev35",
|
|
35
37
|
):
|
|
36
38
|
"""mdmd:hidden
|
|
37
39
|
The Modal client object is not intended to be instantiated directly by users.
|
|
@@ -153,6 +155,7 @@ class Client:
|
|
|
153
155
|
_cancellation_context: modal._utils.async_utils.TaskContext
|
|
154
156
|
_cancellation_context_event_loop: asyncio.events.AbstractEventLoop
|
|
155
157
|
_stub: typing.Optional[modal_proto.api_grpc.ModalClientStub]
|
|
158
|
+
_auth_token_manager: modal._utils.auth_token_manager._AuthTokenManager
|
|
156
159
|
_snapshotted: bool
|
|
157
160
|
|
|
158
161
|
def __init__(
|
|
@@ -160,7 +163,7 @@ class Client:
|
|
|
160
163
|
server_url: str,
|
|
161
164
|
client_type: int,
|
|
162
165
|
credentials: typing.Optional[tuple[str, str]],
|
|
163
|
-
version: str = "1.0.6.
|
|
166
|
+
version: str = "1.0.6.dev35",
|
|
164
167
|
):
|
|
165
168
|
"""mdmd:hidden
|
|
166
169
|
The Modal client object is not intended to be instantiated directly by users.
|
modal/experimental/__init__.py
CHANGED
|
@@ -17,8 +17,9 @@ from .._tunnel import _forward as _forward_tunnel
|
|
|
17
17
|
from .._utils.async_utils import synchronize_api, synchronizer
|
|
18
18
|
from .._utils.deprecation import deprecation_warning
|
|
19
19
|
from .._utils.grpc_utils import retry_transient_errors
|
|
20
|
+
from ..app import _App
|
|
20
21
|
from ..client import _Client
|
|
21
|
-
from ..cls import _Obj
|
|
22
|
+
from ..cls import _Cls, _Obj
|
|
22
23
|
from ..config import logger
|
|
23
24
|
from ..exception import InvalidError
|
|
24
25
|
from ..image import DockerfileSpec, ImageBuilderVersion, _Image, _ImageRegistryConfig
|
|
@@ -88,6 +89,51 @@ async def list_deployed_apps(environment_name: str = "", client: Optional[_Clien
|
|
|
88
89
|
return app_infos
|
|
89
90
|
|
|
90
91
|
|
|
92
|
+
@synchronizer.create_blocking
|
|
93
|
+
async def get_app_objects(
|
|
94
|
+
app_name: str, *, environment_name: Optional[str] = None, client: Optional[_Client] = None
|
|
95
|
+
) -> dict[str, Union[_Function, _Cls]]:
|
|
96
|
+
"""Experimental interface for retrieving a dictionary of the Functions / Clses in an App.
|
|
97
|
+
|
|
98
|
+
The return value is a dictionary mapping names to unhydrated Function or Cls objects.
|
|
99
|
+
|
|
100
|
+
We plan to support this functionality through a stable API in the future. It's likely that
|
|
101
|
+
the stable API will look different (it will probably be a method on the App object itself).
|
|
102
|
+
|
|
103
|
+
"""
|
|
104
|
+
# This is implemented through a somewhat odd mixture of internal RPCs and public APIs.
|
|
105
|
+
# While AppGetLayout provides the object ID and metadata for each object in the App, it's
|
|
106
|
+
# currently somewhere between very awkward and impossible to hydrate a modal.Cls with just
|
|
107
|
+
# that information, since the "class service function" needs to be loaded first
|
|
108
|
+
# (and it's not always possible to do that without knowledge of the parameterization).
|
|
109
|
+
# So instead we just use AppGetLayout to retrieve the names of the Functions / Clsices on
|
|
110
|
+
# the App and then use the public .from_name constructors to return unhydrated handles.
|
|
111
|
+
|
|
112
|
+
# Additionally, since we need to know the environment name to use `.from_name`, and the App's
|
|
113
|
+
# environment name isn't stored anywhere on the App (and cannot be retrieved via an RPC), the
|
|
114
|
+
# experimental function is parameterized by an App name while the stable API would instead
|
|
115
|
+
# be a method on the App itself.
|
|
116
|
+
|
|
117
|
+
if client is None:
|
|
118
|
+
client = await _Client.from_env()
|
|
119
|
+
|
|
120
|
+
app = await _App.lookup(app_name, environment_name=environment_name, client=client)
|
|
121
|
+
req = api_pb2.AppGetLayoutRequest(app_id=app.app_id)
|
|
122
|
+
app_layout_resp = await retry_transient_errors(client.stub.AppGetLayout, req)
|
|
123
|
+
|
|
124
|
+
app_objects: dict[str, Union[_Function, _Cls]] = {}
|
|
125
|
+
|
|
126
|
+
for cls_name in app_layout_resp.app_layout.class_ids:
|
|
127
|
+
app_objects[cls_name] = _Cls.from_name(app_name, cls_name, environment_name=environment_name)
|
|
128
|
+
|
|
129
|
+
for func_name in app_layout_resp.app_layout.function_ids:
|
|
130
|
+
if func_name.endswith(".*"):
|
|
131
|
+
continue # TODO explain
|
|
132
|
+
app_objects[func_name] = _Function.from_name(app_name, func_name, environment_name=environment_name)
|
|
133
|
+
|
|
134
|
+
return app_objects
|
|
135
|
+
|
|
136
|
+
|
|
91
137
|
@synchronizer.create_blocking
|
|
92
138
|
async def raw_dockerfile_image(
|
|
93
139
|
path: Union[str, Path],
|
modal/sandbox.py
CHANGED
|
@@ -578,7 +578,9 @@ class _Sandbox(_Object, type_prefix="sb"):
|
|
|
578
578
|
|
|
579
579
|
async def _get_task_id(self) -> str:
|
|
580
580
|
while not self._task_id:
|
|
581
|
-
resp = await
|
|
581
|
+
resp = await retry_transient_errors(
|
|
582
|
+
self._client.stub.SandboxGetTaskId, api_pb2.SandboxGetTaskIdRequest(sandbox_id=self.object_id)
|
|
583
|
+
)
|
|
582
584
|
self._task_id = resp.task_id
|
|
583
585
|
if not self._task_id:
|
|
584
586
|
await asyncio.sleep(0.5)
|
|
@@ -3,7 +3,7 @@ modal/__main__.py,sha256=sTJcc9EbDuCKSwg3tL6ZckFw9WWdlkXW8mId1IvJCNc,2846
|
|
|
3
3
|
modal/_clustered_functions.py,sha256=kTf-9YBXY88NutC1akI-gCbvf01RhMPCw-zoOI_YIUE,2700
|
|
4
4
|
modal/_clustered_functions.pyi,sha256=_QKM87tdYwcALSGth8a0-9qXl02fZK6zMfEGEoYz7eA,1007
|
|
5
5
|
modal/_container_entrypoint.py,sha256=1qBMNY_E9ICC_sRCtillMxmKPsmxJl1J0_qOAG8rH-0,28288
|
|
6
|
-
modal/_functions.py,sha256=
|
|
6
|
+
modal/_functions.py,sha256=hQ92Vv8wlyecDw2I_essrmYO1Sa6AIPySBogf14Dkr0,82416
|
|
7
7
|
modal/_ipython.py,sha256=TW1fkVOmZL3YYqdS2YlM1hqpf654Yf8ZyybHdBnlhSw,301
|
|
8
8
|
modal/_location.py,sha256=joiX-0ZeutEUDTrrqLF1GHXCdVLF-rHzstocbMcd_-k,366
|
|
9
9
|
modal/_object.py,sha256=QWyUGjrGLupITkyvJru2cekizsaVdteAhwMQlw_tE4k,11172
|
|
@@ -18,11 +18,11 @@ modal/_tunnel.py,sha256=zTBxBiuH1O22tS1OliAJdIsSmaZS8PlnifS_6S5z-mk,6320
|
|
|
18
18
|
modal/_tunnel.pyi,sha256=rvC7USR2BcKkbZIeCJXwf7-UfGE-LPLjKsGNiK7Lxa4,13366
|
|
19
19
|
modal/_type_manager.py,sha256=DWjgmjYJuOagw2erin506UUbG2H5UzZCFEekS-7hmfA,9087
|
|
20
20
|
modal/_watcher.py,sha256=K6LYnlmSGQB4tWWI9JADv-tvSvQ1j522FwT71B51CX8,3584
|
|
21
|
-
modal/app.py,sha256=
|
|
22
|
-
modal/app.pyi,sha256=
|
|
21
|
+
modal/app.py,sha256=U0sPiHpphcRHLnoLYh2IrU2RSpRFX9BE5uHb7h42STs,47478
|
|
22
|
+
modal/app.pyi,sha256=cXiSTu2bwu6csAUdkOlh7mr9tPvtaS2qWSEhlC1UxAg,43787
|
|
23
23
|
modal/call_graph.py,sha256=1g2DGcMIJvRy-xKicuf63IVE98gJSnQsr8R_NVMptNc,2581
|
|
24
|
-
modal/client.py,sha256=
|
|
25
|
-
modal/client.pyi,sha256=
|
|
24
|
+
modal/client.py,sha256=5QyM7VJjsFbHf6E91ar3A2KY9mx03wdtGlNJvfTKUVs,17087
|
|
25
|
+
modal/client.pyi,sha256=FtnPVcn_ibs8N3ZbmQBNMFMxGz8MIXZzPpIUywolqdk,15270
|
|
26
26
|
modal/cloud_bucket_mount.py,sha256=YOe9nnvSr4ZbeCn587d7_VhE9IioZYRvF9VYQTQux08,5914
|
|
27
27
|
modal/cloud_bucket_mount.pyi,sha256=-qSfYAQvIoO_l2wsCCGTG5ZUwQieNKXdAO00yP1-LYU,7394
|
|
28
28
|
modal/cls.py,sha256=EFrM949jNXJpmwB2G_1d28b8IpHShfKIEIaiPkZqeOU,39881
|
|
@@ -65,7 +65,7 @@ modal/retries.py,sha256=IvNLDM0f_GLUDD5VgEDoN09C88yoxSrCquinAuxT1Sc,5205
|
|
|
65
65
|
modal/runner.py,sha256=ostdzYpQb-20tlD6dIq7bpWTkZkOhjJBNuMNektqnJA,24068
|
|
66
66
|
modal/runner.pyi,sha256=lbwLljm1cC8d6PcNvmYQhkE8501V9fg0bYqqKX6G4r4,8489
|
|
67
67
|
modal/running_app.py,sha256=v61mapYNV1-O-Uaho5EfJlryMLvIT9We0amUOSvSGx8,1188
|
|
68
|
-
modal/sandbox.py,sha256=
|
|
68
|
+
modal/sandbox.py,sha256=q7kpGNustlL6Lw7KQbzhw_XwDFn0qBfCoEP7lTW3wYY,37583
|
|
69
69
|
modal/sandbox.pyi,sha256=AyROza8ZUUxs6MO1f3l8zDjTkp6O46H132xUwBUixIc,38565
|
|
70
70
|
modal/schedule.py,sha256=ng0g0AqNY5GQI9KhkXZQ5Wam5G42glbkqVQsNpBtbDE,3078
|
|
71
71
|
modal/scheduler_placement.py,sha256=BAREdOY5HzHpzSBqt6jDVR6YC_jYfHMVqOzkyqQfngU,1235
|
|
@@ -92,6 +92,7 @@ modal/_runtime/user_code_imports.py,sha256=78wJyleqY2RVibqcpbDQyfWVBVT9BjyHPeoV9
|
|
|
92
92
|
modal/_utils/__init__.py,sha256=waLjl5c6IPDhSsdWAm9Bji4e2PVxamYABKAze6CHVXY,28
|
|
93
93
|
modal/_utils/app_utils.py,sha256=88BT4TPLWfYAQwKTHcyzNQRHg8n9B-QE2UyJs96iV-0,108
|
|
94
94
|
modal/_utils/async_utils.py,sha256=MhSCsCL8GqIVFWoHubU_899IH-JBZAiiqadG9Wri2l4,29361
|
|
95
|
+
modal/_utils/auth_token_manager.py,sha256=4YS0pBfwbuNFy5DoAIOnBNCcYjS9rNCMv4zSVGybiOw,5245
|
|
95
96
|
modal/_utils/blob_utils.py,sha256=v2NAQVVGx1AQjHQ7-2T64x5rYtwjFFykxDXb-0grrzA,21022
|
|
96
97
|
modal/_utils/bytes_io_segment_payload.py,sha256=vaXPq8b52-x6G2hwE7SrjS58pg_aRm7gV3bn3yjmTzQ,4261
|
|
97
98
|
modal/_utils/deprecation.py,sha256=-Bgg7jZdcJU8lROy18YyVnQYbM8hue-hVmwJqlWAGH0,5504
|
|
@@ -99,7 +100,7 @@ modal/_utils/docker_utils.py,sha256=h1uETghR40mp_y3fSWuZAfbIASH1HMzuphJHghAL6DU,
|
|
|
99
100
|
modal/_utils/function_utils.py,sha256=wFJcfmGC8RuYeQUORGKg6soLj31Mzw9qfay6CyPSAZE,28130
|
|
100
101
|
modal/_utils/git_utils.py,sha256=qtUU6JAttF55ZxYq51y55OR58B0tDPZsZWK5dJe6W5g,3182
|
|
101
102
|
modal/_utils/grpc_testing.py,sha256=H1zHqthv19eGPJz2HKXDyWXWGSqO4BRsxah3L5Xaa8A,8619
|
|
102
|
-
modal/_utils/grpc_utils.py,sha256=
|
|
103
|
+
modal/_utils/grpc_utils.py,sha256=HBZdMcBHCk6uozILYTjGnR0mV8fg7WOdJldoyZ-ZhSg,10137
|
|
103
104
|
modal/_utils/hash_utils.py,sha256=zg3J6OGxTFGSFri1qQ12giDz90lWk8bzaxCTUCRtiX4,3034
|
|
104
105
|
modal/_utils/http_utils.py,sha256=yeTFsXYr0rYMEhB7vBP7audG9Uc7OLhzKBANFDZWVt0,2451
|
|
105
106
|
modal/_utils/jwt_utils.py,sha256=fxH9plyrbAemTbjSsQtzIdDXE9QXxvMC4DiUZ16G0aA,1360
|
|
@@ -138,7 +139,7 @@ modal/cli/volume.py,sha256=KJ4WKQYjRGsTERkwHE1HcRia9rWzLIDDnlc89QmTLvE,10960
|
|
|
138
139
|
modal/cli/programs/__init__.py,sha256=svYKtV8HDwDCN86zbdWqyq5T8sMdGDj0PVlzc2tIxDM,28
|
|
139
140
|
modal/cli/programs/run_jupyter.py,sha256=44Lpvqk2l3hH-uOkmAOzw60NEsfB5uaRDWDKVshvQhs,2682
|
|
140
141
|
modal/cli/programs/vscode.py,sha256=KbTAaIXyQBVCDXxXjmBHmKpgXkUw0q4R4KkJvUjCYgk,3380
|
|
141
|
-
modal/experimental/__init__.py,sha256=
|
|
142
|
+
modal/experimental/__init__.py,sha256=IT7Tq7nBR59_v5YjKoA5U0KXvMbv_kl5Cgw1jsnm-No,13836
|
|
142
143
|
modal/experimental/ipython.py,sha256=TrCfmol9LGsRZMeDoeMPx3Hv3BFqQhYnmD_iH0pqdhk,2904
|
|
143
144
|
modal/requirements/2023.12.312.txt,sha256=zWWUVgVQ92GXBKNYYr2-5vn9rlnXcmkqlwlX5u1eTYw,400
|
|
144
145
|
modal/requirements/2023.12.txt,sha256=OjsbXFkCSdkzzryZP82Q73osr5wxQ6EUzmGcK7twfkA,502
|
|
@@ -148,7 +149,7 @@ modal/requirements/2025.06.txt,sha256=KxDaVTOwatHvboDo4lorlgJ7-n-MfAwbPwxJ0zcJqr
|
|
|
148
149
|
modal/requirements/PREVIEW.txt,sha256=KxDaVTOwatHvboDo4lorlgJ7-n-MfAwbPwxJ0zcJqrs,312
|
|
149
150
|
modal/requirements/README.md,sha256=9tK76KP0Uph7O0M5oUgsSwEZDj5y-dcUPsnpR0Sc-Ik,854
|
|
150
151
|
modal/requirements/base-images.json,sha256=JYSDAgHTl-WrV_TZW5icY-IJEnbe2eQ4CZ_KN6EOZKU,1304
|
|
151
|
-
modal-1.0.6.
|
|
152
|
+
modal-1.0.6.dev35.dist-info/licenses/LICENSE,sha256=psuoW8kuDP96RQsdhzwOqi6fyWv0ct8CR6Jr7He_P_k,10173
|
|
152
153
|
modal_docs/__init__.py,sha256=svYKtV8HDwDCN86zbdWqyq5T8sMdGDj0PVlzc2tIxDM,28
|
|
153
154
|
modal_docs/gen_cli_docs.py,sha256=c1yfBS_x--gL5bs0N4ihMwqwX8l3IBWSkBAKNNIi6bQ,3801
|
|
154
155
|
modal_docs/gen_reference_docs.py,sha256=d_CQUGQ0rfw28u75I2mov9AlS773z9rG40-yq5o7g2U,6359
|
|
@@ -171,10 +172,10 @@ modal_proto/options_pb2.pyi,sha256=l7DBrbLO7q3Ir-XDkWsajm0d0TQqqrfuX54i4BMpdQg,1
|
|
|
171
172
|
modal_proto/options_pb2_grpc.py,sha256=1oboBPFxaTEXt9Aw7EAj8gXHDCNMhZD2VXqocC9l_gk,159
|
|
172
173
|
modal_proto/options_pb2_grpc.pyi,sha256=CImmhxHsYnF09iENPoe8S4J-n93jtgUYD2JPAc0yJSI,247
|
|
173
174
|
modal_proto/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
174
|
-
modal_version/__init__.py,sha256=
|
|
175
|
+
modal_version/__init__.py,sha256=lOl746IZNj-Ic3Vi6oCzy2IuszcJkff4r7sPXgkKDKI,121
|
|
175
176
|
modal_version/__main__.py,sha256=2FO0yYQQwDTh6udt1h-cBnGd1c4ZyHnHSI4BksxzVac,105
|
|
176
|
-
modal-1.0.6.
|
|
177
|
-
modal-1.0.6.
|
|
178
|
-
modal-1.0.6.
|
|
179
|
-
modal-1.0.6.
|
|
180
|
-
modal-1.0.6.
|
|
177
|
+
modal-1.0.6.dev35.dist-info/METADATA,sha256=hLiw38PEdO-arLLnLtTPnu9wWAhQYRpywfdZokOQTdA,2462
|
|
178
|
+
modal-1.0.6.dev35.dist-info/WHEEL,sha256=1tXe9gY0PYatrMPMDd6jXqjfpz_B-Wqm32CPfRC58XU,91
|
|
179
|
+
modal-1.0.6.dev35.dist-info/entry_points.txt,sha256=An-wYgeEUnm6xzrAP9_NTSTSciYvvEWsMZILtYrvpAI,46
|
|
180
|
+
modal-1.0.6.dev35.dist-info/top_level.txt,sha256=4BWzoKYREKUZ5iyPzZpjqx4G8uB5TWxXPDwibLcVa7k,43
|
|
181
|
+
modal-1.0.6.dev35.dist-info/RECORD,,
|
modal_version/__init__.py
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|