Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add remaining endpoint APIs in SDK #4819

Closed
wants to merge 171 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
171 commits
Select commit Hold shift + click to select a range
e34731d
Fix generated OpenAPI schema
zhiltsov-max Jun 20, 2022
4f1940b
Update changelog
zhiltsov-max Jun 20, 2022
cf759f5
Merge branch 'develop' into zm/fix-openapi-schema
zhiltsov-max Jun 20, 2022
aad0ccc
Make data-related fields in the Task optional
zhiltsov-max Jun 21, 2022
50959a4
Allow null organization in Task, Project, Clouds
zhiltsov-max Jun 21, 2022
f43d47a
Add a task to generate schema
zhiltsov-max Jun 21, 2022
a16d103
Fix attribute values declaration - it is a list of strings
zhiltsov-max Jun 21, 2022
38b7d82
Merge branch 'develop' into zm/fix-openapi-schema
zhiltsov-max Jun 22, 2022
7248a7f
add generator config
zhiltsov-max Jun 24, 2022
4bda27e
Update generator config and templates
zhiltsov-max Jun 27, 2022
e953a23
Add generated code
zhiltsov-max Jun 27, 2022
6d9f43e
Add tasks tests
zhiltsov-max Jun 27, 2022
e73828e
Add sample
zhiltsov-max Jun 27, 2022
35b764a
Fixes to some methods
zhiltsov-max Jun 27, 2022
4acffb5
Add org parameters in schema globally
zhiltsov-max Jun 28, 2022
8c5f2fc
Fix tasks patch tests
zhiltsov-max Jun 28, 2022
aa8d8f0
Enable file uploading in task data
zhiltsov-max Jul 1, 2022
d69af23
Merge branch 'develop' into zm/add-cvat-sdk
zhiltsov-max Jul 1, 2022
5210bce
Merge with develop, fix issues
zhiltsov-max Jul 1, 2022
aa0a8ff
Fix schema generation error
zhiltsov-max Jul 1, 2022
1e5f915
Add introspection to models and apis, embed apis into client, add cod…
zhiltsov-max Jul 4, 2022
78eb73e
Add debug task for api code processing
zhiltsov-max Jul 4, 2022
b580feb
Improve type annotations in api
zhiltsov-max Jul 4, 2022
a491203
Add design document
zhiltsov-max Jul 5, 2022
ac41fd4
Fix launch,json
zhiltsov-max Jul 5, 2022
03ddd56
Simplify imports
zhiltsov-max Jul 5, 2022
122635c
Fix tests
zhiltsov-max Jul 5, 2022
4ca10bc
Move operation method after api tag
zhiltsov-max Jul 5, 2022
1519d3a
Rename _preload_content to _parse_response
zhiltsov-max Jul 5, 2022
a123d6f
Regularize operation return types in API
zhiltsov-max Jul 7, 2022
13e9644
Add default _configuration arg in model creation, fix some type annot…
zhiltsov-max Jul 7, 2022
347e414
Update tests
zhiltsov-max Jul 8, 2022
c9d15d0
Add schema for page_size parameter
zhiltsov-max Jul 8, 2022
97d5beb
Enable users tests
zhiltsov-max Jul 11, 2022
c44f6af
Fix schema for tus-related endpoints (PATCH)
zhiltsov-max Jul 12, 2022
611d7fb
ProjectsApi: fix serializers, fix tests
zhiltsov-max Jul 12, 2022
6e22c63
Merge branch 'develop' into zm/add-cvat-sdk
zhiltsov-max Jul 12, 2022
17d790c
Update changelog
zhiltsov-max Jul 12, 2022
2b8a460
Dont run pylint on generated api client
zhiltsov-max Jul 12, 2022
3784e79
Exclude cvat-api-client from bandit and remark checks
zhiltsov-max Jul 12, 2022
0a991ed
Update CI for cvat-api-client dependency
zhiltsov-max Jul 12, 2022
525feb5
fix linter
zhiltsov-max Jul 12, 2022
af76558
Move remarkignore
zhiltsov-max Jul 12, 2022
434517b
Update docs, fix linter
zhiltsov-max Jul 12, 2022
cd5e1b9
Fix package installation
zhiltsov-max Jul 13, 2022
24837d8
Fix dev instructions
zhiltsov-max Jul 14, 2022
b2c362a
Revert serializer change
zhiltsov-max Jul 14, 2022
e913491
Merge branch 'develop' into zm/add-cvat-sdk
zhiltsov-max Jul 14, 2022
07069c4
Rename api-client to sdk
zhiltsov-max Jul 14, 2022
31034f1
Merge branch 'zm/add-cvat-sdk' of https://github.com/cvat-ai/cvat int…
zhiltsov-max Jul 14, 2022
d0e9075
Format files
zhiltsov-max Jul 14, 2022
06481e1
Add core client base to sdk
zhiltsov-max Jul 14, 2022
aa8672e
Style fixes
zhiltsov-max Jul 14, 2022
cb3576f
Implement task creation
zhiltsov-max Jul 15, 2022
d18271e
Update license headers, add task creation test
zhiltsov-max Jul 18, 2022
0de20f1
remove sample
zhiltsov-max Jul 18, 2022
63ce027
Fix overlap field schema
zhiltsov-max Jul 19, 2022
2af421a
Fix task creation test
zhiltsov-max Jul 19, 2022
bf57543
Manage session cookies in ApiClient
zhiltsov-max Jul 19, 2022
3e4e859
Don't overwrite gitignore
zhiltsov-max Jul 19, 2022
905dd92
Fix type annotation
zhiltsov-max Jul 19, 2022
c27b494
Add list fetching utility
zhiltsov-max Jul 20, 2022
55c120b
Fix users list response
zhiltsov-max Jul 20, 2022
e060f53
Fix example formatting
zhiltsov-max Jul 20, 2022
4a8dc99
Fix license headers
zhiltsov-max Jul 20, 2022
e6529cd
Update bulk task removal
zhiltsov-max Jul 20, 2022
64aecbe
Add progressreporter model, remove tqdm dependency
zhiltsov-max Jul 20, 2022
db96c6b
Fix enpoint names for cloudstorages
zhiltsov-max Jul 20, 2022
11e0ad0
Fix links in api contacts
zhiltsov-max Jul 20, 2022
c6349f4
Move l2 sources
zhiltsov-max Jul 20, 2022
16f09b3
Merge branch 'develop' into zm/sdk-l2
zhiltsov-max Jul 20, 2022
c24dd44
Change contact
zhiltsov-max Jul 20, 2022
9ef4b47
Fix linter error
zhiltsov-max Jul 20, 2022
84cfe84
Extract class for uploading
zhiltsov-max Jul 20, 2022
2f23938
Split cvat client into usecases
zhiltsov-max Jul 21, 2022
412d0fb
Enable sdk tests
zhiltsov-max Jul 26, 2022
2f31269
Move to OO-like approach
zhiltsov-max Jul 26, 2022
c1760fa
Fix test, clarify model interfaces
zhiltsov-max Jul 27, 2022
f05482a
Enable more task tests, introduce config
zhiltsov-max Jul 27, 2022
7bdce47
Enable task file downloading tests
zhiltsov-max Jul 27, 2022
80b36da
Enable frame downloading tests
zhiltsov-max Jul 27, 2022
65a3f9d
Fix annotation and backup uploading
zhiltsov-max Jul 28, 2022
e1bbc5f
Fix backup uploading
zhiltsov-max Jul 29, 2022
dece1bd
Clean imports
zhiltsov-max Jul 29, 2022
f4333f9
Fix param
zhiltsov-max Jul 29, 2022
cdb1be3
Rename CvatClient to Client
zhiltsov-max Aug 1, 2022
b776f18
Move types component
zhiltsov-max Aug 1, 2022
3414a68
Refactor cli code
zhiltsov-max Aug 1, 2022
4d01fb8
Refactor module placement
zhiltsov-max Aug 1, 2022
45c02c7
Add missing args
zhiltsov-max Aug 1, 2022
57e4116
Fix cookie handling
zhiltsov-max Aug 1, 2022
10875ab
Implement cli tests
zhiltsov-max Aug 1, 2022
d9a6e82
Add cli tests task in launch.json
zhiltsov-max Aug 1, 2022
ed2ae4b
Merge branch 'develop' into zm/sdk-l2
zhiltsov-max Aug 1, 2022
5b51bb2
Reorganize python test placement
zhiltsov-max Aug 2, 2022
8eaaf18
Fix tests after merge
zhiltsov-max Aug 2, 2022
89c2725
Add file uploading cli tests
zhiltsov-max Aug 2, 2022
1bc7cf6
Update launch.json
zhiltsov-max Aug 2, 2022
a05beec
Update github workflows
zhiltsov-max Aug 2, 2022
81233fc
Fix login problem
zhiltsov-max Aug 3, 2022
c2a5f3e
Fix imports
zhiltsov-max Aug 3, 2022
b17acc5
Fix linter errors
zhiltsov-max Aug 3, 2022
b8a7087
Fix ci
zhiltsov-max Aug 3, 2022
a4e51d4
Add a test for failed task creation
zhiltsov-max Aug 3, 2022
fb1e358
Add auth tests
zhiltsov-max Aug 3, 2022
a23ff17
Update issue tests to use sdk
zhiltsov-max Aug 3, 2022
39f4715
Remove PUT methods on model-specific endpoints
zhiltsov-max Aug 4, 2022
6798791
Fix auth tests
zhiltsov-max Aug 4, 2022
9da9436
Add issue removal tests
zhiltsov-max Aug 4, 2022
af6c598
Add jobs and downloading
zhiltsov-max Aug 4, 2022
6ef21e3
Fix potential logging problem
zhiltsov-max Aug 4, 2022
e3ea337
Refactor downloading and uploading
zhiltsov-max Aug 4, 2022
7a5df89
Fix tests, add Issues and Comments, move group operations to proxy cl…
zhiltsov-max Aug 5, 2022
00fdcf6
Merge branch 'develop' into zm/sdk-l2
zhiltsov-max Aug 8, 2022
e9c3113
Add TUS dep in SDK
zhiltsov-max Aug 8, 2022
db80b3e
Update cvat-sdk file layout
zhiltsov-max Aug 12, 2022
ee84cc9
Upgrade pylint and clean files
zhiltsov-max Aug 12, 2022
52c3e0f
fix check
zhiltsov-max Aug 12, 2022
5acea16
Update black and isort on CI
zhiltsov-max Aug 12, 2022
f7d786a
fix black and isort on ci
zhiltsov-max Aug 12, 2022
fd3220d
fix exit code
zhiltsov-max Aug 12, 2022
1b66328
fix linter error
zhiltsov-max Aug 12, 2022
a397cbd
Merge branch 'zm/sdk-l2' into zm/sdk-l2-me
zhiltsov-max Aug 12, 2022
dc4b551
Move helpers module
zhiltsov-max Aug 12, 2022
2b6e5f3
Fix generator version, enable sdk building on CI
zhiltsov-max Aug 12, 2022
08c3adf
fix exit code
zhiltsov-max Aug 12, 2022
5aaa323
Fix linter error
zhiltsov-max Aug 12, 2022
d696eb6
Merge branch 'zm/sdk-l2' into zm/sdk-l2-me
zhiltsov-max Aug 12, 2022
57620fc
Add support for OpenApiTypes in PolymorphicProxySerializer, fix job/a…
zhiltsov-max Aug 15, 2022
5afa6b5
Update job rest api tests to use sdk, fix job and job annotations end…
zhiltsov-max Aug 15, 2022
f7541b8
Introduce repositories in sdk level2
zhiltsov-max Aug 16, 2022
f023d11
Fix annotations and datasets schema, add rest api tests
zhiltsov-max Aug 16, 2022
12e5218
Merge branch 'develop' into zm/sdk-l2-me
zhiltsov-max Aug 16, 2022
2adcaad
Remove extra file
zhiltsov-max Aug 16, 2022
3fadfa5
Implement jobs sdk, add missing task methods. Add projects, issues, c…
zhiltsov-max Aug 17, 2022
aec4c29
Refactor sdk code, add job commits and issues
zhiltsov-max Aug 18, 2022
54e415c
Fix partial_update schemas, add issues and comments tests
zhiltsov-max Aug 19, 2022
a7c03a5
Make some parameters optional for annotation serializers
zhiltsov-max Aug 19, 2022
770fa1d
Treat message optional
zhiltsov-max Aug 19, 2022
6540888
Fix other model list endpoints in views
zhiltsov-max Aug 19, 2022
20a1e1b
Add missing tests and annotations methods in proxies
zhiltsov-max Aug 19, 2022
af1e15b
Fix show empty tasks (#100)
Marishka17 Aug 19, 2022
75ba69b
[Snyk] Upgrade dotenv-webpack from 7.1.1 to 8.0.0 (#98)
azhavoro Aug 19, 2022
7b492ee
Disable bandit for tests
zhiltsov-max Aug 22, 2022
f81f982
Fix bandit checks
zhiltsov-max Aug 22, 2022
30b60df
Fix bandit exclude
zhiltsov-max Aug 22, 2022
58e4fe5
Merge branch 'develop' into zm/sdk-l2-me
zhiltsov-max Aug 22, 2022
4f0aac5
Update server tests for task and jobs PUT method
zhiltsov-max Aug 22, 2022
b6369f7
Update changelog
zhiltsov-max Aug 22, 2022
0c5856a
Fix cloudstorages schema
zhiltsov-max Aug 23, 2022
e36f1ab
Add get status api test
zhiltsov-max Aug 23, 2022
bc94fb3
add cloudstorages sdk
zhiltsov-max Aug 23, 2022
de0bb09
Refactor resource import export tests
zhiltsov-max Aug 24, 2022
beaff57
Add debug output for generate.py
zhiltsov-max Aug 24, 2022
05d3eef
Fix sdk apis
zhiltsov-max Aug 24, 2022
77df5c9
Add more tests for cloud storages
zhiltsov-max Aug 24, 2022
6c8bff6
Update cloudstorage api tests
zhiltsov-max Aug 25, 2022
14e8156
Add cloudstorage proxies tests
zhiltsov-max Aug 25, 2022
10eadfd
Remove extra imports
zhiltsov-max Aug 25, 2022
c1f361d
Remove extra imports
zhiltsov-max Aug 26, 2022
54cd4ac
add project tests
zhiltsov-max Aug 27, 2022
9bbf292
Add an issue link in the workaround comment
zhiltsov-max Sep 5, 2022
3f55b31
Merge branch 'zm/cli-for-new-sdk' of https://github.com/opencv/cvat i…
zhiltsov-max Sep 5, 2022
7a16994
Add project tests
zhiltsov-max Sep 5, 2022
e953455
Merge branch 'develop' into zm/cli-for-new-sdk
zhiltsov-max Sep 7, 2022
e9f6e5a
Fix imports
zhiltsov-max Sep 7, 2022
8308948
Fix merge
zhiltsov-max Sep 7, 2022
dc698cd
Add more project proxy tests
zhiltsov-max Sep 8, 2022
9e252fd
try to fix backup uploading
zhiltsov-max Sep 8, 2022
7adf02b
Merge remote-tracking branch 'origin/zm/cli-for-new-sdk' into zm/cli-…
zhiltsov-max Oct 4, 2022
d15960c
Merge branch 'develop' into zm/cli-for-new-sdk
zhiltsov-max Oct 4, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion cvat-sdk/cvat_sdk/core/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from cvat_sdk.api_client import ApiClient, Configuration, exceptions, models
from cvat_sdk.core.exceptions import IncompatibleVersionException, InvalidHostException
from cvat_sdk.core.helpers import expect_status
from cvat_sdk.core.proxies.cloudstorages import CloudStoragesRepo
from cvat_sdk.core.proxies.issues import CommentsRepo, IssuesRepo
from cvat_sdk.core.proxies.jobs import JobsRepo
from cvat_sdk.core.proxies.model_proxy import Repo
Expand Down Expand Up @@ -158,13 +159,15 @@ def wait_for_completion(
post_params: Optional[Dict[str, Any]] = None,
method: str = "POST",
positive_statuses: Optional[Sequence[int]] = None,
max_checks: int = 0,
) -> urllib3.HTTPResponse:
if status_check_period is None:
status_check_period = self.config.status_check_period

positive_statuses = set(positive_statuses) | {success_status}

while True:
attempt = 0
while not max_checks or attempt < max_checks:
sleep(status_check_period)

response = self.api_client.rest_client.request(
Expand All @@ -180,6 +183,8 @@ def wait_for_completion(
if response.status == success_status:
break

attempt += 1

return response

def check_server_version(self, fail_if_unsupported: Optional[bool] = None) -> None:
Expand Down Expand Up @@ -228,6 +233,7 @@ def _get_repo(self, key: str) -> Repo:
"users": UsersRepo,
"issues": IssuesRepo,
"comments": CommentsRepo,
"cloud_storages": CloudStoragesRepo,
}

repo = self._repos.get(key, None)
Expand Down Expand Up @@ -260,6 +266,10 @@ def issues(self) -> IssuesRepo:
def comments(self) -> CommentsRepo:
return self._get_repo("comments")

@property
def cloud_storages(self) -> CloudStoragesRepo:
return self._get_repo("cloud_storages")


class CVAT_API_V2:
"""Build parameterized API URLs"""
Expand Down
57 changes: 57 additions & 0 deletions cvat-sdk/cvat_sdk/core/proxies/cloudstorages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Copyright (C) 2022 CVAT.ai Corporation
#
# SPDX-License-Identifier: MIT

from __future__ import annotations

import io
from typing import List, Optional, Set

from cvat_sdk.api_client import apis, models
from cvat_sdk.core.proxies.model_proxy import (
ModelCreateMixin,
ModelDeleteMixin,
ModelListMixin,
ModelRetrieveMixin,
ModelUpdateMixin,
build_model_bases,
)

_CloudStorageEntityBase, _CloudStorageRepoBase = build_model_bases(
models.CloudStorageRead, apis.CloudstoragesApi, api_member_name="cloudstorages_api"
)


class CloudStorage(
_CloudStorageEntityBase,
models.ICloudStorageRead,
ModelUpdateMixin[models.IPatchedCloudStorageWriteRequest],
ModelDeleteMixin,
):
_model_partial_update_arg = "patched_cloud_storage_write_request"
_put_annotations_data_param = "cloudstorage_annotations_update_request"

def get_actions(self) -> Set[str]:
return set(self.api.retrieve_actions(self.id)[0])

def get_preview(self) -> io.RawIOBase:
(_, response) = self.api.retrieve_preview(self.id, _parse_response=False)
return io.BytesIO(response.data)

def get_status(self) -> str:
return self.api.retrieve_status(self.id)[0]

def get_content(self, manifest_path: Optional[str] = None) -> List[str]:
kwargs = {}
if manifest_path:
kwargs["manifest_path"] = manifest_path
return self.api.retrieve_content(self.id, **kwargs)[0]


class CloudStoragesRepo(
_CloudStorageRepoBase,
ModelCreateMixin[CloudStorage, models.ICloudStorageWriteRequest],
ModelRetrieveMixin[CloudStorage],
ModelListMixin[CloudStorage],
):
_entity_type = CloudStorage
4 changes: 2 additions & 2 deletions cvat-sdk/cvat_sdk/core/proxies/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ def get_frame(
quality: Optional[str] = None,
) -> io.RawIOBase:
(_, response) = self.api.retrieve_data(
self.id, number=frame_id, quality=quality, type="frame"
self.id, number=frame_id, quality=quality, type="frame", _parse_response=False
)
return io.BytesIO(response.data)

def get_preview(
self,
) -> io.RawIOBase:
(_, response) = self.api.retrieve_data(self.id, type="preview")
(_, response) = self.api.retrieve_data(self.id, type="preview", _parse_response=False)
return io.BytesIO(response.data)

def download_frames(
Expand Down
4 changes: 2 additions & 2 deletions cvat-sdk/cvat_sdk/core/proxies/model_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,10 @@ def list(self: Repo, *, return_json: Literal[False] = False) -> List[_EntityT]:
...

@overload
def list(self: Repo, *, return_json: Literal[True] = False) -> List[Any]:
def list(self: Repo, *, return_json: Literal[True] = False) -> List[Dict[str, Any]]:
...

def list(self: Repo, *, return_json: bool = False) -> List[Union[_EntityT, Any]]:
def list(self: Repo, *, return_json: bool = False) -> List[Union[_EntityT, Dict[str, Any]]]:
"""
Retrieves all objects from the server and returns them in basic or JSON format.
"""
Expand Down
18 changes: 12 additions & 6 deletions cvat-sdk/cvat_sdk/core/proxies/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import json
import os.path as osp
from typing import Optional
from typing import List, Optional

from cvat_sdk.api_client import apis, models
from cvat_sdk.core.downloading import Downloader
Expand All @@ -19,6 +19,7 @@
ModelUpdateMixin,
build_model_bases,
)
from cvat_sdk.core.proxies.tasks import Task
from cvat_sdk.core.uploading import DatasetUploader, Uploader

_ProjectEntityBase, _ProjectRepoBase = build_model_bases(
Expand All @@ -27,7 +28,10 @@


class Project(
_ProjectEntityBase, models.IProjectRead, ModelUpdateMixin[models.IPatchedProjectWriteRequest]
_ProjectEntityBase,
models.IProjectRead,
ModelUpdateMixin[models.IPatchedProjectWriteRequest],
ModelDeleteMixin,
):
_model_partial_update_arg = "patched_project_write_request"

Expand Down Expand Up @@ -107,13 +111,15 @@ def get_annotations(self) -> models.ILabeledData:
(annotations, _) = self.api.retrieve_annotations(self.id)
return annotations

def get_tasks(self) -> List[Task]:
return [Task(self._client, m) for m in self.api.list_tasks(id=self.id)[0].results]


class ProjectsRepo(
_ProjectRepoBase,
ModelCreateMixin[Project, models.IProjectWriteRequest],
ModelListMixin[Project],
ModelRetrieveMixin[Project],
ModelDeleteMixin,
):
_entity_type = Project

Expand Down Expand Up @@ -157,12 +163,12 @@ def create_from_backup(
Import a project from a backup file
"""
if status_check_period is None:
status_check_period = self.config.status_check_period
status_check_period = self._client.config.status_check_period

params = {"filename": osp.basename(filename)}
url = self.api_map.make_endpoint_url(self.api.create_backup_endpoint.path)
url = self._client.api_map.make_endpoint_url(self.api.create_backup_endpoint.path)

uploader = Uploader(self)
uploader = Uploader(self._client)
response = uploader.upload_file(
url,
filename,
Expand Down
9 changes: 5 additions & 4 deletions cvat-sdk/cvat_sdk/core/proxies/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,18 @@ def get_frame(
*,
quality: Optional[str] = None,
) -> io.RawIOBase:
params = {}
params = {"number": frame_id}
if quality:
params["quality"] = quality
(_, response) = self.api.retrieve_data(self.id, number=frame_id, **params, type="frame")
(_, response) = self.api.retrieve_data(
self.id, type="frame", **params, _parse_response=False
)
return io.BytesIO(response.data)

def get_preview(
self,
) -> io.RawIOBase:
(_, response) = self.api.retrieve_data(self.id, type="preview")
(_, response) = self.api.retrieve_data(self.id, type="preview", _parse_response=False)
return io.BytesIO(response.data)

def download_frames(
Expand Down Expand Up @@ -255,7 +257,6 @@ class TasksRepo(
ModelCreateMixin[Task, models.ITaskWriteRequest],
ModelRetrieveMixin[Task],
ModelListMixin[Task],
ModelDeleteMixin,
):
_entity_type = Task

Expand Down
52 changes: 34 additions & 18 deletions cvat-sdk/cvat_sdk/core/uploading.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
import os
import os.path as osp
from contextlib import ExitStack, closing
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Sequence, Tuple
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Tuple

import requests
import urllib3

from cvat_sdk.api_client import exceptions
from cvat_sdk.api_client.api_client import ApiClient, Endpoint
from cvat_sdk.api_client.rest import RESTClientObject
from cvat_sdk.core.helpers import StreamWithProgress, expect_status
Expand Down Expand Up @@ -80,21 +81,9 @@ def _wait_for_completion(
url: str,
*,
success_status: int,
status_check_period: Optional[int] = None,
query_params: Optional[Dict[str, Any]] = None,
post_params: Optional[Dict[str, Any]] = None,
method: str = "POST",
positive_statuses: Optional[Sequence[int]] = None,
**kwargs,
) -> urllib3.HTTPResponse:
return self._client.wait_for_completion(
url,
success_status=success_status,
status_check_period=status_check_period,
query_params=query_params,
post_params=post_params,
method=method,
positive_statuses=positive_statuses,
)
return self._client.wait_for_completion(url, success_status=success_status, **kwargs)

def _split_files_by_requests(
self, filenames: List[str]
Expand Down Expand Up @@ -212,6 +201,7 @@ def get_offset(self):
http request to the tus server to retrieve the offset.
"""
# FIXME: traefik changes HEAD to GET for some reason, and it breaks the protocol
# https://github.com/opencv/cvat/issues/4839

# Assume we are starting from scratch. This effectively disallows us to resume
# old file uploading
Expand Down Expand Up @@ -315,12 +305,38 @@ def upload_file_and_wait(
url_params: Optional[Dict[str, Any]] = None,
pbar: Optional[ProgressReporter] = None,
status_check_period: Optional[int] = None,
restart: bool = False,
):
url = self._client.api_map.make_endpoint_url(endpoint.path, kwsub=url_params)
params = {"format": format_name, "filename": osp.basename(filename)}
self.upload_file(
url, filename, pbar=pbar, query_params=params, meta={"filename": params["filename"]}
)

try:
self.upload_file(
url, filename, pbar=pbar, query_params=params, meta={"filename": params["filename"]}
)
except exceptions.ApiException as ex:
if ex.status == 409 and restart:
self._client.logger.debug(f"Failed to upload dataset: {ex}. Retrying...")

# Remove the previous request
# TODO: Not sure if it works at all
self._wait_for_completion(
url,
success_status=201,
positive_statuses=[202],
status_check_period=status_check_period,
query_params=params,
method="GET",
max_checks=1,
)

self.upload_file(
url,
filename,
pbar=pbar,
query_params=params,
meta={"filename": params["filename"]},
)

self._wait_for_completion(
url,
Expand Down
1 change: 1 addition & 0 deletions cvat-sdk/gen/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# SPDX-License-Identifier: MIT

set -e
set -x

GENERATOR_VERSION="v6.0.1"

Expand Down
11 changes: 3 additions & 8 deletions cvat/apps/engine/cloud_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,15 @@

from cvat.apps.engine.log import slogger
from cvat.apps.engine.models import CredentialsTypeChoice, CloudProviderChoice
from cvat.apps.engine.utils import DjangoEnum, StrEnum

class Status(str, Enum):
class Status(DjangoEnum, StrEnum):
AVAILABLE = 'AVAILABLE'
NOT_FOUND = 'NOT_FOUND'
FORBIDDEN = 'FORBIDDEN'

@classmethod
def choices(cls):
return tuple((x.value, x.name) for x in cls)

def __str__(self):
return self.value

class Permissions(str, Enum):
class Permissions(DjangoEnum, StrEnum):
READ = 'read'
WRITE = 'write'

Expand Down
Loading