arkindex-base-worker 0.3.6rc4__py3-none-any.whl → 0.3.7__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.
Files changed (41) hide show
  1. arkindex_base_worker-0.3.7.dist-info/LICENSE +21 -0
  2. arkindex_base_worker-0.3.7.dist-info/METADATA +77 -0
  3. arkindex_base_worker-0.3.7.dist-info/RECORD +47 -0
  4. {arkindex_base_worker-0.3.6rc4.dist-info → arkindex_base_worker-0.3.7.dist-info}/WHEEL +1 -1
  5. {arkindex_base_worker-0.3.6rc4.dist-info → arkindex_base_worker-0.3.7.dist-info}/top_level.txt +2 -0
  6. arkindex_worker/cache.py +14 -0
  7. arkindex_worker/image.py +29 -19
  8. arkindex_worker/models.py +14 -2
  9. arkindex_worker/utils.py +17 -3
  10. arkindex_worker/worker/__init__.py +122 -125
  11. arkindex_worker/worker/base.py +24 -24
  12. arkindex_worker/worker/classification.py +18 -25
  13. arkindex_worker/worker/dataset.py +24 -18
  14. arkindex_worker/worker/element.py +100 -19
  15. arkindex_worker/worker/entity.py +35 -4
  16. arkindex_worker/worker/metadata.py +21 -11
  17. arkindex_worker/worker/training.py +13 -0
  18. arkindex_worker/worker/transcription.py +45 -5
  19. arkindex_worker/worker/version.py +22 -0
  20. hooks/pre_gen_project.py +3 -0
  21. tests/conftest.py +16 -8
  22. tests/test_base_worker.py +0 -6
  23. tests/test_dataset_worker.py +291 -409
  24. tests/test_elements_worker/test_classifications.py +365 -539
  25. tests/test_elements_worker/test_cli.py +1 -1
  26. tests/test_elements_worker/test_dataset.py +97 -116
  27. tests/test_elements_worker/test_elements.py +354 -76
  28. tests/test_elements_worker/test_entities.py +22 -2
  29. tests/test_elements_worker/test_metadata.py +53 -27
  30. tests/test_elements_worker/test_training.py +35 -0
  31. tests/test_elements_worker/test_transcriptions.py +149 -16
  32. tests/test_elements_worker/test_worker.py +19 -6
  33. tests/test_image.py +37 -0
  34. tests/test_utils.py +23 -1
  35. worker-demo/tests/__init__.py +0 -0
  36. worker-demo/tests/conftest.py +32 -0
  37. worker-demo/tests/test_worker.py +12 -0
  38. worker-demo/worker_demo/__init__.py +6 -0
  39. worker-demo/worker_demo/worker.py +19 -0
  40. arkindex_base_worker-0.3.6rc4.dist-info/METADATA +0 -47
  41. arkindex_base_worker-0.3.6rc4.dist-info/RECORD +0 -40
@@ -1,14 +1,16 @@
1
1
  """
2
2
  ElementsWorker methods for elements and element types.
3
3
  """
4
+
4
5
  from collections.abc import Iterable
5
6
  from typing import NamedTuple
6
7
  from uuid import UUID
8
+ from warnings import warn
7
9
 
8
10
  from peewee import IntegrityError
9
11
 
10
12
  from arkindex_worker import logger
11
- from arkindex_worker.cache import CachedElement, CachedImage
13
+ from arkindex_worker.cache import CachedElement, CachedImage, unsupported_cache
12
14
  from arkindex_worker.models import Element
13
15
 
14
16
 
@@ -29,6 +31,7 @@ class MissingTypeError(Exception):
29
31
 
30
32
 
31
33
  class ElementMixin:
34
+ @unsupported_cache
32
35
  def create_required_types(self, element_types: list[ElementType]):
33
36
  """Creates given element types in the corpus.
34
37
 
@@ -81,13 +84,15 @@ class ElementMixin:
81
84
 
82
85
  return True
83
86
 
87
+ @unsupported_cache
84
88
  def create_sub_element(
85
89
  self,
86
90
  element: Element,
87
91
  type: str,
88
92
  name: str,
89
- polygon: list[list[int | float]],
93
+ polygon: list[list[int | float]] | None = None,
90
94
  confidence: float | None = None,
95
+ image: str | None = None,
91
96
  slim_output: bool = True,
92
97
  ) -> str:
93
98
  """
@@ -96,8 +101,10 @@ class ElementMixin:
96
101
  :param Element element: The parent element.
97
102
  :param type: Slug of the element type for this child element.
98
103
  :param name: Name of the child element.
99
- :param polygon: Polygon of the child element.
104
+ :param polygon: Optional polygon of the child element.
100
105
  :param confidence: Optional confidence score, between 0.0 and 1.0.
106
+ :param image: Optional image ID of the child element.
107
+ :param slim_output: Whether to return the child ID or the full child.
101
108
  :returns: UUID of the created element.
102
109
  """
103
110
  assert element and isinstance(
@@ -109,19 +116,29 @@ class ElementMixin:
109
116
  assert name and isinstance(
110
117
  name, str
111
118
  ), "name shouldn't be null and should be of type str"
112
- assert polygon and isinstance(
119
+ assert polygon is None or isinstance(
113
120
  polygon, list
114
- ), "polygon shouldn't be null and should be of type list"
115
- assert len(polygon) >= 3, "polygon should have at least three points"
116
- assert all(
117
- isinstance(point, list) and len(point) == 2 for point in polygon
118
- ), "polygon points should be lists of two items"
119
- assert all(
120
- isinstance(coord, int | float) for point in polygon for coord in point
121
- ), "polygon points should be lists of two numbers"
121
+ ), "polygon should be None or a list"
122
+ if polygon is not None:
123
+ assert len(polygon) >= 3, "polygon should have at least three points"
124
+ assert all(
125
+ isinstance(point, list) and len(point) == 2 for point in polygon
126
+ ), "polygon points should be lists of two items"
127
+ assert all(
128
+ isinstance(coord, int | float) for point in polygon for coord in point
129
+ ), "polygon points should be lists of two numbers"
122
130
  assert confidence is None or (
123
131
  isinstance(confidence, float) and 0 <= confidence <= 1
124
132
  ), "confidence should be None or a float in [0..1] range"
133
+ assert image is None or isinstance(image, str), "image should be None or string"
134
+ if image is not None:
135
+ # Make sure it's a valid UUID
136
+ try:
137
+ UUID(image)
138
+ except ValueError as e:
139
+ raise ValueError("image is not a valid uuid.") from e
140
+ if polygon and image is None:
141
+ assert element.zone, "An image or a parent with an image is required to create an element with a polygon."
125
142
  assert isinstance(slim_output, bool), "slim_output should be of type bool"
126
143
 
127
144
  if self.is_read_only:
@@ -133,7 +150,7 @@ class ElementMixin:
133
150
  body={
134
151
  "type": type,
135
152
  "name": name,
136
- "image": element.zone.image.id,
153
+ "image": image,
137
154
  "corpus": element.corpus.id,
138
155
  "polygon": polygon,
139
156
  "parent": element.id,
@@ -270,6 +287,36 @@ class ElementMixin:
270
287
 
271
288
  return created_ids
272
289
 
290
+ @unsupported_cache
291
+ def create_element_parent(
292
+ self,
293
+ parent: Element,
294
+ child: Element,
295
+ ) -> dict[str, str]:
296
+ """
297
+ Link an element to a parent through the API.
298
+
299
+ :param parent: Parent element.
300
+ :param child: Child element.
301
+ :returns: A dict from the ``CreateElementParent`` API endpoint.
302
+ """
303
+ assert parent and isinstance(
304
+ parent, Element
305
+ ), "parent shouldn't be null and should be of type Element"
306
+ assert child and isinstance(
307
+ child, Element
308
+ ), "child shouldn't be null and should be of type Element"
309
+
310
+ if self.is_read_only:
311
+ logger.warning("Cannot link elements as this worker is in read-only mode")
312
+ return
313
+
314
+ return self.request(
315
+ "CreateElementParent",
316
+ parent=parent.id,
317
+ child=child.id,
318
+ )
319
+
273
320
  def partial_update_element(
274
321
  self, element: Element | CachedElement, **kwargs
275
322
  ) -> dict:
@@ -288,7 +335,7 @@ class ElementMixin:
288
335
  * *image* (``UUID``): Optional ID of the image of this element
289
336
 
290
337
 
291
- :returns: A dict from the ``PartialUpdateElement`` API endpoint,
338
+ :returns: A dict from the ``PartialUpdateElement`` API endpoint.
292
339
  """
293
340
  assert element and isinstance(
294
341
  element, Element | CachedElement
@@ -380,6 +427,13 @@ class ElementMixin:
380
427
  """
381
428
  List children of an element.
382
429
 
430
+ Warns:
431
+ ----
432
+ The following parameters are **deprecated**:
433
+
434
+ - `transcription_worker_version` in favor of `transcription_worker_run`
435
+ - `worker_version` in favor of `worker_run`
436
+
383
437
  :param element: Parent element to find children of.
384
438
  :param folder: Restrict to or exclude elements with folder types.
385
439
  This parameter is not supported when caching is enabled.
@@ -387,9 +441,9 @@ class ElementMixin:
387
441
  This parameter is not supported when caching is enabled.
388
442
  :param recursive: Look for elements recursively (grand-children, etc.)
389
443
  This parameter is not supported when caching is enabled.
390
- :param transcription_worker_version: Restrict to elements that have a transcription created by a worker version with this UUID.
444
+ :param transcription_worker_version: **Deprecated** Restrict to elements that have a transcription created by a worker version with this UUID. Set to False to look for elements that have a manual transcription.
391
445
  This parameter is not supported when caching is enabled.
392
- :param transcription_worker_run: Restrict to elements that have a transcription created by a worker run with this UUID.
446
+ :param transcription_worker_run: Restrict to elements that have a transcription created by a worker run with this UUID. Set to False to look for elements that have a manual transcription.
393
447
  This parameter is not supported when caching is enabled.
394
448
  :param type: Restrict to elements with a specific type slug
395
449
  This parameter is not supported when caching is enabled.
@@ -405,7 +459,7 @@ class ElementMixin:
405
459
  :param with_zone: Include the ``zone`` attribute in the response,
406
460
  holding the element's image and polygon.
407
461
  This parameter is not supported when caching is enabled.
408
- :param worker_version: Restrict to elements created by a worker version with this UUID.
462
+ :param worker_version: **Deprecated** Restrict to elements created by a worker version with this UUID.
409
463
  :param worker_run: Restrict to elements created by a worker run with this UUID.
410
464
  :return: An iterable of dicts from the ``ListElementChildren`` API endpoint,
411
465
  or an iterable of [CachedElement][arkindex_worker.cache.CachedElement] when caching is enabled.
@@ -424,6 +478,11 @@ class ElementMixin:
424
478
  assert isinstance(recursive, bool), "recursive should be of type bool"
425
479
  query_params["recursive"] = recursive
426
480
  if transcription_worker_version is not None:
481
+ warn(
482
+ "`transcription_worker_version` usage is deprecated. Consider using `transcription_worker_run` instead.",
483
+ DeprecationWarning,
484
+ stacklevel=1,
485
+ )
427
486
  assert isinstance(
428
487
  transcription_worker_version, str | bool
429
488
  ), "transcription_worker_version should be of type str or bool"
@@ -464,6 +523,11 @@ class ElementMixin:
464
523
  assert isinstance(with_zone, bool), "with_zone should be of type bool"
465
524
  query_params["with_zone"] = with_zone
466
525
  if worker_version is not None:
526
+ warn(
527
+ "`worker_version` usage is deprecated. Consider using `worker_run` instead.",
528
+ DeprecationWarning,
529
+ stacklevel=1,
530
+ )
467
531
  assert isinstance(
468
532
  worker_version, str | bool
469
533
  ), "worker_version should be of type str or bool"
@@ -542,6 +606,13 @@ class ElementMixin:
542
606
  """
543
607
  List parents of an element.
544
608
 
609
+ Warns:
610
+ ----
611
+ The following parameters are **deprecated**:
612
+
613
+ - `transcription_worker_version` in favor of `transcription_worker_run`
614
+ - `worker_version` in favor of `worker_run`
615
+
545
616
  :param element: Child element to find parents of.
546
617
  :param folder: Restrict to or exclude elements with folder types.
547
618
  This parameter is not supported when caching is enabled.
@@ -549,7 +620,7 @@ class ElementMixin:
549
620
  This parameter is not supported when caching is enabled.
550
621
  :param recursive: Look for elements recursively (grand-children, etc.)
551
622
  This parameter is not supported when caching is enabled.
552
- :param transcription_worker_version: Restrict to elements that have a transcription created by a worker version with this UUID.
623
+ :param transcription_worker_version: **Deprecated** Restrict to elements that have a transcription created by a worker version with this UUID.
553
624
  This parameter is not supported when caching is enabled.
554
625
  :param transcription_worker_run: Restrict to elements that have a transcription created by a worker run with this UUID.
555
626
  This parameter is not supported when caching is enabled.
@@ -567,7 +638,7 @@ class ElementMixin:
567
638
  :param with_zone: Include the ``zone`` attribute in the response,
568
639
  holding the element's image and polygon.
569
640
  This parameter is not supported when caching is enabled.
570
- :param worker_version: Restrict to elements created by a worker version with this UUID.
641
+ :param worker_version: **Deprecated** Restrict to elements created by a worker version with this UUID.
571
642
  :param worker_run: Restrict to elements created by a worker run with this UUID.
572
643
  :return: An iterable of dicts from the ``ListElementParents`` API endpoint,
573
644
  or an iterable of [CachedElement][arkindex_worker.cache.CachedElement] when caching is enabled.
@@ -586,6 +657,11 @@ class ElementMixin:
586
657
  assert isinstance(recursive, bool), "recursive should be of type bool"
587
658
  query_params["recursive"] = recursive
588
659
  if transcription_worker_version is not None:
660
+ warn(
661
+ "`transcription_worker_version` usage is deprecated. Consider using `transcription_worker_run` instead.",
662
+ DeprecationWarning,
663
+ stacklevel=1,
664
+ )
589
665
  assert isinstance(
590
666
  transcription_worker_version, str | bool
591
667
  ), "transcription_worker_version should be of type str or bool"
@@ -626,6 +702,11 @@ class ElementMixin:
626
702
  assert isinstance(with_zone, bool), "with_zone should be of type bool"
627
703
  query_params["with_zone"] = with_zone
628
704
  if worker_version is not None:
705
+ warn(
706
+ "`worker_version` usage is deprecated. Consider using `worker_run` instead.",
707
+ DeprecationWarning,
708
+ stacklevel=1,
709
+ )
629
710
  assert isinstance(
630
711
  worker_version, str | bool
631
712
  ), "worker_version should be of type str or bool"
@@ -4,11 +4,16 @@ ElementsWorker methods for entities.
4
4
 
5
5
  from operator import itemgetter
6
6
  from typing import TypedDict
7
+ from warnings import warn
7
8
 
8
9
  from peewee import IntegrityError
9
10
 
10
11
  from arkindex_worker import logger
11
- from arkindex_worker.cache import CachedEntity, CachedTranscriptionEntity
12
+ from arkindex_worker.cache import (
13
+ CachedEntity,
14
+ CachedTranscriptionEntity,
15
+ unsupported_cache,
16
+ )
12
17
  from arkindex_worker.models import Element, Transcription
13
18
 
14
19
 
@@ -28,6 +33,7 @@ class MissingEntityType(Exception):
28
33
 
29
34
 
30
35
  class EntityMixin:
36
+ @unsupported_cache
31
37
  def check_required_entity_types(
32
38
  self, entity_types: list[str], create_missing: bool = True
33
39
  ):
@@ -205,6 +211,7 @@ class EntityMixin:
205
211
  )
206
212
  return transcription_ent
207
213
 
214
+ @unsupported_cache
208
215
  def create_transcription_entities(
209
216
  self,
210
217
  transcription: Transcription,
@@ -297,13 +304,21 @@ class EntityMixin:
297
304
  self,
298
305
  transcription: Transcription,
299
306
  worker_version: str | bool | None = None,
307
+ worker_run: str | bool | None = None,
300
308
  ):
301
309
  """
302
310
  List existing entities on a transcription
303
311
  This method does not support cache
304
312
 
313
+ Warns:
314
+ ----
315
+ The following parameters are **deprecated**:
316
+
317
+ - `worker_version` in favor of `worker_run`
318
+
305
319
  :param transcription: The transcription to list entities on.
306
- :param worker_version: Restrict to entities created by a worker version with this UUID. Set to False to look for manually created transcriptions.
320
+ :param worker_version: **Deprecated** Restrict to entities created by a worker version with this UUID. Set to False to look for manually created entities.
321
+ :param worker_run: Restrict to entities created by a worker run with this UUID. Set to False to look for manually created entities.
307
322
  """
308
323
  query_params = {}
309
324
  assert transcription and isinstance(
@@ -311,6 +326,11 @@ class EntityMixin:
311
326
  ), "transcription shouldn't be null and should be a Transcription"
312
327
 
313
328
  if worker_version is not None:
329
+ warn(
330
+ "`worker_version` usage is deprecated. Consider using `worker_run` instead.",
331
+ DeprecationWarning,
332
+ stacklevel=1,
333
+ )
314
334
  assert isinstance(
315
335
  worker_version, str | bool
316
336
  ), "worker_version should be of type str or bool"
@@ -320,6 +340,15 @@ class EntityMixin:
320
340
  worker_version is False
321
341
  ), "if of type bool, worker_version can only be set to False"
322
342
  query_params["worker_version"] = worker_version
343
+ if worker_run is not None:
344
+ assert isinstance(
345
+ worker_run, str | bool
346
+ ), "worker_run should be of type str or bool"
347
+ if isinstance(worker_run, bool):
348
+ assert (
349
+ worker_run is False
350
+ ), "if of type bool, worker_run can only be set to False"
351
+ query_params["worker_run"] = worker_run
323
352
 
324
353
  return self.api_client.paginate(
325
354
  "ListTranscriptionEntities", id=transcription.id, **query_params
@@ -351,8 +380,9 @@ class EntityMixin:
351
380
  "ListCorpusEntities", id=self.corpus_id, **query_params
352
381
  )
353
382
  }
383
+ count = len(self.entities)
354
384
  logger.info(
355
- f"Loaded {len(self.entities)} entities in corpus ({self.corpus_id})"
385
+ f'Loaded {count} entit{"ies" if count > 1 else "y"} in corpus ({self.corpus_id})'
356
386
  )
357
387
 
358
388
  def list_corpus_entity_types(
@@ -367,6 +397,7 @@ class EntityMixin:
367
397
  "ListCorpusEntityTypes", id=self.corpus_id
368
398
  )
369
399
  }
400
+ count = len(self.entity_types)
370
401
  logger.info(
371
- f"Loaded {len(self.entity_types)} entity types in corpus ({self.corpus_id})."
402
+ f'Loaded {count} entity type{"s"[:count>1]} in corpus ({self.corpus_id}).'
372
403
  )
@@ -5,7 +5,7 @@ ElementsWorker methods for metadata.
5
5
  from enum import Enum
6
6
 
7
7
  from arkindex_worker import logger
8
- from arkindex_worker.cache import CachedElement
8
+ from arkindex_worker.cache import CachedElement, unsupported_cache
9
9
  from arkindex_worker.models import Element
10
10
 
11
11
 
@@ -50,12 +50,13 @@ class MetaType(Enum):
50
50
 
51
51
  URL = "url"
52
52
  """
53
- A metadata with a string value that should be interpreted as an URL.
53
+ A metadata with a string value that should be interpreted as a URL.
54
54
  Only the ``http`` and ``https`` schemes are allowed.
55
55
  """
56
56
 
57
57
 
58
58
  class MetaDataMixin:
59
+ @unsupported_cache
59
60
  def create_metadata(
60
61
  self,
61
62
  element: Element | CachedElement,
@@ -106,17 +107,18 @@ class MetaDataMixin:
106
107
 
107
108
  return metadata["id"]
108
109
 
109
- def create_metadatas(
110
+ @unsupported_cache
111
+ def create_metadata_bulk(
110
112
  self,
111
113
  element: Element | CachedElement,
112
- metadatas: list[dict[str, MetaType | str | int | float | None]],
114
+ metadata_list: list[dict[str, MetaType | str | int | float | None]],
113
115
  ) -> list[dict[str, str]]:
114
116
  """
115
117
  Create multiple metadata on an existing element.
116
118
  This method does not support cache.
117
119
 
118
120
  :param element: The element to create multiple metadata on.
119
- :param metadatas: The list of dict whose keys are the following:
121
+ :param metadata_list: The list of dict whose keys are the following:
120
122
  - type: MetaType
121
123
  - name: str
122
124
  - value: str | int | float
@@ -126,13 +128,13 @@ class MetaDataMixin:
126
128
  element, Element | CachedElement
127
129
  ), "element shouldn't be null and should be of type Element or CachedElement"
128
130
 
129
- assert metadatas and isinstance(
130
- metadatas, list
131
- ), "type shouldn't be null and should be of type list of Dict"
131
+ assert metadata_list and isinstance(
132
+ metadata_list, list
133
+ ), "metadata_list shouldn't be null and should be of type list of dict"
132
134
 
133
135
  # Make a copy to avoid modifying the metadata_list argument
134
136
  metas = []
135
- for index, metadata in enumerate(metadatas):
137
+ for index, metadata in enumerate(metadata_list):
136
138
  assert isinstance(
137
139
  metadata, dict
138
140
  ), f"Element at index {index} in metadata_list: Should be of type dict"
@@ -178,16 +180,24 @@ class MetaDataMixin:
178
180
  return created_metadata_list
179
181
 
180
182
  def list_element_metadata(
181
- self, element: Element | CachedElement
183
+ self, element: Element | CachedElement, load_parents: bool | None = None
182
184
  ) -> list[dict[str, str]]:
183
185
  """
184
186
  List all metadata linked to an element.
185
187
  This method does not support cache.
186
188
 
187
189
  :param element: The element to list metadata on.
190
+ :param load_parents: Also include all metadata from the element's parents in the response.
188
191
  """
189
192
  assert element and isinstance(
190
193
  element, Element | CachedElement
191
194
  ), "element shouldn't be null and should be of type Element or CachedElement"
192
195
 
193
- return self.api_client.paginate("ListElementMetaData", id=element.id)
196
+ query_params = {}
197
+ if load_parents is not None:
198
+ assert isinstance(load_parents, bool), "load_parents should be of type bool"
199
+ query_params["load_parents"] = load_parents
200
+
201
+ return self.api_client.paginate(
202
+ "ListElementMetaData", id=element.id, **query_params
203
+ )
@@ -81,6 +81,10 @@ class TrainingMixin:
81
81
 
82
82
  model_version = None
83
83
 
84
+ @property
85
+ def is_finetuning(self) -> bool:
86
+ return bool(self.model_version_id)
87
+
84
88
  @skip_if_read_only
85
89
  def publish_model_version(
86
90
  self,
@@ -276,8 +280,17 @@ class TrainingMixin:
276
280
  },
277
281
  )
278
282
  except ErrorResponse as e:
283
+ # Temporary fix while waiting for `ValidateModelVersion` refactoring as it can
284
+ # return errors even when the model version is properly validated
285
+ if e.status_code in [403, 500]:
286
+ logger.warning(
287
+ f'An error occurred while validating model version {self.model_version["id"]}, please check its status.'
288
+ )
289
+ return
290
+
279
291
  if e.status_code != 409:
280
292
  raise e
293
+
281
294
  logger.warning(
282
295
  f"An available model version exists with hash {hash}, using it instead of the pending version."
283
296
  )
@@ -4,6 +4,7 @@ ElementsWorker methods for transcriptions.
4
4
 
5
5
  from collections.abc import Iterable
6
6
  from enum import Enum
7
+ from warnings import warn
7
8
 
8
9
  from peewee import IntegrityError
9
10
 
@@ -366,14 +367,22 @@ class TranscriptionMixin:
366
367
  element_type: str | None = None,
367
368
  recursive: bool | None = None,
368
369
  worker_version: str | bool | None = None,
370
+ worker_run: str | bool | None = None,
369
371
  ) -> Iterable[dict] | Iterable[CachedTranscription]:
370
372
  """
371
373
  List transcriptions on an element.
372
374
 
375
+ Warns:
376
+ ----
377
+ The following parameters are **deprecated**:
378
+
379
+ - `worker_version` in favor of `worker_run`
380
+
373
381
  :param element: The element to list transcriptions on.
374
382
  :param element_type: Restrict to transcriptions whose elements have an element type with this slug.
375
383
  :param recursive: Include transcriptions of any descendant of this element, recursively.
376
- :param worker_version: Restrict to transcriptions created by a worker version with this UUID. Set to False to look for manually created transcriptions.
384
+ :param worker_version: **Deprecated** Restrict to transcriptions created by a worker version with this UUID. Set to False to look for manually created transcriptions.
385
+ :param worker_run: Restrict to transcriptions created by a worker run with this UUID. Set to False to look for manually created transcriptions.
377
386
  :returns: An iterable of dicts representing each transcription,
378
387
  or an iterable of CachedTranscription when cache support is enabled.
379
388
  """
@@ -388,6 +397,11 @@ class TranscriptionMixin:
388
397
  assert isinstance(recursive, bool), "recursive should be of type bool"
389
398
  query_params["recursive"] = recursive
390
399
  if worker_version is not None:
400
+ warn(
401
+ "`worker_version` usage is deprecated. Consider using `worker_run` instead.",
402
+ DeprecationWarning,
403
+ stacklevel=1,
404
+ )
391
405
  assert isinstance(
392
406
  worker_version, str | bool
393
407
  ), "worker_version should be of type str or bool"
@@ -396,6 +410,15 @@ class TranscriptionMixin:
396
410
  worker_version is False
397
411
  ), "if of type bool, worker_version can only be set to False"
398
412
  query_params["worker_version"] = worker_version
413
+ if worker_run is not None:
414
+ assert isinstance(
415
+ worker_run, str | bool
416
+ ), "worker_run should be of type str or bool"
417
+ if isinstance(worker_run, bool):
418
+ assert (
419
+ worker_run is False
420
+ ), "if of type bool, worker_run can only be set to False"
421
+ query_params["worker_run"] = worker_run
399
422
 
400
423
  if self.use_cache:
401
424
  if not recursive:
@@ -427,10 +450,27 @@ class TranscriptionMixin:
427
450
 
428
451
  if worker_version is not None:
429
452
  # If worker_version=False, filter by manual worker_version e.g. None
430
- worker_version_id = worker_version if worker_version else None
431
- transcriptions = transcriptions.where(
432
- CachedTranscription.worker_version_id == worker_version_id
433
- )
453
+ worker_version_id = worker_version or None
454
+ if worker_version_id:
455
+ transcriptions = transcriptions.where(
456
+ CachedTranscription.worker_version_id == worker_version_id
457
+ )
458
+ else:
459
+ transcriptions = transcriptions.where(
460
+ CachedTranscription.worker_version_id.is_null()
461
+ )
462
+
463
+ if worker_run is not None:
464
+ # If worker_run=False, filter by manual worker_run e.g. None
465
+ worker_run_id = worker_run or None
466
+ if worker_run_id:
467
+ transcriptions = transcriptions.where(
468
+ CachedTranscription.worker_run_id == worker_run_id
469
+ )
470
+ else:
471
+ transcriptions = transcriptions.where(
472
+ CachedTranscription.worker_run_id.is_null()
473
+ )
434
474
  else:
435
475
  transcriptions = self.api_client.paginate(
436
476
  "ListTranscriptions", id=element.id, **query_params
@@ -2,10 +2,27 @@
2
2
  ElementsWorker methods for worker versions.
3
3
  """
4
4
 
5
+ import functools
6
+ from warnings import warn
7
+
8
+
9
+ def worker_version_deprecation(func):
10
+ @functools.wraps(func)
11
+ def wrapper(self, *args, **kwargs):
12
+ warn("WorkerVersion usage is deprecated.", DeprecationWarning, stacklevel=2)
13
+ return func(self, *args, **kwargs)
14
+
15
+ return wrapper
16
+
5
17
 
6
18
  class WorkerVersionMixin:
19
+ @worker_version_deprecation
7
20
  def get_worker_version(self, worker_version_id: str) -> dict:
8
21
  """
22
+ Warns:
23
+ ----
24
+ This method is **deprecated**.
25
+
9
26
  Retrieve a worker version, using the [ElementsWorker][arkindex_worker.worker.ElementsWorker]'s internal cache when possible.
10
27
 
11
28
  :param worker_version_id: ID of the worker version to retrieve.
@@ -22,8 +39,13 @@ class WorkerVersionMixin:
22
39
 
23
40
  return worker_version
24
41
 
42
+ @worker_version_deprecation
25
43
  def get_worker_version_slug(self, worker_version_id: str) -> str:
26
44
  """
45
+ Warns:
46
+ ----
47
+ This method is **deprecated**.
48
+
27
49
  Retrieve the slug of the worker of a worker version, from a worker version UUID.
28
50
  Uses a worker version from the internal cache if possible, otherwise makes an API request.
29
51
 
@@ -0,0 +1,3 @@
1
+ # Normalize the slug to generate __package and __module private variables
2
+ {{cookiecutter.update({"__package": cookiecutter.slug.lower().replace("_", "-")})}} # noqa: F821
3
+ {{cookiecutter.update({"__module": cookiecutter.slug.lower().replace("-", "_")})}} # noqa: F821