datashare-python 0.10.10__tar.gz → 0.11.1__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 (29) hide show
  1. {datashare_python-0.10.10 → datashare_python-0.11.1}/PKG-INFO +1 -1
  2. {datashare_python-0.10.10 → datashare_python-0.11.1}/datashare_python/conftest.py +12 -2
  3. {datashare_python-0.10.10 → datashare_python-0.11.1}/datashare_python/objects.py +45 -6
  4. datashare_python-0.11.1/datashare_python/worker-template.tar.gz +0 -0
  5. {datashare_python-0.10.10 → datashare_python-0.11.1}/pyproject.toml +1 -1
  6. datashare_python-0.10.10/datashare_python/worker-template.tar.gz +0 -0
  7. {datashare_python-0.10.10 → datashare_python-0.11.1}/.gitignore +0 -0
  8. {datashare_python-0.10.10 → datashare_python-0.11.1}/README.md +0 -0
  9. {datashare_python-0.10.10 → datashare_python-0.11.1}/datashare_python/.gitignore +0 -0
  10. {datashare_python-0.10.10 → datashare_python-0.11.1}/datashare_python/__init__.py +0 -0
  11. {datashare_python-0.10.10 → datashare_python-0.11.1}/datashare_python/__main__.py +0 -0
  12. {datashare_python-0.10.10 → datashare_python-0.11.1}/datashare_python/cli/__init__.py +0 -0
  13. {datashare_python-0.10.10 → datashare_python-0.11.1}/datashare_python/cli/project.py +0 -0
  14. {datashare_python-0.10.10 → datashare_python-0.11.1}/datashare_python/cli/task.py +0 -0
  15. {datashare_python-0.10.10 → datashare_python-0.11.1}/datashare_python/cli/utils.py +0 -0
  16. {datashare_python-0.10.10 → datashare_python-0.11.1}/datashare_python/cli/worker.py +0 -0
  17. {datashare_python-0.10.10 → datashare_python-0.11.1}/datashare_python/config.py +0 -0
  18. {datashare_python-0.10.10 → datashare_python-0.11.1}/datashare_python/constants.py +0 -0
  19. {datashare_python-0.10.10 → datashare_python-0.11.1}/datashare_python/dependencies.py +0 -0
  20. {datashare_python-0.10.10 → datashare_python-0.11.1}/datashare_python/discovery.py +0 -0
  21. {datashare_python-0.10.10 → datashare_python-0.11.1}/datashare_python/exceptions.py +0 -0
  22. {datashare_python-0.10.10 → datashare_python-0.11.1}/datashare_python/interceptors.py +0 -0
  23. {datashare_python-0.10.10 → datashare_python-0.11.1}/datashare_python/logging_.py +0 -0
  24. {datashare_python-0.10.10 → datashare_python-0.11.1}/datashare_python/mimetypes_.py +0 -0
  25. {datashare_python-0.10.10 → datashare_python-0.11.1}/datashare_python/task_client.py +0 -0
  26. {datashare_python-0.10.10 → datashare_python-0.11.1}/datashare_python/template.py +0 -0
  27. {datashare_python-0.10.10 → datashare_python-0.11.1}/datashare_python/types_.py +0 -0
  28. {datashare_python-0.10.10 → datashare_python-0.11.1}/datashare_python/utils.py +0 -0
  29. {datashare_python-0.10.10 → datashare_python-0.11.1}/datashare_python/worker.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: datashare-python
3
- Version: 0.10.10
3
+ Version: 0.11.1
4
4
  Summary: Manage Python tasks and local resources in Datashare
5
5
  Project-URL: Homepage, https://icij.github.io/datashare-python/
6
6
  Project-URL: Documentation, https://icij.github.io/datashare-python/
@@ -233,14 +233,22 @@ def text_1() -> str:
233
233
  @pytest.fixture(scope="session")
234
234
  def doc_0(text_0: str) -> Document:
235
235
  return Document(
236
- id="doc-0", root_document="root-0", language="ENGLISH", content=text_0
236
+ id="doc-0",
237
+ root_document="root-0",
238
+ extraction_level=1,
239
+ language="ENGLISH",
240
+ content=text_0,
237
241
  )
238
242
 
239
243
 
240
244
  @pytest.fixture(scope="session")
241
245
  def doc_1(text_1: str) -> Document:
242
246
  return Document(
243
- id="doc-1", root_document="root-1", language="ENGLISH", content=text_1
247
+ id="doc-1",
248
+ root_document="root-1",
249
+ extraction_level=1,
250
+ language="ENGLISH",
251
+ content=text_1,
244
252
  )
245
253
 
246
254
 
@@ -249,6 +257,7 @@ def doc_2() -> Document:
249
257
  return Document(
250
258
  id="doc-2",
251
259
  root_document="root-2",
260
+ extraction_level=1,
252
261
  language="FRENCH",
253
262
  content="traduis ce texte en anglais",
254
263
  )
@@ -260,6 +269,7 @@ def doc_3() -> Document:
260
269
  id="doc-3",
261
270
  index=TEST_PROJECT,
262
271
  root_document="root-3",
272
+ extraction_level=1,
263
273
  language="SPANISH",
264
274
  content="traduce este texto al inglés",
265
275
  )
@@ -24,6 +24,7 @@ with workflow.unsafe.imports_passed_through():
24
24
  from icij_common.es import (
25
25
  DOC_CONTENT,
26
26
  DOC_CONTENT_TRANSLATED,
27
+ DOC_EXTRACTION_LEVEL,
27
28
  DOC_LANGUAGE,
28
29
  DOC_METADATA,
29
30
  DOC_PATH,
@@ -222,6 +223,8 @@ class Document(DatashareModel):
222
223
  language: DatashareLanguage
223
224
  index: str | None = None
224
225
  root_document: str | None = None
226
+ content: Annotated[str, BeforeValidator(_from_sentences)]
227
+ extraction_level: int = 0
225
228
  content: str | None = None
226
229
  content_text_length: int | None = None
227
230
  content_type: str | None = None
@@ -244,6 +247,37 @@ class Document(DatashareModel):
244
247
  data["content_text_length"] = len(content)
245
248
  return data
246
249
 
250
+ @model_validator(mode="before")
251
+ @classmethod
252
+ def _set_root_document_to_self_when_not_provided(cls, data: Any) -> Any:
253
+ if isinstance(data, dict):
254
+ root = data.get("root_document")
255
+ if root is None:
256
+ data["root_document"] = data.get("id")
257
+ return data
258
+
259
+ @model_validator(mode="after")
260
+ def _validate_root_document(self) -> Any:
261
+ if self.root_document is None:
262
+ msg = (
263
+ "inconsistent state, root_document cannot be after validation, "
264
+ "there's a bug in this object's implementation."
265
+ " Please report to a developer."
266
+ )
267
+ raise ValueError(msg)
268
+ if self.is_root_document:
269
+ if self.extraction_level > 0:
270
+ msg = "extraction_level should be <= 0 for root documents"
271
+ raise ValueError(msg)
272
+ elif self.extraction_level <= 0:
273
+ msg = "extraction_level should be > 0 for embedded documents"
274
+ raise ValueError(msg)
275
+ return self
276
+
277
+ @property
278
+ def is_root_document(self) -> bool:
279
+ return self.root_document == self.id and self.extraction_level <= 0
280
+
247
281
  @classmethod
248
282
  def from_es(cls, es_doc: dict) -> Self:
249
283
  sources = es_doc[SOURCE]
@@ -255,6 +289,7 @@ class Document(DatashareModel):
255
289
  content_text_length=sources.get("content_text_length"),
256
290
  language=DatashareLanguage(sources[DOC_LANGUAGE]),
257
291
  root_document=sources.get(DOC_ROOT_ID),
292
+ extraction_level=sources.get(DOC_EXTRACTION_LEVEL),
258
293
  tags=sources.get("tags", []),
259
294
  path=sources.get(DOC_PATH),
260
295
  metadata=sources.get(DOC_METADATA),
@@ -269,13 +304,17 @@ class Document(DatashareModel):
269
304
  )
270
305
  resource_name = self.metadata.get(TIKA_METADATA_RESOURCENAME)
271
306
  if resource_name is None:
272
- msg = (
273
- f"doc {self} can't turn ES document into a {ProcessedFile.__name__} "
274
- f"without tika metadata resources name in metadata: {self.metadata}"
275
- )
276
- raise ValueError(msg)
307
+ # Backward compat for project before resourcename was mandatory
308
+ if self.is_root_document:
309
+ resource_name = self.path.name
310
+ else:
311
+ msg = (
312
+ f"doc {self} can't turn ES document into a {ProcessedFile.__name__} "
313
+ f"without tika metadata resources name in metadata: {self.metadata}"
314
+ )
315
+ raise ValueError(msg)
277
316
  resource_name = cast(str, resource_name)
278
- if self.root_document is None:
317
+ if self.is_root_document:
279
318
  path = self.path
280
319
  location = DocumentLocation.FILESYSTEM
281
320
  else:
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "datashare-python"
3
- version = "0.10.10"
3
+ version = "0.11.1"
4
4
  description = "Manage Python tasks and local resources in Datashare"
5
5
  authors = [
6
6
  { name = "Clément Doumouro", email = "cdoumouro@icij.org" },