cvat-cli 2.69.0__tar.gz → 2.70.0__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.
Files changed (27) hide show
  1. {cvat_cli-2.69.0 → cvat_cli-2.70.0}/PKG-INFO +2 -2
  2. {cvat_cli-2.69.0 → cvat_cli-2.70.0}/pyproject.toml +1 -1
  3. {cvat_cli-2.69.0 → cvat_cli-2.70.0}/src/cvat_cli/_internal/agent_driver.py +24 -3
  4. {cvat_cli-2.69.0 → cvat_cli-2.70.0}/src/cvat_cli/_internal/agent_driver_detection.py +44 -4
  5. {cvat_cli-2.69.0 → cvat_cli-2.70.0}/src/cvat_cli/_internal/agent_driver_tracking.py +5 -2
  6. {cvat_cli-2.69.0 → cvat_cli-2.70.0}/src/cvat_cli/_internal/commands_functions.py +5 -47
  7. {cvat_cli-2.69.0 → cvat_cli-2.70.0}/src/cvat_cli/_internal/common.py +14 -99
  8. cvat_cli-2.70.0/src/cvat_cli/version.py +1 -0
  9. {cvat_cli-2.69.0 → cvat_cli-2.70.0}/src/cvat_cli.egg-info/PKG-INFO +2 -2
  10. {cvat_cli-2.69.0 → cvat_cli-2.70.0}/src/cvat_cli.egg-info/requires.txt +1 -1
  11. cvat_cli-2.69.0/src/cvat_cli/version.py +0 -1
  12. {cvat_cli-2.69.0 → cvat_cli-2.70.0}/README.md +0 -0
  13. {cvat_cli-2.69.0 → cvat_cli-2.70.0}/setup.cfg +0 -0
  14. {cvat_cli-2.69.0 → cvat_cli-2.70.0}/src/cvat_cli/__init__.py +0 -0
  15. {cvat_cli-2.69.0 → cvat_cli-2.70.0}/src/cvat_cli/__main__.py +0 -0
  16. {cvat_cli-2.69.0 → cvat_cli-2.70.0}/src/cvat_cli/_internal/__init__.py +0 -0
  17. {cvat_cli-2.69.0 → cvat_cli-2.70.0}/src/cvat_cli/_internal/agent.py +0 -0
  18. {cvat_cli-2.69.0 → cvat_cli-2.70.0}/src/cvat_cli/_internal/command_base.py +0 -0
  19. {cvat_cli-2.69.0 → cvat_cli-2.70.0}/src/cvat_cli/_internal/commands_all.py +0 -0
  20. {cvat_cli-2.69.0 → cvat_cli-2.70.0}/src/cvat_cli/_internal/commands_projects.py +0 -0
  21. {cvat_cli-2.69.0 → cvat_cli-2.70.0}/src/cvat_cli/_internal/commands_tasks.py +0 -0
  22. {cvat_cli-2.69.0 → cvat_cli-2.70.0}/src/cvat_cli/_internal/parsers.py +0 -0
  23. {cvat_cli-2.69.0 → cvat_cli-2.70.0}/src/cvat_cli/_internal/utils.py +0 -0
  24. {cvat_cli-2.69.0 → cvat_cli-2.70.0}/src/cvat_cli.egg-info/SOURCES.txt +0 -0
  25. {cvat_cli-2.69.0 → cvat_cli-2.70.0}/src/cvat_cli.egg-info/dependency_links.txt +0 -0
  26. {cvat_cli-2.69.0 → cvat_cli-2.70.0}/src/cvat_cli.egg-info/entry_points.txt +0 -0
  27. {cvat_cli-2.69.0 → cvat_cli-2.70.0}/src/cvat_cli.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cvat-cli
3
- Version: 2.69.0
3
+ Version: 2.70.0
4
4
  Summary: Command-line client for CVAT
5
5
  Author-email: "CVAT.ai Corporation" <support@cvat.ai>
6
6
  License-Expression: MIT
@@ -9,7 +9,7 @@ Classifier: Programming Language :: Python :: 3
9
9
  Classifier: Operating System :: OS Independent
10
10
  Requires-Python: >=3.10
11
11
  Description-Content-Type: text/markdown
12
- Requires-Dist: cvat-sdk==2.69.0
12
+ Requires-Dist: cvat-sdk==2.70.0
13
13
  Requires-Dist: attrs>=24.2.0
14
14
  Requires-Dist: Pillow>=10.3.0
15
15
 
@@ -16,7 +16,7 @@ classifiers = [
16
16
  ]
17
17
  requires-python = ">=3.10"
18
18
  dependencies = [
19
- "cvat-sdk==2.69.0",
19
+ "cvat-sdk==2.70.0",
20
20
 
21
21
  "attrs>=24.2.0",
22
22
  "Pillow>=10.3.0",
@@ -5,7 +5,7 @@
5
5
  from __future__ import annotations
6
6
 
7
7
  from collections.abc import Callable
8
- from typing import TYPE_CHECKING, Any, ClassVar, Protocol
8
+ from typing import TYPE_CHECKING, Any, ClassVar, Generic, Protocol, TypeVar
9
9
 
10
10
  import cvat_sdk.auto_annotation as cvataa
11
11
  import cvat_sdk.datasets as cvatds
@@ -47,10 +47,13 @@ class CheckInCallback(Protocol):
47
47
  """
48
48
 
49
49
 
50
- class AgentFunctionDriver:
50
+ SpecT = TypeVar("SpecT")
51
+
52
+
53
+ class AgentFunctionDriver(Generic[SpecT]):
51
54
  FUNCTION_KIND: ClassVar[str]
52
55
 
53
- def __init__(self, client: Client, executor: RecoverableExecutor, function_spec: object):
56
+ def __init__(self, client: Client, executor: RecoverableExecutor, function_spec: SpecT) -> None:
54
57
  self._client = client
55
58
  self._executor = executor
56
59
  self._function_spec = function_spec
@@ -59,6 +62,10 @@ class AgentFunctionDriver:
59
62
  def init_worker(cls, state_id_generator: TrackingStateIdGenerator) -> None:
60
63
  pass
61
64
 
65
+ @classmethod
66
+ def get_remote_function_fields(cls, spec: SpecT) -> dict[str, Any]:
67
+ raise NotImplementedError
68
+
62
69
  def validate_function_compatibility(self, remote_function: dict) -> None:
63
70
  raise NotImplementedError
64
71
 
@@ -93,3 +100,17 @@ class AgentFunctionDriver:
93
100
  raise BadArError(f"Frame with index {frame_index} does not exist in the task")
94
101
 
95
102
  return sample, ds.labels
103
+
104
+ def _load_image_for_ar(self, sample, ar_params):
105
+ image = sample.media.load_image()
106
+
107
+ if roi := ar_params.get("roi"):
108
+ xtl, ytl, xbr, ybr = roi
109
+ width, height = image.size
110
+
111
+ if xbr > width or ybr > height:
112
+ raise BadArError("Invalid ROI")
113
+
114
+ return image.crop((xtl, ytl, xbr, ybr))
115
+
116
+ return image
@@ -30,9 +30,45 @@ def _worker_job_detect(
30
30
  return current_function.detect(context, image)
31
31
 
32
32
 
33
- class AgentDetectionFunctionDriver(AgentFunctionDriver):
33
+ class AgentDetectionFunctionDriver(AgentFunctionDriver[cvataa.DetectionFunctionSpec]):
34
34
  FUNCTION_KIND = "detector"
35
- _function_spec: cvataa.DetectionFunctionSpec
35
+
36
+ @staticmethod
37
+ def _dump_sublabel_spec(
38
+ sl_spec: models.SublabelRequest | models.PatchedLabelRequest,
39
+ ) -> dict:
40
+ result = {
41
+ "name": sl_spec.name,
42
+ "attributes": [
43
+ {
44
+ "name": attribute_spec.name,
45
+ "input_type": attribute_spec.input_type,
46
+ "values": attribute_spec.values,
47
+ }
48
+ for attribute_spec in getattr(sl_spec, "attributes", [])
49
+ ],
50
+ }
51
+
52
+ if getattr(sl_spec, "type", "any") != "any":
53
+ # Add the type conditionally, to stay compatible with older
54
+ # CVAT versions when the function doesn't define label types.
55
+ result["type"] = sl_spec.type
56
+
57
+ return result
58
+
59
+ @classmethod
60
+ def get_remote_function_fields(cls, spec: cvataa.DetectionFunctionSpec) -> dict[str, Any]:
61
+ labels_v2 = []
62
+
63
+ for label_spec in spec.labels:
64
+ labels_v2.append(cls._dump_sublabel_spec(label_spec))
65
+
66
+ if sublabels := getattr(label_spec, "sublabels", None):
67
+ labels_v2[-1]["sublabels"] = [
68
+ cls._dump_sublabel_spec(sublabel) for sublabel in sublabels
69
+ ]
70
+
71
+ return {"labels_v2": labels_v2}
36
72
 
37
73
  def _validate_sublabel_compatibility(
38
74
  self, remote_sl: dict, sl: models.Sublabel | None, sl_desc: str
@@ -134,7 +170,9 @@ class AgentDetectionFunctionDriver(AgentFunctionDriver):
134
170
  for sample_index, sample in enumerate(samples):
135
171
  context = self._create_detection_function_context(ar_params, sample.frame_name)
136
172
  annotations = self._executor.result(
137
- self._executor.submit(_worker_job_detect, context, sample.media.load_image())
173
+ self._executor.submit(
174
+ _worker_job_detect, context, self._load_image_for_ar(sample, ar_params)
175
+ )
138
176
  )
139
177
 
140
178
  tags, shapes = mapper.validate_and_remap(annotations, sample.frame_index)
@@ -155,7 +193,9 @@ class AgentDetectionFunctionDriver(AgentFunctionDriver):
155
193
  context = self._create_detection_function_context(ar_params, sample.frame_name)
156
194
 
157
195
  annotations = self._executor.result(
158
- self._executor.submit(_worker_job_detect, context, sample.media.load_image())
196
+ self._executor.submit(
197
+ _worker_job_detect, context, self._load_image_for_ar(sample, ar_params)
198
+ )
159
199
  )
160
200
 
161
201
  tags, shapes = mapper.validate_and_remap(annotations, sample.frame_index)
@@ -146,9 +146,8 @@ class _TrackingFunctionShapeContextImpl(cvataa.TrackingFunctionShapeContext):
146
146
  original_shape_type: str
147
147
 
148
148
 
149
- class AgentTrackingFunctionDriver(AgentFunctionDriver):
149
+ class AgentTrackingFunctionDriver(AgentFunctionDriver[cvataa.TrackingFunctionSpec]):
150
150
  FUNCTION_KIND = "tracker"
151
- _function_spec: cvataa.TrackingFunctionSpec
152
151
 
153
152
  @classmethod
154
153
  def init_worker(cls, state_id_generator: TrackingStateIdGenerator) -> None:
@@ -158,6 +157,10 @@ class AgentTrackingFunctionDriver(AgentFunctionDriver):
158
157
  global _tracking_state_id_generator
159
158
  _tracking_state_id_generator = state_id_generator
160
159
 
160
+ @classmethod
161
+ def get_remote_function_fields(cls, spec: cvataa.TrackingFunctionSpec) -> dict[str, Any]:
162
+ return {"supported_shape_types": sorted(spec.supported_shape_types)}
163
+
161
164
  def validate_function_compatibility(self, remote_function: dict) -> None:
162
165
  remote_supported_shape_types = frozenset(remote_function["supported_shape_types"])
163
166
  unsupported = remote_supported_shape_types - self._function_spec.supported_shape_types
@@ -8,12 +8,9 @@ import textwrap
8
8
  from collections.abc import Sequence
9
9
  from typing import Any
10
10
 
11
- import cvat_sdk.auto_annotation as cvataa
12
- from cvat_sdk import Client, models
11
+ from cvat_sdk import Client
13
12
 
14
- from .agent import FUNCTION_PROVIDER_NATIVE, run_agent
15
- from .agent_driver_detection import AgentDetectionFunctionDriver
16
- from .agent_driver_tracking import AgentTrackingFunctionDriver
13
+ from .agent import FUNCTION_PROVIDER_NATIVE, get_function_driver_class, run_agent
17
14
  from .command_base import CommandGroup
18
15
  from .common import FunctionLoader, configure_function_implementation_arguments
19
16
 
@@ -40,29 +37,6 @@ class FunctionCreateNative:
40
37
 
41
38
  configure_function_implementation_arguments(parser)
42
39
 
43
- @staticmethod
44
- def _dump_sublabel_spec(
45
- sl_spec: models.SublabelRequest | models.PatchedLabelRequest,
46
- ) -> dict:
47
- result = {
48
- "name": sl_spec.name,
49
- "attributes": [
50
- {
51
- "name": attribute_spec.name,
52
- "input_type": attribute_spec.input_type,
53
- "values": attribute_spec.values,
54
- }
55
- for attribute_spec in getattr(sl_spec, "attributes", [])
56
- ],
57
- }
58
-
59
- if getattr(sl_spec, "type", "any") != "any":
60
- # Add the type conditionally, to stay compatible with older
61
- # CVAT versions when the function doesn't define label types.
62
- result["type"] = sl_spec.type
63
-
64
- return result
65
-
66
40
  def execute(
67
41
  self,
68
42
  client: Client,
@@ -72,32 +46,16 @@ class FunctionCreateNative:
72
46
  function_loader: FunctionLoader,
73
47
  ) -> None:
74
48
  function = function_loader.load()
49
+ driver_class = get_function_driver_class(function.spec)
75
50
 
76
51
  remote_function: dict[str, Any] = {
77
52
  "provider": FUNCTION_PROVIDER_NATIVE,
78
53
  "name": name,
79
54
  "visibility": visibility,
55
+ "kind": driver_class.FUNCTION_KIND,
56
+ **driver_class.get_remote_function_fields(function.spec),
80
57
  }
81
58
 
82
- spec = function.spec
83
-
84
- if isinstance(spec, cvataa.DetectionFunctionSpec):
85
- remote_function["kind"] = AgentDetectionFunctionDriver.FUNCTION_KIND
86
- remote_function["labels_v2"] = []
87
-
88
- for label_spec in spec.labels:
89
- remote_function["labels_v2"].append(self._dump_sublabel_spec(label_spec))
90
-
91
- if sublabels := getattr(label_spec, "sublabels", None):
92
- remote_function["labels_v2"][-1]["sublabels"] = [
93
- self._dump_sublabel_spec(sublabel) for sublabel in sublabels
94
- ]
95
- elif isinstance(spec, cvataa.TrackingFunctionSpec):
96
- remote_function["kind"] = AgentTrackingFunctionDriver.FUNCTION_KIND
97
- remote_function["supported_shape_types"] = sorted(spec.supported_shape_types)
98
- else:
99
- raise cvataa.BadFunctionError(f"Unsupported function spec type: {type(spec).__name__}")
100
-
101
59
  _, response = client.api_client.call_api(
102
60
  "/api/functions",
103
61
  "POST",
@@ -4,27 +4,23 @@
4
4
  # SPDX-License-Identifier: MIT
5
5
 
6
6
  import argparse
7
- import getpass
8
7
  import importlib
9
8
  import importlib.util
10
9
  import logging
11
- import os
12
10
  import sys
13
- import textwrap
14
- from collections.abc import Callable
15
11
  from http.client import HTTPConnection
16
12
  from pathlib import Path
17
13
  from typing import Any
18
14
 
19
15
  import attrs
20
16
  import cvat_sdk.auto_annotation as cvataa
21
- from cvat_sdk.core.client import (
22
- AccessTokenCredentials,
23
- Client,
24
- Config,
25
- Credentials,
26
- PasswordCredentials,
17
+ from cvat_sdk.core.auth import (
18
+ ClientAuthParameters,
19
+ configure_client_auth_arguments,
20
+ make_client_from_cli,
27
21
  )
22
+ from cvat_sdk.core.client import Client
23
+ from cvat_sdk.core.exceptions import AuthStoreError
28
24
 
29
25
  from ..version import VERSION
30
26
  from .parsers import BuildDictAction, parse_function_parameter
@@ -35,82 +31,9 @@ class CriticalError(Exception):
35
31
  pass
36
32
 
37
33
 
38
- CVAT_ACCESS_TOKEN_ENV_VAR = "CVAT_ACCESS_TOKEN" # nosec - a variable name declaration
39
-
40
-
41
- def default_auth_factory() -> Callable[[str], Credentials]:
42
- """
43
- Try to read the CVAT_ACCESS_TOKEN environment variable for a Personal Access Token (PAT).
44
- If there is no value, try using the current user and asking for the password.
45
- """
46
-
47
- token = os.getenv(CVAT_ACCESS_TOKEN_ENV_VAR)
48
- if token is not None:
49
- return lambda _: AccessTokenCredentials(token)
50
-
51
- return get_auth_factory(getpass.getuser())
52
-
53
-
54
- def get_auth_factory(s: str) -> Callable[[str], Credentials]:
55
- """
56
- Parse a USER[:PASS] string and return a callable that takes the server URL
57
- and returns auth credentials for that URL.
58
- The callable will prompt the user for the password if none was initially supplied in the
59
- input string and in the PASS env variable.
60
- """
61
-
62
- user, _, password = s.partition(":")
63
- if not password:
64
- password = os.environ.get("PASS")
65
-
66
- if password:
67
- return lambda _: PasswordCredentials(user, password)
68
- else:
69
- return lambda url: PasswordCredentials(
70
- user, getpass.getpass(f"Password for {user} at {url}: ")
71
- )
72
-
73
-
74
34
  def configure_common_arguments(parser: argparse.ArgumentParser) -> None:
75
35
  parser.add_argument("--version", action="version", version=VERSION)
76
- parser.add_argument(
77
- "--insecure",
78
- action="store_true",
79
- help="Allows to disable SSL certificate check",
80
- )
81
-
82
- parser.add_argument(
83
- "--auth",
84
- type=get_auth_factory,
85
- metavar="USER[:PASS]",
86
- default=default_auth_factory(),
87
- help=textwrap.dedent("""\
88
- User and password to use for authentication;
89
- defaults to the current user and supports the PASS
90
- environment variable or password prompt.
91
- A Personal Access Token (PAT) can be generated on the server
92
- and specified in the {} environment variable instead.
93
- (default user: {}).
94
- """).format(CVAT_ACCESS_TOKEN_ENV_VAR, getpass.getuser()),
95
- )
96
- parser.add_argument(
97
- "--server-host", type=str, default="http://localhost", help="host (default: %(default)s)"
98
- )
99
- parser.add_argument(
100
- "--server-port",
101
- type=int,
102
- default=None,
103
- help="port (default: 80 for http and 443 for https connections)",
104
- )
105
- parser.add_argument(
106
- "--organization",
107
- "--org",
108
- metavar="SLUG",
109
- help="""short name (slug) of the organization
110
- to use when listing or creating resources;
111
- set to blank string to use the personal workspace
112
- (default: list all accessible objects, create in personal workspace)""",
113
- )
36
+ configure_client_auth_arguments(parser)
114
37
  parser.add_argument(
115
38
  "--debug",
116
39
  action="store_const",
@@ -135,24 +58,16 @@ def configure_logger(logger: logging.Logger, parsed_args: argparse.Namespace) ->
135
58
 
136
59
 
137
60
  def build_client(parsed_args: argparse.Namespace, logger: logging.Logger) -> Client:
138
- config = Config(verify_ssl=not popattr(parsed_args, "insecure"))
139
-
140
- url = popattr(parsed_args, "server_host")
141
- if server_port := popattr(parsed_args, "server_port"):
142
- url += f":{server_port}"
61
+ auth_args = ClientAuthParameters.from_namespace(parsed_args)
62
+ for field in attrs.fields(ClientAuthParameters):
63
+ popattr(parsed_args, field.name)
143
64
 
144
- client = Client(
145
- url=url,
146
- logger=logger,
147
- config=config,
148
- check_server_version=False, # version is checked after auth to support versions < 2.3
149
- )
65
+ try:
66
+ client = make_client_from_cli(auth_args, logger=logger)
67
+ except AuthStoreError as e:
68
+ raise CriticalError(str(e)) from e
150
69
 
151
- client.login(popattr(parsed_args, "auth")(client.api_client.configuration.host))
152
70
  client.check_server_version(fail_if_unsupported=False)
153
-
154
- client.organization_slug = popattr(parsed_args, "organization")
155
-
156
71
  return client
157
72
 
158
73
 
@@ -0,0 +1 @@
1
+ VERSION = "2.70.0"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cvat-cli
3
- Version: 2.69.0
3
+ Version: 2.70.0
4
4
  Summary: Command-line client for CVAT
5
5
  Author-email: "CVAT.ai Corporation" <support@cvat.ai>
6
6
  License-Expression: MIT
@@ -9,7 +9,7 @@ Classifier: Programming Language :: Python :: 3
9
9
  Classifier: Operating System :: OS Independent
10
10
  Requires-Python: >=3.10
11
11
  Description-Content-Type: text/markdown
12
- Requires-Dist: cvat-sdk==2.69.0
12
+ Requires-Dist: cvat-sdk==2.70.0
13
13
  Requires-Dist: attrs>=24.2.0
14
14
  Requires-Dist: Pillow>=10.3.0
15
15
 
@@ -1,3 +1,3 @@
1
- cvat-sdk==2.69.0
1
+ cvat-sdk==2.70.0
2
2
  attrs>=24.2.0
3
3
  Pillow>=10.3.0
@@ -1 +0,0 @@
1
- VERSION = "2.69.0"
File without changes
File without changes