datashare-python 0.12.9__tar.gz → 0.12.11__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.
- {datashare_python-0.12.9 → datashare_python-0.12.11}/PKG-INFO +1 -1
- {datashare_python-0.12.9 → datashare_python-0.12.11}/datashare_python/conftest.py +1 -0
- {datashare_python-0.12.9 → datashare_python-0.12.11}/datashare_python/exceptions.py +8 -0
- {datashare_python-0.12.9 → datashare_python-0.12.11}/datashare_python/objects.py +4 -2
- {datashare_python-0.12.9 → datashare_python-0.12.11}/datashare_python/utils.py +32 -0
- datashare_python-0.12.11/datashare_python/worker-template.tar.gz +0 -0
- {datashare_python-0.12.9 → datashare_python-0.12.11}/pyproject.toml +1 -1
- datashare_python-0.12.9/datashare_python/worker-template.tar.gz +0 -0
- {datashare_python-0.12.9 → datashare_python-0.12.11}/.gitignore +0 -0
- {datashare_python-0.12.9 → datashare_python-0.12.11}/README.md +0 -0
- {datashare_python-0.12.9 → datashare_python-0.12.11}/datashare_python/.gitignore +0 -0
- {datashare_python-0.12.9 → datashare_python-0.12.11}/datashare_python/__init__.py +0 -0
- {datashare_python-0.12.9 → datashare_python-0.12.11}/datashare_python/__main__.py +0 -0
- {datashare_python-0.12.9 → datashare_python-0.12.11}/datashare_python/cli/__init__.py +0 -0
- {datashare_python-0.12.9 → datashare_python-0.12.11}/datashare_python/cli/project.py +0 -0
- {datashare_python-0.12.9 → datashare_python-0.12.11}/datashare_python/cli/task.py +0 -0
- {datashare_python-0.12.9 → datashare_python-0.12.11}/datashare_python/cli/utils.py +0 -0
- {datashare_python-0.12.9 → datashare_python-0.12.11}/datashare_python/cli/worker.py +0 -0
- {datashare_python-0.12.9 → datashare_python-0.12.11}/datashare_python/config.py +0 -0
- {datashare_python-0.12.9 → datashare_python-0.12.11}/datashare_python/constants.py +0 -0
- {datashare_python-0.12.9 → datashare_python-0.12.11}/datashare_python/dependencies.py +0 -0
- {datashare_python-0.12.9 → datashare_python-0.12.11}/datashare_python/discovery.py +0 -0
- {datashare_python-0.12.9 → datashare_python-0.12.11}/datashare_python/interceptors.py +0 -0
- {datashare_python-0.12.9 → datashare_python-0.12.11}/datashare_python/logging_.py +0 -0
- {datashare_python-0.12.9 → datashare_python-0.12.11}/datashare_python/mimetypes_.py +0 -0
- {datashare_python-0.12.9 → datashare_python-0.12.11}/datashare_python/task_client.py +0 -0
- {datashare_python-0.12.9 → datashare_python-0.12.11}/datashare_python/template.py +0 -0
- {datashare_python-0.12.9 → datashare_python-0.12.11}/datashare_python/types_.py +0 -0
- {datashare_python-0.12.9 → datashare_python-0.12.11}/datashare_python/worker.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: datashare-python
|
|
3
|
-
Version: 0.12.
|
|
3
|
+
Version: 0.12.11
|
|
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/
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
from abc import ABC
|
|
2
2
|
|
|
3
|
+
from .objects import DocArtifact
|
|
4
|
+
|
|
3
5
|
|
|
4
6
|
class DatashareError(Exception, ABC): ...
|
|
5
7
|
|
|
@@ -16,3 +18,9 @@ class DependencyInjectionError(DatashareError, RuntimeError):
|
|
|
16
18
|
def __init__(self, name: str):
|
|
17
19
|
msg = f"{name} was not injected"
|
|
18
20
|
super().__init__(msg)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class ArtifactNotFound(DatashareError):
|
|
24
|
+
def __init__(self, doc_id: str, artifact_type: type[DocArtifact]):
|
|
25
|
+
msg = f"could not find {artifact_type.__name__} for {doc_id}"
|
|
26
|
+
super().__init__(msg)
|
|
@@ -858,10 +858,12 @@ class WorkerFile(
|
|
|
858
858
|
)
|
|
859
859
|
|
|
860
860
|
|
|
861
|
-
def _file_discriminator(v: Any) -> str:
|
|
861
|
+
def _file_discriminator(v: Any) -> str | None:
|
|
862
862
|
parent = v.get("parent") if isinstance(v, dict) else getattr(v, "parent", None)
|
|
863
863
|
if parent is None:
|
|
864
|
-
|
|
864
|
+
# No match the parent is neither a DatashareFile of WorkerFile it could be a
|
|
865
|
+
# Document or we're just deserializing something else
|
|
866
|
+
return None
|
|
865
867
|
if isinstance(parent, dict):
|
|
866
868
|
is_document = parent.get("type") == "Document"
|
|
867
869
|
else:
|
|
@@ -54,6 +54,7 @@ from datashare_python.types_ import (
|
|
|
54
54
|
)
|
|
55
55
|
|
|
56
56
|
from .constants import MANIFEST_JSON, METADATA_JSON
|
|
57
|
+
from .exceptions import ArtifactNotFound
|
|
57
58
|
from .mimetypes_ import types_map
|
|
58
59
|
from .objects import (
|
|
59
60
|
BaseModel,
|
|
@@ -401,6 +402,37 @@ def artifacts_dir(doc_id: str, *, project: str) -> Path:
|
|
|
401
402
|
return Path(project, safe_dir(doc_id), doc_id)
|
|
402
403
|
|
|
403
404
|
|
|
405
|
+
async def async_read_artifact(
|
|
406
|
+
paths: WorkerPaths, doc_id: str, artifact_type: type[DocArtifact], *, project: str
|
|
407
|
+
) -> bytes:
|
|
408
|
+
# Reading the manifest can be long, we load it only if the artifact exists then
|
|
409
|
+
# we check that the entry is in the manifest
|
|
410
|
+
artifact_path = (
|
|
411
|
+
paths.artifacts
|
|
412
|
+
/ artifacts_dir(doc_id, project=project)
|
|
413
|
+
/ artifact_type.filename
|
|
414
|
+
)
|
|
415
|
+
if not artifact_path.exists():
|
|
416
|
+
raise ArtifactNotFound(doc_id, artifact_type)
|
|
417
|
+
m_path = paths.artifacts / _manifest_path(doc_id, project=project)
|
|
418
|
+
|
|
419
|
+
try:
|
|
420
|
+
async with async_open(m_path, "r") as f:
|
|
421
|
+
manifest_json = await f.read()
|
|
422
|
+
except OSError as e:
|
|
423
|
+
raise ArtifactNotFound(doc_id, artifact_type) from e
|
|
424
|
+
|
|
425
|
+
manifest = json.loads(manifest_json)
|
|
426
|
+
if artifact_type.type.value not in manifest:
|
|
427
|
+
raise ArtifactNotFound(doc_id, artifact_type)
|
|
428
|
+
|
|
429
|
+
try:
|
|
430
|
+
async with async_open(artifact_path, "rb") as f:
|
|
431
|
+
return await f.read()
|
|
432
|
+
except OSError as e:
|
|
433
|
+
raise ArtifactNotFound(doc_id, artifact_type) from e
|
|
434
|
+
|
|
435
|
+
|
|
404
436
|
def _metadata_path(doc_id: str, *, project: str) -> Path:
|
|
405
437
|
metadata_path = artifacts_dir(doc_id, project=project) / METADATA_JSON
|
|
406
438
|
return metadata_path
|
|
Binary file
|
|
Binary file
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|