modal 1.0.5.dev1__py3-none-any.whl → 1.0.5.dev3__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.
modal/environments.pyi CHANGED
@@ -7,20 +7,42 @@ import typing
7
7
  import typing_extensions
8
8
 
9
9
  class EnvironmentSettings:
10
+ """EnvironmentSettings(image_builder_version: str, webhook_suffix: str)"""
11
+
10
12
  image_builder_version: str
11
13
  webhook_suffix: str
12
14
 
13
- def __init__(self, image_builder_version: str, webhook_suffix: str) -> None: ...
14
- def __repr__(self): ...
15
- def __eq__(self, other): ...
16
- def __setattr__(self, name, value): ...
17
- def __delattr__(self, name): ...
18
- def __hash__(self): ...
15
+ def __init__(self, image_builder_version: str, webhook_suffix: str) -> None:
16
+ """Initialize self. See help(type(self)) for accurate signature."""
17
+ ...
18
+
19
+ def __repr__(self):
20
+ """Return repr(self)."""
21
+ ...
22
+
23
+ def __eq__(self, other):
24
+ """Return self==value."""
25
+ ...
26
+
27
+ def __setattr__(self, name, value):
28
+ """Implement setattr(self, name, value)."""
29
+ ...
30
+
31
+ def __delattr__(self, name):
32
+ """Implement delattr(self, name)."""
33
+ ...
34
+
35
+ def __hash__(self):
36
+ """Return hash(self)."""
37
+ ...
19
38
 
20
39
  class _Environment(modal._object._Object):
21
40
  _settings: EnvironmentSettings
22
41
 
23
- def __init__(self): ...
42
+ def __init__(self):
43
+ """mdmd:hidden"""
44
+ ...
45
+
24
46
  def _hydrate_metadata(self, metadata: google.protobuf.message.Message): ...
25
47
  @staticmethod
26
48
  def from_name(name: str, *, create_if_missing: bool = False): ...
@@ -32,7 +54,10 @@ class _Environment(modal._object._Object):
32
54
  class Environment(modal.object.Object):
33
55
  _settings: EnvironmentSettings
34
56
 
35
- def __init__(self): ...
57
+ def __init__(self):
58
+ """mdmd:hidden"""
59
+ ...
60
+
36
61
  def _hydrate_metadata(self, metadata: google.protobuf.message.Message): ...
37
62
  @staticmethod
38
63
  def from_name(name: str, *, create_if_missing: bool = False): ...
@@ -93,6 +118,13 @@ class __list_environments_spec(typing_extensions.Protocol):
93
118
 
94
119
  list_environments: __list_environments_spec
95
120
 
96
- def ensure_env(environment_name: typing.Optional[str] = None) -> str: ...
121
+ def ensure_env(environment_name: typing.Optional[str] = None) -> str:
122
+ """Override config environment with environment from environment_name
123
+
124
+ This is necessary since a cli command that runs Modal code, without explicit
125
+ environment specification wouldn't pick up the environment specified in a
126
+ command line flag otherwise, e.g. when doing `modal run --env=foo`
127
+ """
128
+ ...
97
129
 
98
130
  ENVIRONMENT_CACHE: dict[str, _Environment]
modal/exception.py CHANGED
@@ -2,6 +2,10 @@
2
2
  import random
3
3
  import signal
4
4
 
5
+ import synchronicity.exceptions
6
+
7
+ UserCodeException = synchronicity.exceptions.UserCodeException # Deprecated type used for return_exception wrapping
8
+
5
9
 
6
10
  class Error(Exception):
7
11
  """
modal/file_io.pyi CHANGED
@@ -6,12 +6,24 @@ import typing_extensions
6
6
 
7
7
  T = typing.TypeVar("T")
8
8
 
9
- async def _delete_bytes(
10
- file: _FileIO, start: typing.Optional[int] = None, end: typing.Optional[int] = None
11
- ) -> None: ...
9
+ async def _delete_bytes(file: _FileIO, start: typing.Optional[int] = None, end: typing.Optional[int] = None) -> None:
10
+ """Delete a range of bytes from the file.
11
+
12
+ `start` and `end` are byte offsets. `start` is inclusive, `end` is exclusive.
13
+ If either is None, the start or end of the file is used, respectively.
14
+ """
15
+ ...
16
+
12
17
  async def _replace_bytes(
13
18
  file: _FileIO, data: bytes, start: typing.Optional[int] = None, end: typing.Optional[int] = None
14
- ) -> None: ...
19
+ ) -> None:
20
+ """Replace a range of bytes in the file with new data. The length of the data does not
21
+ have to be the same as the length of the range being replaced.
22
+
23
+ `start` and `end` are byte offsets. `start` is inclusive, `end` is exclusive.
24
+ If either is None, the start or end of the file is used, respectively.
25
+ """
26
+ ...
15
27
 
16
28
  class FileWatchEventType(enum.Enum):
17
29
  Unknown = "Unknown"
@@ -21,20 +33,51 @@ class FileWatchEventType(enum.Enum):
21
33
  Remove = "Remove"
22
34
 
23
35
  class FileWatchEvent:
36
+ """FileWatchEvent(paths: list[str], type: modal.file_io.FileWatchEventType)"""
37
+
24
38
  paths: list[str]
25
39
  type: FileWatchEventType
26
40
 
27
- def __init__(self, paths: list[str], type: FileWatchEventType) -> None: ...
28
- def __repr__(self): ...
29
- def __eq__(self, other): ...
41
+ def __init__(self, paths: list[str], type: FileWatchEventType) -> None:
42
+ """Initialize self. See help(type(self)) for accurate signature."""
43
+ ...
44
+
45
+ def __repr__(self):
46
+ """Return repr(self)."""
47
+ ...
48
+
49
+ def __eq__(self, other):
50
+ """Return self==value."""
51
+ ...
30
52
 
31
53
  class _FileIO(typing.Generic[T]):
54
+ """FileIO handle, used in the Sandbox filesystem API.
55
+
56
+ The API is designed to mimic Python's io.FileIO.
57
+
58
+ **Usage**
59
+
60
+ ```python
61
+ import modal
62
+
63
+ app = modal.App.lookup("my-app", create_if_missing=True)
64
+
65
+ sb = modal.Sandbox.create(app=app)
66
+ f = sb.open("/tmp/foo.txt", "w")
67
+ f.write("hello")
68
+ f.close()
69
+ ```
70
+ """
71
+
32
72
  _task_id: str
33
73
  _file_descriptor: str
34
74
  _client: modal.client._Client
35
75
  _watch_output_buffer: list[typing.Union[bytes, None, Exception]]
36
76
 
37
- def __init__(self, client: modal.client._Client, task_id: str) -> None: ...
77
+ def __init__(self, client: modal.client._Client, task_id: str) -> None:
78
+ """Initialize self. See help(type(self)) for accurate signature."""
79
+ ...
80
+
38
81
  def _validate_mode(self, mode: str) -> None: ...
39
82
  def _consume_output(self, exec_id: str) -> typing.AsyncIterator[typing.Union[bytes, None, Exception]]: ...
40
83
  async def _consume_watch_output(self, exec_id: str) -> None: ...
@@ -49,21 +92,60 @@ class _FileIO(typing.Generic[T]):
49
92
  mode: typing.Union[_typeshed.OpenTextMode, _typeshed.OpenBinaryMode],
50
93
  client: modal.client._Client,
51
94
  task_id: str,
52
- ) -> _FileIO: ...
95
+ ) -> _FileIO:
96
+ """Create a new FileIO handle."""
97
+ ...
98
+
53
99
  async def _make_read_request(self, n: typing.Optional[int]) -> bytes: ...
54
- async def read(self, n: typing.Optional[int] = None) -> T: ...
55
- async def readline(self) -> T: ...
56
- async def readlines(self) -> typing.Sequence[T]: ...
57
- async def write(self, data: typing.Union[bytes, str]) -> None: ...
58
- async def flush(self) -> None: ...
100
+ async def read(self, n: typing.Optional[int] = None) -> T:
101
+ """Read n bytes from the current position, or the entire remaining file if n is None."""
102
+ ...
103
+
104
+ async def readline(self) -> T:
105
+ """Read a single line from the current position."""
106
+ ...
107
+
108
+ async def readlines(self) -> typing.Sequence[T]:
109
+ """Read all lines from the current position."""
110
+ ...
111
+
112
+ async def write(self, data: typing.Union[bytes, str]) -> None:
113
+ """Write data to the current position.
114
+
115
+ Writes may not appear until the entire buffer is flushed, which
116
+ can be done manually with `flush()` or automatically when the file is
117
+ closed.
118
+ """
119
+ ...
120
+
121
+ async def flush(self) -> None:
122
+ """Flush the buffer to disk."""
123
+ ...
124
+
59
125
  def _get_whence(self, whence: int): ...
60
- async def seek(self, offset: int, whence: int = 0) -> None: ...
126
+ async def seek(self, offset: int, whence: int = 0) -> None:
127
+ """Move to a new position in the file.
128
+
129
+ `whence` defaults to 0 (absolute file positioning); other values are 1
130
+ (relative to the current position) and 2 (relative to the file's end).
131
+ """
132
+ ...
133
+
61
134
  @classmethod
62
- async def ls(cls, path: str, client: modal.client._Client, task_id: str) -> list[str]: ...
135
+ async def ls(cls, path: str, client: modal.client._Client, task_id: str) -> list[str]:
136
+ """List the contents of the provided directory."""
137
+ ...
138
+
63
139
  @classmethod
64
- async def mkdir(cls, path: str, client: modal.client._Client, task_id: str, parents: bool = False) -> None: ...
140
+ async def mkdir(cls, path: str, client: modal.client._Client, task_id: str, parents: bool = False) -> None:
141
+ """Create a new directory."""
142
+ ...
143
+
65
144
  @classmethod
66
- async def rm(cls, path: str, client: modal.client._Client, task_id: str, recursive: bool = False) -> None: ...
145
+ async def rm(cls, path: str, client: modal.client._Client, task_id: str, recursive: bool = False) -> None:
146
+ """Remove a file or directory in the Sandbox."""
147
+ ...
148
+
67
149
  @classmethod
68
150
  def watch(
69
151
  cls,
@@ -75,7 +157,10 @@ class _FileIO(typing.Generic[T]):
75
157
  timeout: typing.Optional[int] = None,
76
158
  ) -> typing.AsyncIterator[FileWatchEvent]: ...
77
159
  async def _close(self) -> None: ...
78
- async def close(self) -> None: ...
160
+ async def close(self) -> None:
161
+ """Flush the buffer and close the file."""
162
+ ...
163
+
79
164
  def _check_writable(self) -> None: ...
80
165
  def _check_readable(self) -> None: ...
81
166
  def _check_closed(self) -> None: ...
@@ -83,22 +168,46 @@ class _FileIO(typing.Generic[T]):
83
168
  async def __aexit__(self, exc_type, exc_value, traceback) -> None: ...
84
169
 
85
170
  class __delete_bytes_spec(typing_extensions.Protocol):
86
- def __call__(
87
- self, /, file: FileIO, start: typing.Optional[int] = None, end: typing.Optional[int] = None
88
- ) -> None: ...
89
- async def aio(
90
- self, /, file: FileIO, start: typing.Optional[int] = None, end: typing.Optional[int] = None
91
- ) -> None: ...
171
+ def __call__(self, /, file: FileIO, start: typing.Optional[int] = None, end: typing.Optional[int] = None) -> None:
172
+ """Delete a range of bytes from the file.
173
+
174
+ `start` and `end` are byte offsets. `start` is inclusive, `end` is exclusive.
175
+ If either is None, the start or end of the file is used, respectively.
176
+ """
177
+ ...
178
+
179
+ async def aio(self, /, file: FileIO, start: typing.Optional[int] = None, end: typing.Optional[int] = None) -> None:
180
+ """Delete a range of bytes from the file.
181
+
182
+ `start` and `end` are byte offsets. `start` is inclusive, `end` is exclusive.
183
+ If either is None, the start or end of the file is used, respectively.
184
+ """
185
+ ...
92
186
 
93
187
  delete_bytes: __delete_bytes_spec
94
188
 
95
189
  class __replace_bytes_spec(typing_extensions.Protocol):
96
190
  def __call__(
97
191
  self, /, file: FileIO, data: bytes, start: typing.Optional[int] = None, end: typing.Optional[int] = None
98
- ) -> None: ...
192
+ ) -> None:
193
+ """Replace a range of bytes in the file with new data. The length of the data does not
194
+ have to be the same as the length of the range being replaced.
195
+
196
+ `start` and `end` are byte offsets. `start` is inclusive, `end` is exclusive.
197
+ If either is None, the start or end of the file is used, respectively.
198
+ """
199
+ ...
200
+
99
201
  async def aio(
100
202
  self, /, file: FileIO, data: bytes, start: typing.Optional[int] = None, end: typing.Optional[int] = None
101
- ) -> None: ...
203
+ ) -> None:
204
+ """Replace a range of bytes in the file with new data. The length of the data does not
205
+ have to be the same as the length of the range being replaced.
206
+
207
+ `start` and `end` are byte offsets. `start` is inclusive, `end` is exclusive.
208
+ If either is None, the start or end of the file is used, respectively.
209
+ """
210
+ ...
102
211
 
103
212
  replace_bytes: __replace_bytes_spec
104
213
 
@@ -107,6 +216,24 @@ SUPERSELF = typing.TypeVar("SUPERSELF", covariant=True)
107
216
  T_INNER = typing.TypeVar("T_INNER", covariant=True)
108
217
 
109
218
  class FileIO(typing.Generic[T]):
219
+ """FileIO handle, used in the Sandbox filesystem API.
220
+
221
+ The API is designed to mimic Python's io.FileIO.
222
+
223
+ **Usage**
224
+
225
+ ```python
226
+ import modal
227
+
228
+ app = modal.App.lookup("my-app", create_if_missing=True)
229
+
230
+ sb = modal.Sandbox.create(app=app)
231
+ f = sb.open("/tmp/foo.txt", "w")
232
+ f.write("hello")
233
+ f.close()
234
+ ```
235
+ """
236
+
110
237
  _task_id: str
111
238
  _file_descriptor: str
112
239
  _client: modal.client.Client
@@ -154,7 +281,9 @@ class FileIO(typing.Generic[T]):
154
281
  mode: typing.Union[_typeshed.OpenTextMode, _typeshed.OpenBinaryMode],
155
282
  client: modal.client.Client,
156
283
  task_id: str,
157
- ) -> FileIO: ...
284
+ ) -> FileIO:
285
+ """Create a new FileIO handle."""
286
+ ...
158
287
 
159
288
  class ___make_read_request_spec(typing_extensions.Protocol[SUPERSELF]):
160
289
  def __call__(self, /, n: typing.Optional[int]) -> bytes: ...
@@ -163,49 +292,106 @@ class FileIO(typing.Generic[T]):
163
292
  _make_read_request: ___make_read_request_spec[typing_extensions.Self]
164
293
 
165
294
  class __read_spec(typing_extensions.Protocol[T_INNER, SUPERSELF]):
166
- def __call__(self, /, n: typing.Optional[int] = None) -> T_INNER: ...
167
- async def aio(self, /, n: typing.Optional[int] = None) -> T_INNER: ...
295
+ def __call__(self, /, n: typing.Optional[int] = None) -> T_INNER:
296
+ """Read n bytes from the current position, or the entire remaining file if n is None."""
297
+ ...
298
+
299
+ async def aio(self, /, n: typing.Optional[int] = None) -> T_INNER:
300
+ """Read n bytes from the current position, or the entire remaining file if n is None."""
301
+ ...
168
302
 
169
303
  read: __read_spec[T, typing_extensions.Self]
170
304
 
171
305
  class __readline_spec(typing_extensions.Protocol[T_INNER, SUPERSELF]):
172
- def __call__(self, /) -> T_INNER: ...
173
- async def aio(self, /) -> T_INNER: ...
306
+ def __call__(self, /) -> T_INNER:
307
+ """Read a single line from the current position."""
308
+ ...
309
+
310
+ async def aio(self, /) -> T_INNER:
311
+ """Read a single line from the current position."""
312
+ ...
174
313
 
175
314
  readline: __readline_spec[T, typing_extensions.Self]
176
315
 
177
316
  class __readlines_spec(typing_extensions.Protocol[T_INNER, SUPERSELF]):
178
- def __call__(self, /) -> typing.Sequence[T_INNER]: ...
179
- async def aio(self, /) -> typing.Sequence[T_INNER]: ...
317
+ def __call__(self, /) -> typing.Sequence[T_INNER]:
318
+ """Read all lines from the current position."""
319
+ ...
320
+
321
+ async def aio(self, /) -> typing.Sequence[T_INNER]:
322
+ """Read all lines from the current position."""
323
+ ...
180
324
 
181
325
  readlines: __readlines_spec[T, typing_extensions.Self]
182
326
 
183
327
  class __write_spec(typing_extensions.Protocol[SUPERSELF]):
184
- def __call__(self, /, data: typing.Union[bytes, str]) -> None: ...
185
- async def aio(self, /, data: typing.Union[bytes, str]) -> None: ...
328
+ def __call__(self, /, data: typing.Union[bytes, str]) -> None:
329
+ """Write data to the current position.
330
+
331
+ Writes may not appear until the entire buffer is flushed, which
332
+ can be done manually with `flush()` or automatically when the file is
333
+ closed.
334
+ """
335
+ ...
336
+
337
+ async def aio(self, /, data: typing.Union[bytes, str]) -> None:
338
+ """Write data to the current position.
339
+
340
+ Writes may not appear until the entire buffer is flushed, which
341
+ can be done manually with `flush()` or automatically when the file is
342
+ closed.
343
+ """
344
+ ...
186
345
 
187
346
  write: __write_spec[typing_extensions.Self]
188
347
 
189
348
  class __flush_spec(typing_extensions.Protocol[SUPERSELF]):
190
- def __call__(self, /) -> None: ...
191
- async def aio(self, /) -> None: ...
349
+ def __call__(self, /) -> None:
350
+ """Flush the buffer to disk."""
351
+ ...
352
+
353
+ async def aio(self, /) -> None:
354
+ """Flush the buffer to disk."""
355
+ ...
192
356
 
193
357
  flush: __flush_spec[typing_extensions.Self]
194
358
 
195
359
  def _get_whence(self, whence: int): ...
196
360
 
197
361
  class __seek_spec(typing_extensions.Protocol[SUPERSELF]):
198
- def __call__(self, /, offset: int, whence: int = 0) -> None: ...
199
- async def aio(self, /, offset: int, whence: int = 0) -> None: ...
362
+ def __call__(self, /, offset: int, whence: int = 0) -> None:
363
+ """Move to a new position in the file.
364
+
365
+ `whence` defaults to 0 (absolute file positioning); other values are 1
366
+ (relative to the current position) and 2 (relative to the file's end).
367
+ """
368
+ ...
369
+
370
+ async def aio(self, /, offset: int, whence: int = 0) -> None:
371
+ """Move to a new position in the file.
372
+
373
+ `whence` defaults to 0 (absolute file positioning); other values are 1
374
+ (relative to the current position) and 2 (relative to the file's end).
375
+ """
376
+ ...
200
377
 
201
378
  seek: __seek_spec[typing_extensions.Self]
202
379
 
203
380
  @classmethod
204
- def ls(cls, path: str, client: modal.client.Client, task_id: str) -> list[str]: ...
381
+ def ls(cls, path: str, client: modal.client.Client, task_id: str) -> list[str]:
382
+ """List the contents of the provided directory."""
383
+ ...
384
+
205
385
  @classmethod
206
- def mkdir(cls, path: str, client: modal.client.Client, task_id: str, parents: bool = False) -> None: ...
386
+ def mkdir(cls, path: str, client: modal.client.Client, task_id: str, parents: bool = False) -> None:
387
+ """Create a new directory."""
388
+ ...
389
+
207
390
  @classmethod
208
- def rm(cls, path: str, client: modal.client.Client, task_id: str, recursive: bool = False) -> None: ...
391
+ def rm(cls, path: str, client: modal.client.Client, task_id: str, recursive: bool = False) -> None:
392
+ """Remove a file or directory in the Sandbox."""
393
+ ...
394
+
209
395
  @classmethod
210
396
  def watch(
211
397
  cls,
@@ -224,8 +410,13 @@ class FileIO(typing.Generic[T]):
224
410
  _close: ___close_spec[typing_extensions.Self]
225
411
 
226
412
  class __close_spec(typing_extensions.Protocol[SUPERSELF]):
227
- def __call__(self, /) -> None: ...
228
- async def aio(self, /) -> None: ...
413
+ def __call__(self, /) -> None:
414
+ """Flush the buffer and close the file."""
415
+ ...
416
+
417
+ async def aio(self, /) -> None:
418
+ """Flush the buffer and close the file."""
419
+ ...
229
420
 
230
421
  close: __close_spec[typing_extensions.Self]
231
422