arkindex-base-worker 0.5.1rc3__py3-none-any.whl → 0.5.2a1__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.
@@ -1,31 +1,9 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: arkindex-base-worker
3
- Version: 0.5.1rc3
3
+ Version: 0.5.2a1
4
4
  Summary: Base Worker to easily build Arkindex ML workflows
5
5
  Author-email: Teklia <contact@teklia.com>
6
6
  Maintainer-email: Teklia <contact@teklia.com>
7
- License: MIT License
8
-
9
- Copyright (c) 2023 Teklia
10
-
11
- Permission is hereby granted, free of charge, to any person obtaining a copy
12
- of this software and associated documentation files (the "Software"), to deal
13
- in the Software without restriction, including without limitation the rights
14
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
- copies of the Software, and to permit persons to whom the Software is
16
- furnished to do so, subject to the following conditions:
17
-
18
- The above copyright notice and this permission notice shall be included in all
19
- copies or substantial portions of the Software.
20
-
21
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
- SOFTWARE.
28
-
29
7
  Project-URL: Homepage, https://workers.arkindex.org
30
8
  Project-URL: Documentation, https://workers.arkindex.org
31
9
  Project-URL: Repository, https://gitlab.teklia.com/workers/base-worker
@@ -41,12 +19,12 @@ Classifier: Programming Language :: Python :: 3.12
41
19
  Requires-Python: >=3.10
42
20
  Description-Content-Type: text/markdown
43
21
  License-File: LICENSE
44
- Requires-Dist: humanize==4.14.0
22
+ Requires-Dist: humanize==4.15.0
45
23
  Requires-Dist: peewee~=3.17
46
24
  Requires-Dist: Pillow==11.3.0
47
- Requires-Dist: python-gnupg==0.5.5
25
+ Requires-Dist: python-gnupg==0.5.6
48
26
  Requires-Dist: shapely==2.0.6
49
- Requires-Dist: teklia-toolbox==0.1.11
27
+ Requires-Dist: teklia-toolbox==0.1.12
50
28
  Requires-Dist: zstandard==0.25.0
51
29
  Provides-Extra: tests
52
30
  Requires-Dist: pytest-mock==3.15.1; extra == "tests"
@@ -1,9 +1,9 @@
1
- arkindex_base_worker-0.5.1rc3.dist-info/licenses/LICENSE,sha256=NVshRi1efwVezMfW7xXYLrdDr2Li1AfwfGOd5WuH1kQ,1063
1
+ arkindex_base_worker-0.5.2a1.dist-info/licenses/LICENSE,sha256=NVshRi1efwVezMfW7xXYLrdDr2Li1AfwfGOd5WuH1kQ,1063
2
2
  arkindex_worker/__init__.py,sha256=Sdt5KXn8EgURb2MurYVrUWaHbH3iFA1XLRo0Lc5AJ44,250
3
3
  arkindex_worker/cache.py,sha256=XpEXMSnbhYCvrJquwA9XXqZo-ajMLpaCxKG5wH3Gp6Y,10959
4
4
  arkindex_worker/image.py,sha256=sGE8to5iykXv25bpkftOEWzlh5NzBZSKy4lSRoHYHPU,20929
5
- arkindex_worker/models.py,sha256=7GnKqpWPOSxyR_eKlDNVBe_r3TcE4ofK-1GzaonJEdM,10132
6
- arkindex_worker/utils.py,sha256=yq_LmRlqfWOzB09Aiz2XYx4xPZnoEXR3As48h2HxOVc,10974
5
+ arkindex_worker/models.py,sha256=DgKvAB_2e1cPcuUavZkyTkV10jBK8y083oVklB9idSk,10855
6
+ arkindex_worker/utils.py,sha256=Eqg5pGAuOmuwMT3EhKTQDMek7wHC1KzZL7XXqYVVfHY,10977
7
7
  arkindex_worker/worker/__init__.py,sha256=SzD0s1_m6gMV02EUF-NeciqZdVPA4dpXI84tSj-g494,17869
8
8
  arkindex_worker/worker/base.py,sha256=-R_aLMJHbR6X1uM-U0zExsF_KLy5Wl3WJ_YMGO9We0I,22153
9
9
  arkindex_worker/worker/classification.py,sha256=qvykymkgd4nGywHCxL8obo4egstoGsmWNS4Ztc1qNWQ,11024
@@ -55,7 +55,7 @@ worker-demo/tests/conftest.py,sha256=XzNMNeg6pmABUAH8jN6eZTlZSFGLYjS3-DTXjiRN6Yc
55
55
  worker-demo/tests/test_worker.py,sha256=3DLd4NRK4bfyatG5P_PK4k9P9tJHx9XQq5_ryFEEFVg,304
56
56
  worker-demo/worker_demo/__init__.py,sha256=2BPomV8ZMNf3YXJgloatKeHQCE6QOkwmsHGkO6MkQuM,125
57
57
  worker-demo/worker_demo/worker.py,sha256=Rt-DjWa5iBP08k58NDZMfeyPuFbtNcbX6nc5jFX7GNo,440
58
- arkindex_base_worker-0.5.1rc3.dist-info/METADATA,sha256=EhM_vIe59B-G10-l3mQUdEWXDIe4HmoSp8vbstcJ2Cs,3091
59
- arkindex_base_worker-0.5.1rc3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
60
- arkindex_base_worker-0.5.1rc3.dist-info/top_level.txt,sha256=-vNjP2VfROx0j83mdi9aIqRZ88eoJjxeWz-R_gPgyXU,49
61
- arkindex_base_worker-0.5.1rc3.dist-info/RECORD,,
58
+ arkindex_base_worker-0.5.2a1.dist-info/METADATA,sha256=AwYp_xJZzu6zAtvnvZjeK_W29tzqvRuwYnxwMYcKSIc,1849
59
+ arkindex_base_worker-0.5.2a1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
60
+ arkindex_base_worker-0.5.2a1.dist-info/top_level.txt,sha256=-vNjP2VfROx0j83mdi9aIqRZ88eoJjxeWz-R_gPgyXU,49
61
+ arkindex_base_worker-0.5.2a1.dist-info/RECORD,,
arkindex_worker/models.py CHANGED
@@ -9,6 +9,8 @@ from contextlib import contextmanager
9
9
  from PIL import Image
10
10
  from requests import HTTPError
11
11
 
12
+ IMAGE_EXTENSION = "jpg"
13
+
12
14
 
13
15
  class MagicDict(dict):
14
16
  """
@@ -62,28 +64,38 @@ class Element(MagicDict):
62
64
  Describes an Arkindex element.
63
65
  """
64
66
 
65
- def resize_zone_url(self, size: str = "full") -> str:
67
+ def resize_zone_url(
68
+ self, size: str = "full", extension: str = IMAGE_EXTENSION
69
+ ) -> str:
66
70
  """
67
71
  Compute the URL of the image corresponding to the size
68
72
  :param size: Requested size
73
+ :param extension: IIIF extension to download the image
69
74
  :return: The URL corresponding to the size
70
75
  """
76
+ # Removing the `jpg` default extension at the end of the URL to use the provided one
77
+ url = self.zone.url[:-3] + extension
78
+
71
79
  if size == "full":
72
- return self.zone.url
80
+ return url
73
81
  else:
74
- parts = self.zone.url.split("/")
82
+ parts = url.split("/")
75
83
  parts[-3] = size
76
84
  return "/".join(parts)
77
85
 
78
- def image_url(self, size: str = "full") -> str | None:
86
+ def image_url(
87
+ self, size: str = "full", extension: str = IMAGE_EXTENSION
88
+ ) -> str | None:
79
89
  """
80
90
  Build a URL to access the image.
81
91
  When possible, will return the S3 URL for images, so an ML worker can bypass IIIF servers.
82
92
  :param size: Subresolution of the image, following the syntax of the IIIF resize parameter.
93
+ :param extension: IIIF extension to download the image.
83
94
  :returns: A URL to the image, or None if the element does not have an image.
84
95
  """
85
96
  if not self.get("zone"):
86
97
  return
98
+
87
99
  url = self.zone.image.get("s3_url")
88
100
  if url:
89
101
  return url
@@ -95,7 +107,7 @@ class Element(MagicDict):
95
107
  url = self.zone.image.url
96
108
  if not url.endswith("/"):
97
109
  url += "/"
98
- return f"{url}full/{size}/0/default.jpg"
110
+ return f"{url}full/{size}/0/default.{extension}"
99
111
 
100
112
  @property
101
113
  def polygon(self) -> list[float]:
@@ -131,6 +143,7 @@ class Element(MagicDict):
131
143
  max_width: int | None = None,
132
144
  max_height: int | None = None,
133
145
  use_full_image: bool | None = False,
146
+ extension: str | None = IMAGE_EXTENSION,
134
147
  **kwargs,
135
148
  ) -> Image.Image:
136
149
  """
@@ -163,6 +176,7 @@ class Element(MagicDict):
163
176
  :param max_height: The maximum height of the image.
164
177
  :param use_full_image: Ignore the ``zone.polygon`` and always
165
178
  retrieve the image without cropping.
179
+ :param extension: The extension to download the image.
166
180
  :param *args: Positional arguments passed to [arkindex_worker.image.open_image][].
167
181
  :param **kwargs: Keyword arguments passed to [arkindex_worker.image.open_image][].
168
182
  :raises ValueError: When the element does not have an image.
@@ -200,7 +214,11 @@ class Element(MagicDict):
200
214
  else:
201
215
  resize = f"{max_width or ''},{max_height or ''}"
202
216
 
203
- url = self.image_url(resize) if use_full_image else self.resize_zone_url(resize)
217
+ url = (
218
+ self.image_url(resize, extension)
219
+ if use_full_image
220
+ else self.resize_zone_url(resize, extension)
221
+ )
204
222
 
205
223
  try:
206
224
  return open_image(
@@ -224,7 +242,7 @@ class Element(MagicDict):
224
242
 
225
243
  @contextmanager
226
244
  def open_image_tempfile(
227
- self, format: str | None = "jpeg", *args, **kwargs
245
+ self, extension: str | None = IMAGE_EXTENSION, *args, **kwargs
228
246
  ) -> Generator[tempfile.NamedTemporaryFile, None, None]:
229
247
  """
230
248
  Get the element's image as a temporary file stored on the disk.
@@ -243,8 +261,12 @@ class Element(MagicDict):
243
261
  :param **kwargs: Keyword arguments passed to [arkindex_worker.image.open_image][].
244
262
 
245
263
  """
246
- with tempfile.NamedTemporaryFile() as f:
247
- self.open_image(*args, **kwargs).save(f, format=format)
264
+ PIL_format = "jpeg" if extension == IMAGE_EXTENSION else extension
265
+
266
+ with tempfile.NamedTemporaryFile(suffix=f".{extension}") as f:
267
+ self.open_image(*args, extension=extension, **kwargs).save(
268
+ f, format=PIL_format
269
+ )
248
270
  yield f
249
271
 
250
272
  def __str__(self):
arkindex_worker/utils.py CHANGED
@@ -243,7 +243,7 @@ def create_zip_archive(source: Path, destination: Path | None = None) -> Path:
243
243
  logger.debug(f"Compressing file to {destination}")
244
244
 
245
245
  with zipfile.ZipFile(
246
- destination, mode="w", compression=zipfile.ZIP_BZIP2
246
+ destination, mode="w", compression=zipfile.ZIP_DEFLATED
247
247
  ) as archive:
248
248
  for p in source.rglob("*"):
249
249
  relpath = p.relative_to(source)