kf-sdk 3.0.2__tar.gz → 3.0.3__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.
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/.gitignore +5 -1
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/Cargo.lock +1 -1
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/Cargo.toml +1 -1
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/PKG-INFO +6 -5
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/README.en.md +5 -4
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/README.md +5 -4
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/docs/BuildAndPublish.md +1 -1
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/docs/Datasets.md +3 -1
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/docs/GettingStarted.md +1 -1
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/docs/README.md +1 -1
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/docs/ru/BuildAndPublish.md +1 -1
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/docs/ru/GettingStarted.md +1 -1
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/docs/ru/README.md +1 -1
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/kappa_apk.pyi +12 -1
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/src/client.rs +161 -105
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/src/datasets/datasets.rs +5 -3
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/src/models/datasets_model.rs +26 -0
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/.dockerignore +0 -0
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/.github/workflows/ci.yml +0 -0
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/.gitlab-ci.yml +0 -0
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/Dockerfile +0 -0
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/LICENSE.md +0 -0
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/build_wheel.sh +0 -0
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/code_examples/README.md +0 -0
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/code_examples/bulk_upload.py +0 -0
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/code_examples/dataset_lifecycle_example.py +0 -0
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/code_examples/dataset_operations_example.py +0 -0
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/code_examples/http_client_authentication_example.py +0 -0
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/code_examples/mnist_kappa_training_example.py +0 -0
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/code_examples/requirements.txt +0 -0
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/code_examples/setup_venv.sh +0 -0
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/code_examples/upgrade_venv.sh +0 -0
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/code_examples/upload_kappa_helpers.py +0 -0
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/code_examples/upload_torchvision_to_kappa_example.py +0 -0
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/docker-compose.yml +0 -0
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/docs/Benchmarks.md +0 -0
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/docs/DataModels.md +0 -0
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/docs/KappaApkClient.md +0 -0
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/docs/LoadersAndTransforms.md +0 -0
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/docs/ru/Benchmarks.md +0 -0
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/docs/ru/DataModels.md +0 -0
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/docs/ru/Datasets.md +0 -0
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/docs/ru/KappaApkClient.md +0 -0
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/docs/ru/LoadersAndTransforms.md +0 -0
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/kappa-eng.png +0 -0
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/kappa-rus.png +0 -0
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/pyproject.toml +0 -0
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/src/benchmarks/benchmarks.rs +0 -0
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/src/benchmarks/mod.rs +0 -0
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/src/benchmarks/verifications.rs +0 -0
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/src/compat.rs +0 -0
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/src/datasets/dataloader_helper.rs +0 -0
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/src/datasets/kappa_dataloader.rs +0 -0
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/src/datasets/mod.rs +0 -0
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/src/lib.rs +0 -0
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/src/ml_tags.rs +0 -0
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/src/models/benchmarks_model.rs +0 -0
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/src/models/login_models.rs +0 -0
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/src/models/mod.rs +0 -0
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/src/models/users_model.rs +0 -0
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/src/models_api.rs +0 -0
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/src/traits.rs +0 -0
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/src/transforms/audio.rs +0 -0
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/src/transforms/mod.rs +0 -0
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/src/transforms/text.rs +0 -0
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/src/transforms/vision.rs +0 -0
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/src/upload_limits.rs +0 -0
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/src/users/mod.rs +0 -0
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/src/users/users.rs +0 -0
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/src/utils/file_utils.rs +0 -0
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/src/utils/git_utils.rs +0 -0
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/src/utils/metric_utils.rs +0 -0
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/src/utils/mod.rs +0 -0
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/src/utils/python_json.rs +0 -0
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/src/utils/zip_utils.rs +0 -0
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/tests/fixtures/README.md +0 -0
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/tests/fixtures/benchmark_verification_files.json +0 -0
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/tests/fixtures/benchmark_verification_response.json +0 -0
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/tests/fixtures/dataset_labels_string.json +0 -0
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/tests/fixtures/dataset_labels_wrapped.json +0 -0
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/tests/fixtures/user_profile_no_org.json +0 -0
- {kf_sdk-3.0.2 → kf_sdk-3.0.3}/tests/fixtures/user_profile_with_org.json +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: kf-sdk
|
|
3
|
-
Version: 3.0.
|
|
3
|
+
Version: 3.0.3
|
|
4
4
|
Classifier: Development Status :: 4 - Beta
|
|
5
5
|
Classifier: Intended Audience :: Developers
|
|
6
6
|
Classifier: Intended Audience :: Science/Research
|
|
@@ -27,8 +27,9 @@ Project-URL: Repository, https://github.com/nsu-ai/kappa
|
|
|
27
27
|
|
|
28
28
|
[](https://github.com/nsu-ai/kappa/blob/main/LICENSE.md)
|
|
29
29
|

|
|
30
|
-
[](https://pypi.org/project/kf-sdk/)
|
|
31
|
+
[](https://pypi.org/project/kf-sdk/)
|
|
32
|
+
[](https://github.com/nsu-ai/kappa/releases)
|
|
32
33
|
|
|
33
34
|
Python-клиент SDK для **Kappa-framework** — самостоятельно развёртываемой микросервисной платформы для исследовательских ML/AI рабочих процессов.
|
|
34
35
|
|
|
@@ -38,7 +39,7 @@ Python-клиент SDK для **Kappa-framework** — самостоятель
|
|
|
38
39
|
|
|
39
40
|
| | |
|
|
40
41
|
|---|---|
|
|
41
|
-
| **Версия** | 3.0.
|
|
42
|
+
| **Версия** | 3.0.3 |
|
|
42
43
|
| **Требует Kappa** | **≥ 2.10.0** (`min_backend_version()`) |
|
|
43
44
|
| **Python** | 3.9+ |
|
|
44
45
|
| **Rust edition** | 2024 |
|
|
@@ -46,7 +47,7 @@ Python-клиент SDK для **Kappa-framework** — самостоятель
|
|
|
46
47
|
|
|
47
48
|
---
|
|
48
49
|
|
|
49
|
-
# Каппа — ϰ-фреймворк управления датасетами и моделями, версия 3.0.
|
|
50
|
+
# Каппа — ϰ-фреймворк управления датасетами и моделями, версия 3.0.3
|
|
50
51
|
|
|
51
52
|
Каппа — набор концептуального и программного обеспечения (фреймворк) для осуществления функций курации датасетов и моделей ([Исследовательский центр](https://nsu.ru/n/ai-center) в сфере искусственного интеллекта по направлению «Строительство и городская среда» НГУ, Новосибирск).
|
|
52
53
|
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://github.com/nsu-ai/kappa/blob/main/LICENSE.md)
|
|
4
4
|

|
|
5
|
-
[](https://pypi.org/project/kf-sdk/)
|
|
6
|
+
[](https://pypi.org/project/kf-sdk/)
|
|
7
|
+
[](https://github.com/nsu-ai/kappa/releases)
|
|
7
8
|
|
|
8
9
|
Python client SDK for **Kappa-framework** — a self-hosted microservices platform for ML/AI research workflows.
|
|
9
10
|
|
|
@@ -13,7 +14,7 @@ Built with Rust + [PyO3](https://pyo3.rs). **PyPI:** `kf-sdk` · **import:** `im
|
|
|
13
14
|
|
|
14
15
|
| | |
|
|
15
16
|
|---|---|
|
|
16
|
-
| **Version** | 3.0.
|
|
17
|
+
| **Version** | 3.0.3 |
|
|
17
18
|
| **Requires Kappa** | **≥ 2.10.0** (`min_backend_version()`) |
|
|
18
19
|
| **Python** | 3.9+ |
|
|
19
20
|
| **Rust edition** | 2024 |
|
|
@@ -21,7 +22,7 @@ Built with Rust + [PyO3](https://pyo3.rs). **PyPI:** `kf-sdk` · **import:** `im
|
|
|
21
22
|
|
|
22
23
|
---
|
|
23
24
|
|
|
24
|
-
# Kappa — ϰ-framework for dataset and model management, version 3.0.
|
|
25
|
+
# Kappa — ϰ-framework for dataset and model management, version 3.0.3
|
|
25
26
|
|
|
26
27
|
Kappa is a conceptual and software framework for dataset curation and model lifecycle management, developed at the [AI Research Center](https://nsu.ru/n/ai-center) for Construction and Urban Environment, Novosibirsk State University.
|
|
27
28
|
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://github.com/nsu-ai/kappa/blob/main/LICENSE.md)
|
|
4
4
|

|
|
5
|
-
[](https://pypi.org/project/kf-sdk/)
|
|
6
|
+
[](https://pypi.org/project/kf-sdk/)
|
|
7
|
+
[](https://github.com/nsu-ai/kappa/releases)
|
|
7
8
|
|
|
8
9
|
Python-клиент SDK для **Kappa-framework** — самостоятельно развёртываемой микросервисной платформы для исследовательских ML/AI рабочих процессов.
|
|
9
10
|
|
|
@@ -13,7 +14,7 @@ Python-клиент SDK для **Kappa-framework** — самостоятель
|
|
|
13
14
|
|
|
14
15
|
| | |
|
|
15
16
|
|---|---|
|
|
16
|
-
| **Версия** | 3.0.
|
|
17
|
+
| **Версия** | 3.0.3 |
|
|
17
18
|
| **Требует Kappa** | **≥ 2.10.0** (`min_backend_version()`) |
|
|
18
19
|
| **Python** | 3.9+ |
|
|
19
20
|
| **Rust edition** | 2024 |
|
|
@@ -21,7 +22,7 @@ Python-клиент SDK для **Kappa-framework** — самостоятель
|
|
|
21
22
|
|
|
22
23
|
---
|
|
23
24
|
|
|
24
|
-
# Каппа — ϰ-фреймворк управления датасетами и моделями, версия 3.0.
|
|
25
|
+
# Каппа — ϰ-фреймворк управления датасетами и моделями, версия 3.0.3
|
|
25
26
|
|
|
26
27
|
Каппа — набор концептуального и программного обеспечения (фреймворк) для осуществления функций курации датасетов и моделей ([Исследовательский центр](https://nsu.ru/n/ai-center) в сфере искусственного интеллекта по направлению «Строительство и городская среда» НГУ, Новосибирск).
|
|
27
28
|
|
|
@@ -80,7 +80,7 @@ CIBW_ARCHS_LINUX="x86_64 aarch64" cibuildwheel --output-dir dist
|
|
|
80
80
|
| [`.github/workflows/ci.yml`](../.github/workflows/ci.yml) | push / PR | `cargo test`, clippy, maturin wheels (py3.9–3.13), sdist |
|
|
81
81
|
| [`.github/workflows/publish.yml`](../.github/workflows/publish.yml) | Release / manual | sdist + cibuildwheel on Linux/macOS/Windows → PyPI (Linux uses QEMU for aarch64) |
|
|
82
82
|
|
|
83
|
-
**PyPI trusted publishing:** configure environment `pypi` on GitHub, create a Release tag (e.g. `v3.0.
|
|
83
|
+
**PyPI trusted publishing:** configure environment `pypi` on GitHub, create a Release tag (e.g. `v3.0.3`).
|
|
84
84
|
|
|
85
85
|
---
|
|
86
86
|
|
|
@@ -109,7 +109,9 @@ Async job API — same flow as the React bulk dialog. Full script: [`code_exampl
|
|
|
109
109
|
| CSV | **2 GB** client | Backend default is **50 MB** (`BULK_UPLOAD_MAX_CSV_BYTES`); raise that env for larger CSVs |
|
|
110
110
|
| Archive `.zip` | **50 GB** | `upload_type="archive"` + `archive_layout` + `dataset_schema` |
|
|
111
111
|
|
|
112
|
-
`archive_layout` must be `input_output` or `classes`. For `input_output`, pass `dataset_schema={"inputDataPath": "input", ...}
|
|
112
|
+
`archive_layout` must be `input_output` or `classes`. For `input_output`, pass `dataset_schema={"inputDataPath": "input", ...}` where paths are **relative to the zip root** (include a parent folder if the zip wraps one, e.g. `"abc/input"`). For `classes`, pass a non-empty `classes` list. Do **not** send an empty `{}` schema — the server treats that as missing and returns 422. The file is **streamed** from disk (not loaded fully into RAM).
|
|
113
|
+
|
|
114
|
+
If folder paths are wrong, the backend may respond with HTTP 400 and `status=needs_correction` plus `jobId` / `availableArchiveDirectories`. The SDK returns that JSON (does not raise) so you can call `retry_bulk_upload_job` with corrected `datasetSchema` without re-uploading the zip. `wait_for_bulk_upload_job` also stops on `needs_correction`.
|
|
113
115
|
|
|
114
116
|
Also see [`code_examples/dataset_operations_example.py`](../code_examples/dataset_operations_example.py) (CUD → entities → version) and [`code_examples/dataset_lifecycle_example.py`](../code_examples/dataset_lifecycle_example.py) (schema, mark-labeled, soft-delete/recover).
|
|
115
117
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# kf-sdk documentation (`import kappa_apk`)
|
|
2
2
|
|
|
3
|
-
> **PyPI:** `kf-sdk` · **Import:** `kappa_apk` · **Version:** 3.0.
|
|
3
|
+
> **PyPI:** `kf-sdk` · **Import:** `kappa_apk` · **Version:** 3.0.3 · **Branch:** `main`
|
|
4
4
|
> **Python:** 3.9+ · **API:** Kappa-framework **v2** (JWT identity — no `user_id` / `user_type_id` in URLs)
|
|
5
5
|
> **Requires backend:** Kappa-framework **≥ 2.10.0** (`kappa_apk.min_backend_version()`)
|
|
6
6
|
>
|
|
@@ -80,7 +80,7 @@ CIBW_ARCHS_LINUX="x86_64 aarch64" cibuildwheel --output-dir dist
|
|
|
80
80
|
| [`.github/workflows/ci.yml`](../../.github/workflows/ci.yml) | push / PR | `cargo test`, clippy, maturin wheels (py3.9–3.13), sdist |
|
|
81
81
|
| [`.github/workflows/publish.yml`](../../.github/workflows/publish.yml) | Release / вручную | sdist + cibuildwheel на Linux/macOS/Windows → PyPI (Linux: QEMU для aarch64) |
|
|
82
82
|
|
|
83
|
-
**Trusted publishing PyPI:** настройте окружение `pypi` на GitHub, создайте тег Release (например, `v3.0.
|
|
83
|
+
**Trusted publishing PyPI:** настройте окружение `pypi` на GitHub, создайте тег Release (например, `v3.0.3`).
|
|
84
84
|
|
|
85
85
|
---
|
|
86
86
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Документация SDK (`kf-sdk` / `kappa_apk`)
|
|
2
2
|
|
|
3
|
-
> **PyPI:** `kf-sdk` · **Импорт:** `kappa_apk` · **Версия:** 3.0.
|
|
3
|
+
> **PyPI:** `kf-sdk` · **Импорт:** `kappa_apk` · **Версия:** 3.0.3 · **Ветка:** `main`
|
|
4
4
|
> **Python:** 3.9+ · **API:** Kappa-framework **v2** (идентификация по JWT — без `user_id` / `user_type_id` в URL)
|
|
5
5
|
>
|
|
6
6
|
> Имя дистрибутива на PyPI **`kf-sdk`** сохранено для совместимости с ранними релизами; модуль импорта намеренно **`kappa_apk`**.
|
|
@@ -103,7 +103,18 @@ class BulkUploadJob:
|
|
|
103
103
|
def is_stale(self) -> bool: ...
|
|
104
104
|
@property
|
|
105
105
|
def preflight_deferred(self) -> bool: ...
|
|
106
|
-
def is_terminal(self) -> bool:
|
|
106
|
+
def is_terminal(self) -> bool:
|
|
107
|
+
"""True for completed / failed / cancelled (FE ``isBulkJobTerminal``)."""
|
|
108
|
+
...
|
|
109
|
+
|
|
110
|
+
def is_wait_complete(self) -> bool:
|
|
111
|
+
"""True when :meth:`wait_for_bulk_upload_job` should stop (terminal or needs_correction)."""
|
|
112
|
+
...
|
|
113
|
+
|
|
114
|
+
def needs_correction(self) -> bool:
|
|
115
|
+
"""True when status is ``needs_correction`` (fix layout and retry)."""
|
|
116
|
+
...
|
|
117
|
+
|
|
107
118
|
def as_dict(self) -> dict[str, Any]: ...
|
|
108
119
|
|
|
109
120
|
class Dataset:
|
|
@@ -303,6 +303,7 @@ impl ApiClient for KappaApkClient {
|
|
|
303
303
|
|
|
304
304
|
let url = format!("{}{}", self.base_url, endpoint);
|
|
305
305
|
let http = self.client.clone();
|
|
306
|
+
let runtime = Arc::clone(&self.runtime);
|
|
306
307
|
let path = std::path::PathBuf::from(&file_path);
|
|
307
308
|
let file_name = path
|
|
308
309
|
.file_name()
|
|
@@ -312,84 +313,121 @@ impl ApiClient for KappaApkClient {
|
|
|
312
313
|
let total = std::fs::metadata(&path).map(|m| m.len()).unwrap_or(0);
|
|
313
314
|
let progress_cb = on_upload_progress.map(Arc::new);
|
|
314
315
|
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
let
|
|
334
|
-
let
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
316
|
+
// Release the GIL before block_on. Progress callbacks re-acquire it via
|
|
317
|
+
// Python::with_gil from Tokio worker threads; holding the GIL across
|
|
318
|
+
// block_on deadlocks as soon as the first progress tick runs.
|
|
319
|
+
Python::with_gil(|py| {
|
|
320
|
+
py.allow_threads(move || {
|
|
321
|
+
runtime.block_on(async move {
|
|
322
|
+
let file = tokio::fs::File::open(&path).await.map_err(|e| {
|
|
323
|
+
PyErr::new::<pyo3::exceptions::PyIOError, _>(format!(
|
|
324
|
+
"Cannot open {}: {}",
|
|
325
|
+
path.display(),
|
|
326
|
+
e
|
|
327
|
+
))
|
|
328
|
+
})?;
|
|
329
|
+
let reader = ReaderStream::new(file);
|
|
330
|
+
let sent = Arc::new(AtomicU64::new(0));
|
|
331
|
+
let last_pct = Arc::new(AtomicI32::new(-1));
|
|
332
|
+
let sent2 = sent.clone();
|
|
333
|
+
let last2 = last_pct.clone();
|
|
334
|
+
let cb2 = progress_cb.clone();
|
|
335
|
+
let total2 = total;
|
|
336
|
+
|
|
337
|
+
let stream = reader.map(move |chunk| match chunk {
|
|
338
|
+
Ok(bytes) => {
|
|
339
|
+
let n = bytes.len() as u64;
|
|
340
|
+
let cur = sent2.fetch_add(n, Ordering::Relaxed) + n;
|
|
341
|
+
let pct = if total2 > 0 {
|
|
342
|
+
(((cur as f64) * 100.0) / (total2 as f64)).round() as i32
|
|
343
|
+
} else {
|
|
344
|
+
0
|
|
345
|
+
}
|
|
346
|
+
.clamp(0, 100);
|
|
347
|
+
let prev_pct = last2.swap(pct, Ordering::Relaxed);
|
|
348
|
+
if (pct != prev_pct || cur >= total2)
|
|
349
|
+
&& let Some(ref cb) = cb2
|
|
350
|
+
{
|
|
351
|
+
Python::with_gil(|py| {
|
|
352
|
+
let _ = cb.bind(py).call1((cur, total2, pct));
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
Ok::<_, std::io::Error>(bytes)
|
|
356
|
+
}
|
|
357
|
+
Err(e) => Err(e),
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
let body = reqwest::Body::wrap_stream(stream);
|
|
361
|
+
let file_part = multipart::Part::stream(body)
|
|
362
|
+
.file_name(file_name)
|
|
363
|
+
.mime_str("application/octet-stream")
|
|
364
|
+
.map_err(|e| {
|
|
365
|
+
PyErr::new::<pyo3::exceptions::PyValueError, _>(e.to_string())
|
|
366
|
+
})?;
|
|
367
|
+
let form = multipart::Form::new()
|
|
368
|
+
.text("sources", sources_json)
|
|
369
|
+
.part("file", file_part);
|
|
370
|
+
|
|
371
|
+
let mut request = http.post(&url).multipart(form);
|
|
372
|
+
request = request.header("accept", "application/json");
|
|
373
|
+
if let Some(ref t) = token {
|
|
374
|
+
request = request.header("Authorization", format!("Bearer {}", t));
|
|
339
375
|
}
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
if (pct != prev_pct || cur >= total2)
|
|
343
|
-
&& let Some(ref cb) = cb2
|
|
344
|
-
{
|
|
345
|
-
Python::with_gil(|py| {
|
|
346
|
-
let _ = cb.bind(py).call1((cur, total2, pct));
|
|
347
|
-
});
|
|
376
|
+
for (k, v) in headers {
|
|
377
|
+
request = request.header(k, v);
|
|
348
378
|
}
|
|
349
|
-
Ok::<_, std::io::Error>(bytes)
|
|
350
|
-
}
|
|
351
|
-
Err(e) => Err(e),
|
|
352
|
-
});
|
|
353
379
|
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
.text("sources", sources_json)
|
|
361
|
-
.part("file", file_part);
|
|
362
|
-
|
|
363
|
-
let mut request = http.post(&url).multipart(form);
|
|
364
|
-
request = request.header("accept", "application/json");
|
|
365
|
-
if let Some(ref t) = token {
|
|
366
|
-
request = request.header("Authorization", format!("Bearer {}", t));
|
|
367
|
-
}
|
|
368
|
-
for (k, v) in headers {
|
|
369
|
-
request = request.header(k, v);
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
let response = request.send().await.map_err(|e| {
|
|
373
|
-
PyErr::new::<pyo3::exceptions::PyConnectionError, _>(format!(
|
|
374
|
-
"Request failed: {}",
|
|
375
|
-
e
|
|
376
|
-
))
|
|
377
|
-
})?;
|
|
380
|
+
let response = request.send().await.map_err(|e| {
|
|
381
|
+
PyErr::new::<pyo3::exceptions::PyConnectionError, _>(format!(
|
|
382
|
+
"Request failed: {}",
|
|
383
|
+
e
|
|
384
|
+
))
|
|
385
|
+
})?;
|
|
378
386
|
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
387
|
+
let status = response.status();
|
|
388
|
+
let text = response.text().await.unwrap_or_default();
|
|
389
|
+
if status.is_success() {
|
|
390
|
+
let json_data: serde_json::Value = serde_json::from_str(&text)
|
|
391
|
+
.map_err(|e| {
|
|
392
|
+
PyErr::new::<pyo3::exceptions::PyValueError, _>(format!(
|
|
393
|
+
"Failed to parse response: {}",
|
|
394
|
+
e
|
|
395
|
+
))
|
|
396
|
+
})?;
|
|
397
|
+
return Python::with_gil(|py| json_value_to_pyobject(py, &json_data));
|
|
398
|
+
}
|
|
399
|
+
// BE returns HTTP 400 for layout preflight with status=needs_correction
|
|
400
|
+
// and a jobId (staging kept for retry). Surface that body like a start
|
|
401
|
+
// response so callers can save jobId and call retry_bulk_upload_job.
|
|
402
|
+
if status.as_u16() == 400
|
|
403
|
+
&& let Ok(json_data) = serde_json::from_str::<serde_json::Value>(&text)
|
|
404
|
+
{
|
|
405
|
+
let has_job = json_data
|
|
406
|
+
.get("jobId")
|
|
407
|
+
.or_else(|| json_data.get("job_id"))
|
|
408
|
+
.and_then(|v| v.as_str())
|
|
409
|
+
.map(|s| !s.is_empty())
|
|
410
|
+
.unwrap_or(false);
|
|
411
|
+
let job_status = json_data
|
|
412
|
+
.get("status")
|
|
413
|
+
.and_then(|v| v.as_str())
|
|
414
|
+
.unwrap_or("")
|
|
415
|
+
.to_ascii_lowercase();
|
|
416
|
+
if has_job
|
|
417
|
+
&& (job_status == "needs_correction"
|
|
418
|
+
|| json_data
|
|
419
|
+
.get("retryable")
|
|
420
|
+
.and_then(|v| v.as_bool())
|
|
421
|
+
.unwrap_or(false))
|
|
422
|
+
{
|
|
423
|
+
return Python::with_gil(|py| {
|
|
424
|
+
json_value_to_pyobject(py, &json_data)
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
Err(http_error_to_pyerr(status, text))
|
|
429
|
+
})
|
|
430
|
+
})
|
|
393
431
|
})
|
|
394
432
|
}
|
|
395
433
|
|
|
@@ -660,11 +698,21 @@ impl KappaApkClient {
|
|
|
660
698
|
/// ```
|
|
661
699
|
#[new]
|
|
662
700
|
pub fn new(base_url: String, login_id: String, passwd: String) -> PyResult<Self> {
|
|
663
|
-
|
|
701
|
+
// Connect timeout only — bulk uploads can run for a long time with no overall deadline.
|
|
702
|
+
let client = Client::builder()
|
|
703
|
+
.connect_timeout(std::time::Duration::from_secs(30))
|
|
704
|
+
.build()
|
|
705
|
+
.map_err(|e| {
|
|
706
|
+
PyErr::new::<pyo3::exceptions::PyRuntimeError, _>(format!(
|
|
707
|
+
"Failed to create HTTP client: {}",
|
|
708
|
+
e
|
|
709
|
+
))
|
|
710
|
+
})?;
|
|
664
711
|
let runtime = Arc::new(tokio::runtime::Runtime::new().map_err(|e| {
|
|
665
|
-
PyErr::new::<pyo3::exceptions::PyRuntimeError, _>(
|
|
666
|
-
|
|
667
|
-
|
|
712
|
+
PyErr::new::<pyo3::exceptions::PyRuntimeError, _>(format!(
|
|
713
|
+
"Failed to create async runtime: {}",
|
|
714
|
+
e
|
|
715
|
+
))
|
|
668
716
|
})?);
|
|
669
717
|
Ok(KappaApkClient {
|
|
670
718
|
client,
|
|
@@ -697,34 +745,42 @@ impl KappaApkClient {
|
|
|
697
745
|
};
|
|
698
746
|
let login_url = format!("{}/user-micro-services/v2/session/new", self.base_url);
|
|
699
747
|
let client = self.client.clone();
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
.
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
)
|
|
748
|
+
let runtime = Arc::clone(&self.runtime);
|
|
749
|
+
|
|
750
|
+
let login_data: User = Python::with_gil(|py| {
|
|
751
|
+
py.allow_threads(move || {
|
|
752
|
+
runtime.block_on(async move {
|
|
753
|
+
let response = client
|
|
754
|
+
.post(&login_url)
|
|
755
|
+
.header("accept", "application/json")
|
|
756
|
+
.header("Content-Type", "application/json")
|
|
757
|
+
.json(&login_request)
|
|
758
|
+
.send()
|
|
759
|
+
.await
|
|
760
|
+
.map_err(|e| {
|
|
761
|
+
PyErr::new::<pyo3::exceptions::PyConnectionError, _>(format!(
|
|
762
|
+
"Request failed: {}",
|
|
763
|
+
e
|
|
764
|
+
))
|
|
765
|
+
})?;
|
|
766
|
+
|
|
767
|
+
if response.status().is_success() {
|
|
768
|
+
response.json::<User>().await.map_err(|e| {
|
|
769
|
+
PyErr::new::<pyo3::exceptions::PyValueError, _>(format!(
|
|
770
|
+
"Failed to parse login response: {}",
|
|
771
|
+
e
|
|
772
|
+
))
|
|
773
|
+
})
|
|
774
|
+
} else {
|
|
775
|
+
let status = response.status();
|
|
776
|
+
let msg = response.text().await.unwrap_or_default();
|
|
777
|
+
Err(PyErr::new::<pyo3::exceptions::PyValueError, _>(format!(
|
|
778
|
+
"Login failed (HTTP {}): {}",
|
|
779
|
+
status, msg
|
|
780
|
+
)))
|
|
781
|
+
}
|
|
720
782
|
})
|
|
721
|
-
}
|
|
722
|
-
let status = response.status();
|
|
723
|
-
let msg = response.text().await.unwrap_or_default();
|
|
724
|
-
Err(PyErr::new::<pyo3::exceptions::PyValueError, _>(
|
|
725
|
-
format!("Login failed (HTTP {}): {}", status, msg),
|
|
726
|
-
))
|
|
727
|
-
}
|
|
783
|
+
})
|
|
728
784
|
})?;
|
|
729
785
|
|
|
730
786
|
self.login_response = Some(login_data.clone());
|
|
@@ -1849,10 +1849,12 @@ tf_dataset = tf.data.Dataset.from_generator(
|
|
|
1849
1849
|
let _ = cb.bind(py).call1((bound.clone(),));
|
|
1850
1850
|
});
|
|
1851
1851
|
}
|
|
1852
|
-
let
|
|
1853
|
-
job.bind(py)
|
|
1852
|
+
let stop = Python::with_gil(|py| {
|
|
1853
|
+
job.bind(py)
|
|
1854
|
+
.call_method0("is_wait_complete")?
|
|
1855
|
+
.extract::<bool>()
|
|
1854
1856
|
})?;
|
|
1855
|
-
if
|
|
1857
|
+
if stop {
|
|
1856
1858
|
return Ok(job);
|
|
1857
1859
|
}
|
|
1858
1860
|
if start.elapsed().as_secs_f64() >= timeout {
|
|
@@ -910,6 +910,9 @@ impl BulkUploadJob {
|
|
|
910
910
|
}
|
|
911
911
|
|
|
912
912
|
/// True when status is a terminal job state (FE `isBulkJobTerminal` parity).
|
|
913
|
+
///
|
|
914
|
+
/// Note: ``needs_correction`` is **not** terminal (FE still treats it as active for
|
|
915
|
+
/// list filters) but :meth:`wait_for_bulk_upload_job` stops on it so callers can retry.
|
|
913
916
|
fn is_terminal(&self) -> bool {
|
|
914
917
|
matches!(
|
|
915
918
|
self.status().to_ascii_lowercase().as_str(),
|
|
@@ -923,6 +926,16 @@ impl BulkUploadJob {
|
|
|
923
926
|
)
|
|
924
927
|
}
|
|
925
928
|
|
|
929
|
+
/// True when polling should stop (terminal **or** ``needs_correction``).
|
|
930
|
+
fn is_wait_complete(&self) -> bool {
|
|
931
|
+
self.is_terminal() || self.status().eq_ignore_ascii_case("needs_correction")
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
/// True when status is ``needs_correction`` (fix paths / retry with staging).
|
|
935
|
+
fn needs_correction(&self) -> bool {
|
|
936
|
+
self.status().eq_ignore_ascii_case("needs_correction")
|
|
937
|
+
}
|
|
938
|
+
|
|
926
939
|
/// Full API payload as a Python dict.
|
|
927
940
|
fn as_dict(&self, py: Python<'_>) -> PyResult<PyObject> {
|
|
928
941
|
let json_str = serde_json::to_string(&self.raw).map_err(|e| {
|
|
@@ -963,5 +976,18 @@ mod bulk_upload_job_tests {
|
|
|
963
976
|
"status": "processing"
|
|
964
977
|
}));
|
|
965
978
|
assert!(!job.is_terminal());
|
|
979
|
+
assert!(!job.is_wait_complete());
|
|
980
|
+
}
|
|
981
|
+
|
|
982
|
+
#[test]
|
|
983
|
+
fn needs_correction_stops_wait_but_not_terminal() {
|
|
984
|
+
let job = BulkUploadJob::from_json_value(json!({
|
|
985
|
+
"jobId": "j1",
|
|
986
|
+
"status": "needs_correction",
|
|
987
|
+
"retryable": true
|
|
988
|
+
}));
|
|
989
|
+
assert!(!job.is_terminal());
|
|
990
|
+
assert!(job.needs_correction());
|
|
991
|
+
assert!(job.is_wait_complete());
|
|
966
992
|
}
|
|
967
993
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|