contree-sdk 0.4.0.dev3__py3-none-any.whl → 0.4.0.dev5__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.
@@ -6,6 +6,7 @@ from asyncio import Event, Lock, Queue, create_task, gather, shield
6
6
  from collections import defaultdict
7
7
  from contextlib import asynccontextmanager, suppress
8
8
  from dataclasses import dataclass
9
+ from datetime import timedelta
9
10
  from sys import version_info
10
11
  from types import EllipsisType
11
12
  from typing import TYPE_CHECKING, Literal, TypeVar, overload
@@ -21,6 +22,7 @@ from contree_client.models import (
21
22
 
22
23
  from contree_sdk._internals.io.typing import AsyncWritable, Writable
23
24
  from contree_sdk._internals.io.writer_wrapper import EOF, WriterToQueue, WriterWrapper
25
+ from contree_sdk._internals.utils.circuit_retrier import CircuitRetrier
24
26
  from contree_sdk.sdk.exceptions import (
25
27
  CancelledOperationError,
26
28
  ContreeApiError,
@@ -31,6 +33,7 @@ from contree_sdk.sdk.exceptions import (
31
33
  NotFoundError,
32
34
  OperationTimedOutError,
33
35
  )
36
+ from contree_sdk.sdk.exceptions.api import ApiTimeoutError, ContreeTransportError, TooEarlyError, TooManyRequestsError
34
37
  from contree_sdk.utils.models.operation import OperationEventType, OperationStatus
35
38
 
36
39
 
@@ -84,6 +87,19 @@ class OperationWaiter:
84
87
  self.operation_id = operation_id
85
88
  self._client = client
86
89
  self._output_limit = client.config.default_truncate_output_at
90
+ import_timeout = client.config.operation_import_timeout or client.config.operation_timeout
91
+ spawn_timeout = client.config.operation_run_timeout or client.config.operation_timeout
92
+ self._stream_retrier = CircuitRetrier(
93
+ exceptions=[
94
+ TooManyRequestsError,
95
+ ApiTimeoutError,
96
+ ContreeTransportError,
97
+ NotFoundError,
98
+ TooEarlyError,
99
+ EventStreamInterruptedError,
100
+ ],
101
+ retry_timeout=timedelta(seconds=max(spawn_timeout, import_timeout)),
102
+ )
87
103
  self._output_by_spid = defaultdict(lambda: defaultdict(bytearray))
88
104
  self._local_output_dropped: dict[int | None, dict[StreamName, int]] = defaultdict(lambda: defaultdict(int))
89
105
  # IO objects by spid and stream name
@@ -231,10 +247,9 @@ class OperationWaiter:
231
247
  async def wait_for_result(
232
248
  self, *, operation_timeout: float | None = None, spid: int | None = MAIN_SPID
233
249
  ) -> tuple[EventDataCompletion, EventDataExit | None]:
234
- retrier = self._client._default_retrier
235
250
  try:
236
251
  async with self._operation_canceller(), timeout(operation_timeout):
237
- await retrier(self._load_events)
252
+ await self._stream_retrier(self._load_events)
238
253
  except (TimeoutError, asyncio.TimeoutError) as e:
239
254
  raise OperationTimedOutError(operation_uuid=self.operation_id) from e
240
255
 
@@ -27,14 +27,7 @@ from contree_sdk._internals.utils.circuit_retrier import CircuitRetrier
27
27
  from contree_sdk.auth import IAMAuth
28
28
  from contree_sdk.config import ContreeConfig
29
29
  from contree_sdk.sdk.exceptions import ContreeError, UnknownContreeError
30
- from contree_sdk.sdk.exceptions.api import (
31
- ApiTimeoutError,
32
- ContreeTransportError,
33
- EventStreamInterruptedError,
34
- NotFoundError,
35
- TooEarlyError,
36
- TooManyRequestsError,
37
- )
30
+ from contree_sdk.sdk.exceptions.api import ApiTimeoutError, TooManyRequestsError
38
31
  from contree_sdk.sdk.objects.image._base import _ContreeImageBase
39
32
  from contree_sdk.utils.models.auth import WhoAmI
40
33
 
@@ -90,14 +83,6 @@ class _ContreeBase:
90
83
  self._config = config
91
84
  self._token_info: WhoAmI | None = None
92
85
  start_exceptions = [TooManyRequestsError, ApiTimeoutError]
93
- stream_exceptions = [
94
- TooManyRequestsError,
95
- ApiTimeoutError,
96
- ContreeTransportError,
97
- NotFoundError,
98
- TooEarlyError,
99
- EventStreamInterruptedError,
100
- ]
101
86
  import_timeout = config.operation_import_timeout or config.operation_timeout
102
87
  spawn_timeout = config.operation_run_timeout or config.operation_timeout
103
88
  self._import_retrier = CircuitRetrier(
@@ -106,9 +91,6 @@ class _ContreeBase:
106
91
  self._spawn_retrier = CircuitRetrier(
107
92
  exceptions=start_exceptions, retry_timeout=timedelta(seconds=spawn_timeout)
108
93
  )
109
- self._default_retrier = CircuitRetrier(
110
- exceptions=stream_exceptions, retry_timeout=timedelta(seconds=max(spawn_timeout, import_timeout))
111
- )
112
94
  self._waiters: WeakValueDictionary[UUID, OperationWaiter] = WeakValueDictionary()
113
95
  self._waiters_lock = Lock()
114
96
 
@@ -1,6 +1,8 @@
1
- from collections.abc import AsyncIterator
1
+ from collections.abc import AsyncIterator, Sequence
2
2
  from pathlib import Path, PurePosixPath
3
- from typing import TypeVar
3
+ from typing import Literal, TypeVar
4
+
5
+ from contree_client.models import GrepResult
4
6
 
5
7
  from contree_sdk._internals.io.operation_waiter import OutputChunk
6
8
  from contree_sdk._internals.utils.typing import keep_signature
@@ -36,6 +38,45 @@ class _ImageLike(_ImageLikeBase):
36
38
  """
37
39
  return await self._ls(path, ImageFile, ImageDirectory)
38
40
 
41
+ async def grep(
42
+ self,
43
+ pattern: str | Sequence[str],
44
+ *,
45
+ path: str | Sequence[str] | None = None,
46
+ glob: str | Sequence[str] | None = None,
47
+ max_count: int | None = None,
48
+ max_total: int | None = None,
49
+ case: Literal["sensitive", "insensitive", "smart"] | None = None,
50
+ before: int | None = None,
51
+ after: int | None = None,
52
+ ) -> GrepResult:
53
+ """Search file contents in the image.
54
+
55
+ Args:
56
+ pattern: Search pattern or patterns.
57
+ path: Path or paths to search. Defaults to the image root.
58
+ glob: Glob filter or filters.
59
+ max_count: Maximum matches per file.
60
+ max_total: Maximum matches across all files.
61
+ case: Case matching mode.
62
+ before: Number of context lines before each match.
63
+ after: Number of context lines after each match.
64
+
65
+ Returns:
66
+ Typed grep result with matches and truncation status.
67
+
68
+ """
69
+ return await self._grep(
70
+ pattern,
71
+ path=path,
72
+ glob=glob,
73
+ max_count=max_count,
74
+ max_total=max_total,
75
+ case=case,
76
+ before=before,
77
+ after=after,
78
+ )
79
+
39
80
  async def download(self, image_path: str | PurePosixPath, local_path: str | Path | None = None) -> Path | None:
40
81
  """Download a file from the image to local filesystem.
41
82
 
@@ -1,17 +1,17 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  from asyncio import create_task, gather, to_thread
4
- from collections.abc import AsyncGenerator, Iterable
4
+ from collections.abc import AsyncGenerator, Iterable, Sequence
5
5
  from contextlib import aclosing
6
6
  from copy import copy
7
7
  from dataclasses import replace
8
8
  from datetime import timedelta
9
9
  from math import ceil
10
10
  from pathlib import Path, PurePosixPath
11
- from typing import TYPE_CHECKING, BinaryIO, TypeVar, cast, overload
11
+ from typing import TYPE_CHECKING, BinaryIO, Literal, TypeVar, cast, overload
12
12
  from uuid import UUID
13
13
 
14
- from contree_client.models import FileSpec
14
+ from contree_client.models import FileSpec, GrepResult
15
15
 
16
16
  from contree_sdk._internals.io.operation_waiter import MAIN_SPID, OutputChunk
17
17
  from contree_sdk._internals.io.typing import INPUT_TYPES, OUTPUT_REQUEST_TYPES, OUTPUT_TYPES
@@ -379,6 +379,30 @@ class _ImageLikeBase:
379
379
  )
380
380
  return result
381
381
 
382
+ async def _grep(
383
+ self,
384
+ pattern: str | Sequence[str],
385
+ *,
386
+ path: str | Sequence[str] | None = None,
387
+ glob: str | Sequence[str] | None = None,
388
+ max_count: int | None = None,
389
+ max_total: int | None = None,
390
+ case: Literal["sensitive", "insensitive", "smart"] | None = None,
391
+ before: int | None = None,
392
+ after: int | None = None,
393
+ ) -> GrepResult:
394
+ return await self._client._api.inspect_image_grep(
395
+ await self._resolved_uuid(),
396
+ pattern,
397
+ path=path,
398
+ glob=glob,
399
+ max_count=max_count,
400
+ max_total=max_total,
401
+ case=case,
402
+ before=before,
403
+ after=after,
404
+ )
405
+
382
406
  async def _read_file(self, path: str | PurePosixPath) -> bytes:
383
407
  return await self._client._api.inspect_image_download(await self._resolved_uuid(), str(path))
384
408
 
@@ -1,8 +1,10 @@
1
1
  from __future__ import annotations
2
2
 
3
- from collections.abc import Iterator
3
+ from collections.abc import Iterator, Sequence
4
4
  from pathlib import Path, PurePosixPath
5
- from typing import TypeVar
5
+ from typing import Literal, TypeVar
6
+
7
+ from contree_client.models import GrepResult
6
8
 
7
9
  from contree_sdk._internals.io.operation_waiter import OutputChunk
8
10
  from contree_sdk._internals.io.typing import INPUT_TYPES, OUTPUT_REQUEST_TYPES
@@ -47,6 +49,47 @@ class _ImageLikeSync(_ImageLikeBase):
47
49
  """
48
50
  return coro_sync(self._ls(path, ImageFileSync, ImageDirectorySync))
49
51
 
52
+ def grep(
53
+ self,
54
+ pattern: str | Sequence[str],
55
+ *,
56
+ path: str | Sequence[str] | None = None,
57
+ glob: str | Sequence[str] | None = None,
58
+ max_count: int | None = None,
59
+ max_total: int | None = None,
60
+ case: Literal["sensitive", "insensitive", "smart"] | None = None,
61
+ before: int | None = None,
62
+ after: int | None = None,
63
+ ) -> GrepResult:
64
+ """Search file contents in the image.
65
+
66
+ Args:
67
+ pattern: Search pattern or patterns.
68
+ path: Path or paths to search. Defaults to the image root.
69
+ glob: Glob filter or filters.
70
+ max_count: Maximum matches per file.
71
+ max_total: Maximum matches across all files.
72
+ case: Case matching mode.
73
+ before: Number of context lines before each match.
74
+ after: Number of context lines after each match.
75
+
76
+ Returns:
77
+ Typed grep result with matches and truncation status.
78
+
79
+ """
80
+ return coro_sync(
81
+ self._grep(
82
+ pattern,
83
+ path=path,
84
+ glob=glob,
85
+ max_count=max_count,
86
+ max_total=max_total,
87
+ case=case,
88
+ before=before,
89
+ after=after,
90
+ )
91
+ )
92
+
50
93
  def download(self, image_path: str | PurePosixPath, local_path: str | Path | None = None) -> Path | None:
51
94
  """Download a file from the image to local filesystem.
52
95
 
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.4
1
+ Metadata-Version: 2.5
2
2
  Name: contree-sdk
3
- Version: 0.4.0.dev3
3
+ Version: 0.4.0.dev5
4
4
  Summary: SDK for ConTree container runtime with versioned filesystem state
5
5
  License: Apache-2.0
6
6
  License-File: LICENSE
@@ -16,7 +16,7 @@ Requires-Python: <3.15,>=3.10
16
16
  Requires-Dist: aiofiles
17
17
  Requires-Dist: async-timeout; python_version < '3.11'
18
18
  Requires-Dist: cattrs
19
- Requires-Dist: contree-client~=0.2.0
19
+ Requires-Dist: contree-client~=0.2.1
20
20
  Requires-Dist: strenum
21
21
  Requires-Dist: typing-extensions; python_version < '3.13'
22
22
  Provides-Extra: aiohttp
@@ -8,7 +8,7 @@ contree_sdk/_internals/client/provider.py,sha256=n2-fv0SjPfn1652DNn3vlsIwQDNnn-3
8
8
  contree_sdk/_internals/client/transport.py,sha256=6Vu8wW8KL4MQNAouLFDbQVLGXOs2apAYz6PBWbK0MuE,4823
9
9
  contree_sdk/_internals/io/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
10
  contree_sdk/_internals/io/codecs.py,sha256=qwJaP1mPo-o-7OBMkcbND1eVT4aB0c1C_YcaG9xQJjs,782
11
- contree_sdk/_internals/io/operation_waiter.py,sha256=LvQwmWONGlB6bcGGxv5zKPLXtql7rbNIJdjoKavLgks,10702
11
+ contree_sdk/_internals/io/operation_waiter.py,sha256=Sfn10qi8e-Qvc4D7-UJuRk9hQjTyP0Kizw5M7By5ydA,11478
12
12
  contree_sdk/_internals/io/typing.py,sha256=rRQ8AKWXu-aOW9syYN8XQZEofqaM4NzbOyuwzOL5Si4,1739
13
13
  contree_sdk/_internals/io/wiring.py,sha256=wyWquuoZgUdE85VCJBBKo6lqTikSEU6IH0IzwBonTyQ,3433
14
14
  contree_sdk/_internals/io/writer_wrapper.py,sha256=ELLPkvA74sDYJKyU6y3qjGnRmJiDx-RXv6Otp9L7mYk,2490
@@ -28,7 +28,7 @@ contree_sdk/langchain/sandbox.py,sha256=dy4MgMMVzDvsfR353hB7eOHUTBeS6bxUnl2CStL3
28
28
  contree_sdk/sdk/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
29
29
  contree_sdk/sdk/client/__init__.py,sha256=4_tscZTYTtQ2wd8bEaGqJEDBY0kZ30Z6axS5IRiAkog,98
30
30
  contree_sdk/sdk/client/_async.py,sha256=urdvKAjLFQwRHjsaJ57V1ZHR_IQjY1xRHUuNMaIlCaQ,1298
31
- contree_sdk/sdk/client/_base.py,sha256=HWGeeeoDir9rn3Z1kAVKS25JJ4hBtdsQJFn5cKi8nR4,8679
31
+ contree_sdk/sdk/client/_base.py,sha256=WUyQ47EvFNJkznznoX8IfvYR1uZKI6eWojz0yO_mU6E,8167
32
32
  contree_sdk/sdk/client/_sync.py,sha256=_YAv7pgZlGubt-GRTk3cVv_fgGhWsruL53ecpOiaj4c,1385
33
33
  contree_sdk/sdk/exceptions/__init__.py,sha256=s6HQmYd8gOESEHpfSXQGg88-LR6gKCqWtfV0O43XvDw,1373
34
34
  contree_sdk/sdk/exceptions/api.py,sha256=g2nKi1uA2iVNj6PbTtkN59ecLcfGQX99VyLVq8ov9tQ,1579
@@ -57,9 +57,9 @@ contree_sdk/sdk/objects/image_fs/_async.py,sha256=aREtHK3H3Wo4uRIOmMvInIKHRkDwZq
57
57
  contree_sdk/sdk/objects/image_fs/_base.py,sha256=K07WZ75dHNYVsS-PHVM4ha8z8EcSBFdRra2LAgrcv7I,1094
58
58
  contree_sdk/sdk/objects/image_fs/_sync.py,sha256=cJUkPd00d8B6rZDFBce3GlK-4RynE569g9uZjj6FR3k,778
59
59
  contree_sdk/sdk/objects/image_like/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
60
- contree_sdk/sdk/objects/image_like/_async.py,sha256=hqcPlp7z3T3OuAWLE7m7Nrj-W6pGDmOjOb4eNx01YIg,2366
61
- contree_sdk/sdk/objects/image_like/_base.py,sha256=3v7j-7JToq3Gz6s3Nq6LSHh2PsexV86rYqQU7OgHgWg,17290
62
- contree_sdk/sdk/objects/image_like/_sync.py,sha256=zWTtD1pjz8h8fPWC8TGj9juoH_mwmtlz8ytPU1JO8B4,4756
60
+ contree_sdk/sdk/objects/image_like/_async.py,sha256=izss4GGbvkqlgiXmEkQ5LR4sFbgZJI4U1LNddgh1UMA,3692
61
+ contree_sdk/sdk/objects/image_like/_base.py,sha256=Ye4a93FZzZ-Z29HPoByzFrEpbyGVY3wDjg_f0qBiueM,18062
62
+ contree_sdk/sdk/objects/image_like/_sync.py,sha256=Lloh9usg55Vk-Nva14vjpkelHuOIKBLZ9Cf9Uoy7yns,6139
63
63
  contree_sdk/sdk/objects/image_like/result.py,sha256=imcmFNquy7fczl-y_lZ2kXFtMNTds98JdY_pF43qHA8,1089
64
64
  contree_sdk/sdk/objects/image_like/state.py,sha256=UUFOLu2fdbIkxw7f77iVtz8FGH_o5U-AcPxbUGetF9s,2125
65
65
  contree_sdk/sdk/objects/session/__init__.py,sha256=ws5Q7tr1GBsxujaWaaVVnKVilw-_nSPtsgV452Yd7Qg,188
@@ -81,7 +81,7 @@ contree_sdk/utils/models/file.py,sha256=9izWiiCiH1t2AU6GgY0pHaIztHDVdjVoUZQP3NOL
81
81
  contree_sdk/utils/models/image.py,sha256=bhFHRO8FTKKtCwU2efxNuST7rAnr5sMeP3jAS_BQcgc,88
82
82
  contree_sdk/utils/models/operation.py,sha256=0hQi-IGbAP6_Ao32YBJHJ9KwXK2unHWpRLjmlacu0ow,523
83
83
  contree_sdk/utils/models/stream.py,sha256=Ckorhu_-5dVQPfaaFpr7HVjoN00a_c9d7fqTisOyz3c,315
84
- contree_sdk-0.4.0.dev3.dist-info/METADATA,sha256=p6cT_JuhKVNmFPyFjK-ZF8keXlDy-w_FVA62XDAmrEI,17486
85
- contree_sdk-0.4.0.dev3.dist-info/WHEEL,sha256=lCkmxWfQsSc9CfIClYeavTdQeEX2toPqufh9gI35EQA,87
86
- contree_sdk-0.4.0.dev3.dist-info/licenses/LICENSE,sha256=DVQuDIgE45qn836wDaWnYhSdxoLXgpRRKH4RuTjpRZQ,10174
87
- contree_sdk-0.4.0.dev3.dist-info/RECORD,,
84
+ contree_sdk-0.4.0.dev5.dist-info/METADATA,sha256=gZcIEXVfP02J3zfM5qHfpePqM5z9vwd9J21jHvmSoGw,17486
85
+ contree_sdk-0.4.0.dev5.dist-info/WHEEL,sha256=zOwg4jB6zX2kU910N-cMawjivD6tO8NEWvE12je1bVk,87
86
+ contree_sdk-0.4.0.dev5.dist-info/licenses/LICENSE,sha256=DVQuDIgE45qn836wDaWnYhSdxoLXgpRRKH4RuTjpRZQ,10174
87
+ contree_sdk-0.4.0.dev5.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: hatchling 1.31.0
2
+ Generator: hatchling 1.32.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any