ap-client 0.8.1.dev1__tar.gz → 0.8.1.dev2__tar.gz
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.
- {ap_client-0.8.1.dev1 → ap_client-0.8.1.dev2}/PKG-INFO +1 -1
- {ap_client-0.8.1.dev1 → ap_client-0.8.1.dev2}/ap_client/api.py +38 -17
- {ap_client-0.8.1.dev1 → ap_client-0.8.1.dev2}/ap_client/canonical_get.py +68 -42
- {ap_client-0.8.1.dev1 → ap_client-0.8.1.dev2}/ap_client/canonical_put.py +229 -115
- {ap_client-0.8.1.dev1 → ap_client-0.8.1.dev2}/ap_client/cluster_layout_fetcher.py +5 -11
- {ap_client-0.8.1.dev1 → ap_client-0.8.1.dev2}/ap_client/cluster_region_resolver.py +12 -15
- {ap_client-0.8.1.dev1 → ap_client-0.8.1.dev2}/ap_client/fs_commands.py +254 -103
- {ap_client-0.8.1.dev1 → ap_client-0.8.1.dev2}/ap_client/fs_storage.py +52 -13
- {ap_client-0.8.1.dev1 → ap_client-0.8.1.dev2}/ap_client/instance_commands.py +281 -26
- {ap_client-0.8.1.dev1 → ap_client-0.8.1.dev2}/ap_client/irepo_sdk.py +195 -63
- {ap_client-0.8.1.dev1 → ap_client-0.8.1.dev2}/ap_client/ossutil_io.py +32 -10
- {ap_client-0.8.1.dev1 → ap_client-0.8.1.dev2}/ap_client/replica_policy.py +8 -8
- {ap_client-0.8.1.dev1 → ap_client-0.8.1.dev2}/ap_client/shared_adapter.py +327 -168
- {ap_client-0.8.1.dev1 → ap_client-0.8.1.dev2}/ap_client/shared_commands.py +231 -101
- {ap_client-0.8.1.dev1 → ap_client-0.8.1.dev2}/ap_client/tool_manifest.py +13 -9
- {ap_client-0.8.1.dev1 → ap_client-0.8.1.dev2}/pyproject.toml +1 -1
- {ap_client-0.8.1.dev1 → ap_client-0.8.1.dev2}/ap_client/__init__.py +0 -0
- {ap_client-0.8.1.dev1 → ap_client-0.8.1.dev2}/ap_client/akpool_commands.py +0 -0
- {ap_client-0.8.1.dev1 → ap_client-0.8.1.dev2}/ap_client/cli.py +0 -0
- {ap_client-0.8.1.dev1 → ap_client-0.8.1.dev2}/ap_client/cli_help.py +0 -0
- {ap_client-0.8.1.dev1 → ap_client-0.8.1.dev2}/ap_client/cli_submission_defaults.py +0 -0
- {ap_client-0.8.1.dev1 → ap_client-0.8.1.dev2}/ap_client/config.py +0 -0
- {ap_client-0.8.1.dev1 → ap_client-0.8.1.dev2}/ap_client/dataset_commands.py +0 -0
- {ap_client-0.8.1.dev1 → ap_client-0.8.1.dev2}/ap_client/dataset_name.py +0 -0
- {ap_client-0.8.1.dev1 → ap_client-0.8.1.dev2}/ap_client/dataset_register.py +0 -0
- {ap_client-0.8.1.dev1 → ap_client-0.8.1.dev2}/ap_client/dfs_commands.py +0 -0
- {ap_client-0.8.1.dev1 → ap_client-0.8.1.dev2}/ap_client/exporter.py +0 -0
- {ap_client-0.8.1.dev1 → ap_client-0.8.1.dev2}/ap_client/fs_transfer.py +0 -0
- {ap_client-0.8.1.dev1 → ap_client-0.8.1.dev2}/ap_client/instance_options.py +0 -0
- {ap_client-0.8.1.dev1 → ap_client-0.8.1.dev2}/ap_client/managed_ak.py +0 -0
- {ap_client-0.8.1.dev1 → ap_client-0.8.1.dev2}/ap_client/manifest_view.py +0 -0
- {ap_client-0.8.1.dev1 → ap_client-0.8.1.dev2}/ap_client/ossutil_hash.py +0 -0
- {ap_client-0.8.1.dev1 → ap_client-0.8.1.dev2}/ap_client/profile_cascade_all.py +0 -0
- {ap_client-0.8.1.dev1 → ap_client-0.8.1.dev2}/ap_client/profile_cascade_cli.py +0 -0
- {ap_client-0.8.1.dev1 → ap_client-0.8.1.dev2}/ap_client/profile_cascade_display.py +0 -0
- {ap_client-0.8.1.dev1 → ap_client-0.8.1.dev2}/ap_client/profile_cascade_state.py +0 -0
- {ap_client-0.8.1.dev1 → ap_client-0.8.1.dev2}/ap_client/profile_commands.py +0 -0
- {ap_client-0.8.1.dev1 → ap_client-0.8.1.dev2}/ap_client/profile_diagnostics.py +0 -0
- {ap_client-0.8.1.dev1 → ap_client-0.8.1.dev2}/ap_client/profile_display.py +0 -0
- {ap_client-0.8.1.dev1 → ap_client-0.8.1.dev2}/ap_client/profile_references.py +0 -0
- {ap_client-0.8.1.dev1 → ap_client-0.8.1.dev2}/ap_client/repo_read_guard.py +0 -0
- {ap_client-0.8.1.dev1 → ap_client-0.8.1.dev2}/ap_client/share_api.py +0 -0
- {ap_client-0.8.1.dev1 → ap_client-0.8.1.dev2}/ap_client/split_publish.py +0 -0
- {ap_client-0.8.1.dev1 → ap_client-0.8.1.dev2}/ap_client/submission_metadata.py +0 -0
- {ap_client-0.8.1.dev1 → ap_client-0.8.1.dev2}/ap_client/tbb.py +0 -0
- {ap_client-0.8.1.dev1 → ap_client-0.8.1.dev2}/ap_client/waiter.py +0 -0
|
@@ -461,8 +461,9 @@ class _DeadlineWatchdog:
|
|
|
461
461
|
pass
|
|
462
462
|
|
|
463
463
|
|
|
464
|
-
def _read_bounded_control_bytes(
|
|
465
|
-
|
|
464
|
+
def _read_bounded_control_bytes(
|
|
465
|
+
resp, limit: int = _DEFAULT_CONTROL_BYTES, deadline: Optional[float] = None
|
|
466
|
+
) -> bytes:
|
|
466
467
|
"""Stream one bounded canonical control response via public requests APIs.
|
|
467
468
|
|
|
468
469
|
Content-Length pre-check plus streamed chunk reads keep memory at
|
|
@@ -477,7 +478,7 @@ def _read_bounded_control_bytes(resp, limit: int = _DEFAULT_CONTROL_BYTES,
|
|
|
477
478
|
raise CanonicalControlAPIError("deadline")
|
|
478
479
|
length = resp.headers.get("Content-Length")
|
|
479
480
|
if isinstance(length, str) and length.isascii() and length.isdecimal():
|
|
480
|
-
digits, cap = length.lstrip(
|
|
481
|
+
digits, cap = length.lstrip("0") or "0", str(limit)
|
|
481
482
|
if len(digits) > len(cap) or (len(digits) == len(cap) and digits > cap):
|
|
482
483
|
raise CanonicalControlAPIError("response_limit", status_code=resp.status_code)
|
|
483
484
|
data = bytearray()
|
|
@@ -491,7 +492,8 @@ def _read_bounded_control_bytes(resp, limit: int = _DEFAULT_CONTROL_BYTES,
|
|
|
491
492
|
raise CanonicalControlAPIError("deadline")
|
|
492
493
|
if len(block) > limit - len(data):
|
|
493
494
|
raise CanonicalControlAPIError(
|
|
494
|
-
"response_limit", status_code=resp.status_code
|
|
495
|
+
"response_limit", status_code=resp.status_code
|
|
496
|
+
)
|
|
495
497
|
data.extend(block)
|
|
496
498
|
except CanonicalControlAPIError:
|
|
497
499
|
raise
|
|
@@ -508,8 +510,9 @@ def _read_bounded_control_bytes(resp, limit: int = _DEFAULT_CONTROL_BYTES,
|
|
|
508
510
|
return bytes(data)
|
|
509
511
|
|
|
510
512
|
|
|
511
|
-
def _bounded_response_prefix(
|
|
512
|
-
|
|
513
|
+
def _bounded_response_prefix(
|
|
514
|
+
resp, limit: int = _DEFAULT_CONTROL_BYTES, deadline: Optional[float] = None
|
|
515
|
+
) -> bytes:
|
|
513
516
|
"""Read one bounded first block of an error body for typed classification.
|
|
514
517
|
|
|
515
518
|
Oversized bodies contribute only this bounded prefix; their real status
|
|
@@ -749,8 +752,14 @@ class APIClient:
|
|
|
749
752
|
# Bounded canonical projection (P1 fix): a finite per-request duration
|
|
750
753
|
# owns ONE deadline across this request's retries, never per attempt,
|
|
751
754
|
# so a slow byte-drip response cannot outlive its budget.
|
|
752
|
-
if
|
|
753
|
-
|
|
755
|
+
if (
|
|
756
|
+
_bounded
|
|
757
|
+
and deadline is None
|
|
758
|
+
and isinstance(timeout, (int, float))
|
|
759
|
+
and not isinstance(timeout, bool)
|
|
760
|
+
and math.isfinite(timeout)
|
|
761
|
+
and timeout >= 0
|
|
762
|
+
):
|
|
754
763
|
deadline = time.monotonic() + timeout
|
|
755
764
|
verbose = self.config.verbose
|
|
756
765
|
max_attempts = 1 if _single_attempt else max(1, self.config.http_max_attempts)
|
|
@@ -837,13 +846,19 @@ class APIClient:
|
|
|
837
846
|
resp_is_error = resp is not None and not 200 <= resp.status_code < 300
|
|
838
847
|
if resp_is_error:
|
|
839
848
|
resp.close()
|
|
840
|
-
reason =
|
|
849
|
+
reason = (
|
|
850
|
+
"deadline"
|
|
851
|
+
if (deadline is not None and time.monotonic() >= deadline)
|
|
852
|
+
else "network"
|
|
853
|
+
)
|
|
841
854
|
raise CanonicalControlAPIError(reason) from None
|
|
842
855
|
if _single_attempt and resp is not None:
|
|
843
856
|
status = resp.status_code
|
|
844
857
|
resp.close()
|
|
845
858
|
if not 200 <= status < 300:
|
|
846
|
-
raise APIError(
|
|
859
|
+
raise APIError(
|
|
860
|
+
status, "Incomplete HTTP error response", request_id, resp
|
|
861
|
+
) from None
|
|
847
862
|
if deadline is not None:
|
|
848
863
|
_manifest_budget_remaining(deadline)
|
|
849
864
|
duration_ms = (time.perf_counter() - start) * 1000
|
|
@@ -891,7 +906,11 @@ class APIClient:
|
|
|
891
906
|
# auth headers were never sent there. Refuse.
|
|
892
907
|
raise CanonicalControlAPIError("redirect", status_code=resp.status_code)
|
|
893
908
|
if not 200 <= resp.status_code < 300:
|
|
894
|
-
if
|
|
909
|
+
if (
|
|
910
|
+
read_only
|
|
911
|
+
and attempt < max_attempts
|
|
912
|
+
and _is_retryable_status(resp.status_code)
|
|
913
|
+
):
|
|
895
914
|
delay = _retry_delay(attempt, resp, max_wait=max_wait)
|
|
896
915
|
if not math.isfinite(delay):
|
|
897
916
|
delay = _retry_delay(attempt)
|
|
@@ -912,12 +931,15 @@ class APIClient:
|
|
|
912
931
|
# report the deadline, never a late http_error.
|
|
913
932
|
raise CanonicalControlAPIError("deadline")
|
|
914
933
|
prefix = _bounded_response_prefix(
|
|
915
|
-
resp, _DEFAULT_CONTROL_BYTES, deadline=deadline
|
|
934
|
+
resp, _DEFAULT_CONTROL_BYTES, deadline=deadline
|
|
935
|
+
)
|
|
916
936
|
code = _bounded_error_biz_code(prefix)
|
|
917
937
|
raise CanonicalControlAPIError(
|
|
918
|
-
"http_error", status_code=resp.status_code, biz_code=code
|
|
938
|
+
"http_error", status_code=resp.status_code, biz_code=code
|
|
939
|
+
)
|
|
919
940
|
data = _read_bounded_control_bytes(
|
|
920
|
-
resp, _DEFAULT_CONTROL_BYTES, deadline=deadline
|
|
941
|
+
resp, _DEFAULT_CONTROL_BYTES, deadline=deadline
|
|
942
|
+
)
|
|
921
943
|
if not data:
|
|
922
944
|
resp.close()
|
|
923
945
|
return None
|
|
@@ -932,8 +954,7 @@ class APIClient:
|
|
|
932
954
|
except (ValueError, RecursionError):
|
|
933
955
|
refusal = "invalid_json"
|
|
934
956
|
if refusal is not None:
|
|
935
|
-
raise CanonicalControlAPIError(
|
|
936
|
-
refusal, status_code=resp.status_code)
|
|
957
|
+
raise CanonicalControlAPIError(refusal, status_code=resp.status_code)
|
|
937
958
|
if deadline is not None and time.monotonic() >= deadline:
|
|
938
959
|
# Refuse a late success; the budget is already spent.
|
|
939
960
|
raise CanonicalControlAPIError("deadline")
|
|
@@ -4096,7 +4117,7 @@ def _response_error_detail(resp: requests.Response) -> Any:
|
|
|
4096
4117
|
inner = err_data["detail"]
|
|
4097
4118
|
if isinstance(inner, dict):
|
|
4098
4119
|
return inner # FastAPI detail=dict:内层即结构化错误体
|
|
4099
|
-
return inner
|
|
4120
|
+
return inner # detail=str:旧语义
|
|
4100
4121
|
if "code" in err_data:
|
|
4101
4122
|
# Go 裸信封 {code, message, data}:保留完整结构化错误体
|
|
4102
4123
|
return err_data
|
|
@@ -5,11 +5,12 @@ This module owns the invocation's absolute budget, operator input guards,
|
|
|
5
5
|
matching typed results and honest per-file display. It does not replace the
|
|
6
6
|
runtime fs_get entry before the cross-repository integration gates pass.
|
|
7
7
|
"""
|
|
8
|
+
|
|
8
9
|
from __future__ import annotations
|
|
9
10
|
|
|
10
11
|
import math
|
|
11
|
-
from pathlib import Path
|
|
12
12
|
import time
|
|
13
|
+
from pathlib import Path
|
|
13
14
|
from typing import Any, Optional
|
|
14
15
|
|
|
15
16
|
from .canonical_put import _bind_operation_deadline
|
|
@@ -28,9 +29,15 @@ class CanonicalReadOrchestrationError(Exception):
|
|
|
28
29
|
class ReadOutcome:
|
|
29
30
|
"""Presentation result; only a matching SDK verified result is verified."""
|
|
30
31
|
|
|
31
|
-
def __init__(
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
def __init__(
|
|
33
|
+
self,
|
|
34
|
+
mode: str,
|
|
35
|
+
*,
|
|
36
|
+
canonical_key: str = "",
|
|
37
|
+
legacy_profile: str = "",
|
|
38
|
+
verified: bool = False,
|
|
39
|
+
target: Optional[Path] = None,
|
|
40
|
+
):
|
|
34
41
|
self.mode = mode
|
|
35
42
|
self.canonical_key = canonical_key
|
|
36
43
|
self.legacy_profile = legacy_profile
|
|
@@ -58,14 +65,16 @@ def _remaining(absolute: Optional[float]) -> Optional[float]:
|
|
|
58
65
|
remaining = absolute - time.monotonic()
|
|
59
66
|
if remaining <= 0:
|
|
60
67
|
raise CanonicalReadOrchestrationError(
|
|
61
|
-
"budget_exhausted", "the read operation exceeded its time budget"
|
|
68
|
+
"budget_exhausted", "the read operation exceeded its time budget"
|
|
69
|
+
)
|
|
62
70
|
return remaining
|
|
63
71
|
|
|
64
72
|
|
|
65
73
|
def _reader_failure() -> None:
|
|
66
74
|
# No repr of a resolution/result: they can contain signed URLs.
|
|
67
75
|
raise CanonicalReadOrchestrationError(
|
|
68
|
-
"reader_failure", "the SDK reader returned an inconsistent typed result"
|
|
76
|
+
"reader_failure", "the SDK reader returned an inconsistent typed result"
|
|
77
|
+
)
|
|
69
78
|
|
|
70
79
|
|
|
71
80
|
class _ReadProgress:
|
|
@@ -123,31 +132,40 @@ def get_user_data(
|
|
|
123
132
|
"""
|
|
124
133
|
if reader is None:
|
|
125
134
|
raise CanonicalReadOrchestrationError(
|
|
126
|
-
"reader_missing", "the typed user-data SDK reader is not available"
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
135
|
+
"reader_missing", "the typed user-data SDK reader is not available"
|
|
136
|
+
)
|
|
137
|
+
if any(not isinstance(v, str) or not v for v in (owner, relative_path, cluster)) or any(
|
|
138
|
+
char.isspace() for value in (owner, cluster) for char in value
|
|
139
|
+
):
|
|
130
140
|
raise CanonicalReadOrchestrationError(
|
|
131
|
-
"invalid_input",
|
|
141
|
+
"invalid_input",
|
|
142
|
+
"owner and cluster must be nonempty without whitespace; relative_path must be nonempty",
|
|
143
|
+
)
|
|
132
144
|
# A relative path is an exact object identity. Leading/trailing spaces are
|
|
133
145
|
# legal bytes and must reach the SDK unchanged; validation rejects aliases
|
|
134
146
|
# instead of silently selecting a different object.
|
|
135
147
|
if deadline is not None and (
|
|
136
|
-
|
|
137
|
-
|
|
148
|
+
isinstance(deadline, bool)
|
|
149
|
+
or not isinstance(deadline, (int, float))
|
|
150
|
+
or not math.isfinite(deadline)
|
|
151
|
+
):
|
|
138
152
|
raise CanonicalReadOrchestrationError(
|
|
139
|
-
"invalid_input", "the read deadline must be a finite absolute monotonic time"
|
|
140
|
-
|
|
141
|
-
|
|
153
|
+
"invalid_input", "the read deadline must be a finite absolute monotonic time"
|
|
154
|
+
)
|
|
155
|
+
if not isinstance(overwrite, bool) or (progress is not None and not isinstance(progress, bool)):
|
|
142
156
|
raise CanonicalReadOrchestrationError(
|
|
143
|
-
"invalid_input", "overwrite and progress must be boolean options"
|
|
157
|
+
"invalid_input", "overwrite and progress must be boolean options"
|
|
158
|
+
)
|
|
144
159
|
if not callable(getattr(reader, "resolve", None)) or not callable(
|
|
145
|
-
|
|
160
|
+
getattr(reader, "download", None)
|
|
161
|
+
):
|
|
146
162
|
_reader_failure()
|
|
147
163
|
|
|
148
164
|
from instance_repo.clients.user_data_reads import (
|
|
149
|
-
CanonicalReadResolution,
|
|
150
|
-
|
|
165
|
+
CanonicalReadResolution,
|
|
166
|
+
LegacyReadResolution,
|
|
167
|
+
LegacyReadResult,
|
|
168
|
+
VerifiedReadResult,
|
|
151
169
|
)
|
|
152
170
|
|
|
153
171
|
_remaining(deadline)
|
|
@@ -155,8 +173,8 @@ def get_user_data(
|
|
|
155
173
|
if transport is not None:
|
|
156
174
|
_bind_operation_deadline(transport, deadline)
|
|
157
175
|
resolution = reader.resolve(
|
|
158
|
-
owner=owner, relative_path=relative_path, cluster=cluster,
|
|
159
|
-
|
|
176
|
+
owner=owner, relative_path=relative_path, cluster=cluster, deadline=_remaining(deadline)
|
|
177
|
+
)
|
|
160
178
|
_remaining(deadline)
|
|
161
179
|
|
|
162
180
|
if type(resolution) is CanonicalReadResolution:
|
|
@@ -170,38 +188,46 @@ def get_user_data(
|
|
|
170
188
|
else:
|
|
171
189
|
_reader_failure()
|
|
172
190
|
if (resolution.owner, resolution.relative_path, resolution.cluster) != (
|
|
173
|
-
|
|
191
|
+
owner,
|
|
192
|
+
relative_path,
|
|
193
|
+
cluster,
|
|
194
|
+
):
|
|
174
195
|
_reader_failure()
|
|
175
196
|
|
|
176
197
|
target = Path(target)
|
|
177
198
|
with _ReadProgress(progress, key, size) as display:
|
|
178
199
|
result = reader.download(
|
|
179
|
-
resolution, target, overwrite=overwrite, deadline=_remaining(deadline)
|
|
200
|
+
resolution, target, overwrite=overwrite, deadline=_remaining(deadline)
|
|
201
|
+
)
|
|
180
202
|
_remaining(deadline)
|
|
181
203
|
if type(resolution) is CanonicalReadResolution:
|
|
182
204
|
if type(result) is not VerifiedReadResult or (
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
205
|
+
result.mode != "canonical"
|
|
206
|
+
or result.canonical_key != resolution.canonical_key
|
|
207
|
+
or result.anchor != resolution.anchor
|
|
208
|
+
or result.sha256_verified != resolution.anchor.sha256
|
|
209
|
+
or type(result.bytes_written) is not int
|
|
210
|
+
or result.bytes_written != size
|
|
211
|
+
or result.target != target
|
|
212
|
+
):
|
|
190
213
|
_reader_failure()
|
|
191
|
-
outcome = ReadOutcome("canonical", canonical_key=key,
|
|
192
|
-
verified=True, target=target)
|
|
214
|
+
outcome = ReadOutcome("canonical", canonical_key=key, verified=True, target=target)
|
|
193
215
|
else:
|
|
194
216
|
if type(result) is not LegacyReadResult or (
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
217
|
+
result.mode != "legacy-unanchored"
|
|
218
|
+
or result.legacy_key != resolution.legacy_key
|
|
219
|
+
or result.unanchored is not True
|
|
220
|
+
or type(result.bytes_written) is not int
|
|
221
|
+
or result.bytes_written != size
|
|
222
|
+
or result.target != target
|
|
223
|
+
):
|
|
201
224
|
_reader_failure()
|
|
202
|
-
outcome = ReadOutcome(
|
|
203
|
-
|
|
204
|
-
|
|
225
|
+
outcome = ReadOutcome(
|
|
226
|
+
"legacy-unanchored",
|
|
227
|
+
legacy_profile=resolution.legacy_profile,
|
|
228
|
+
verified=False,
|
|
229
|
+
target=target,
|
|
230
|
+
)
|
|
205
231
|
_remaining(deadline)
|
|
206
232
|
display.finish()
|
|
207
233
|
# Display completion/cleanup belongs to this invocation too. Never report
|