datashare-python 0.10.6__py3-none-any.whl → 0.10.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.
@@ -1,3 +1,5 @@
1
+ import hashlib
2
+ import json
1
3
  import logging
2
4
  import os
3
5
  from abc import ABC
@@ -63,6 +65,12 @@ Predicate = Callable[[T], bool] | Callable[[T], Awaitable[bool]]
63
65
  class BaseModel(_BaseModel):
64
66
  model_config = merge_configs(icij_config(), no_enum_values_config())
65
67
 
68
+ def __hash__(self) -> int:
69
+ digest = hashlib.md5(
70
+ json.dumps(self.model_dump(mode="json"), sort_keys=True).encode()
71
+ ).digest()
72
+ return int.from_bytes(digest[:8])
73
+
66
74
 
67
75
  class DatashareModel(BaseModel):
68
76
  model_config = merge_configs(BaseModel.model_config, lowercamel_case_config())
datashare_python/utils.py CHANGED
@@ -32,6 +32,7 @@ import temporalio
32
32
  from aiofile import async_open
33
33
  from lru import LRU
34
34
  from pydantic import ValidationError
35
+ from pydantic.alias_generators import to_snake
35
36
  from temporalio import activity, workflow
36
37
  from temporalio.api.common.v1 import Payload
37
38
  from temporalio.client import Client
@@ -62,6 +63,8 @@ from .objects import (
62
63
  )
63
64
  from .types_ import RawAsyncProgressHandler
64
65
 
66
+ _CACHE_DIR = "__cache__"
67
+
65
68
  logger = logging.getLogger(__name__)
66
69
 
67
70
  DependencyLabel = str | None
@@ -533,7 +536,11 @@ activity_contextual_id = contextual_id
533
536
 
534
537
 
535
538
  def _contextual_path(
536
- *, wf_context: bool = True, act_context: bool = True, run_context: bool = False
539
+ *,
540
+ wf_context: bool = True,
541
+ act_context: bool = True,
542
+ run_context: bool = False,
543
+ caching_key: str | None = None,
537
544
  ) -> Path:
538
545
  act_info = activity.info()
539
546
  path = []
@@ -541,14 +548,18 @@ def _contextual_path(
541
548
  raise ValueError("at least one of wf_context and act_context must be True")
542
549
  if wf_context:
543
550
  path = [act_info.workflow_type]
544
- path.append(act_info.workflow_id)
545
- if run_context:
546
- path.append(act_info.workflow_run_id)
551
+ if not caching_key:
552
+ path.append(act_info.workflow_id)
553
+ if run_context:
554
+ path.append(act_info.workflow_run_id)
547
555
  if act_context:
548
556
  path.append(act_info.activity_type)
549
- path.append(act_info.activity_id)
550
- if run_context:
551
- path.append(act_info.activity_run_id)
557
+ if not caching_key:
558
+ path.append(act_info.activity_id)
559
+ if run_context:
560
+ path.append(act_info.activity_run_id)
561
+ if caching_key:
562
+ path += [_CACHE_DIR, caching_key]
552
563
  return Path(*path)
553
564
 
554
565
 
@@ -559,9 +570,13 @@ def activity_workdir(
559
570
  wf_context: bool = True,
560
571
  act_context: bool = True,
561
572
  run_context: bool = False,
573
+ caching_key: str | None = None,
562
574
  ) -> Path:
563
575
  ctx_path = _contextual_path(
564
- wf_context=wf_context, act_context=act_context, run_context=run_context
576
+ wf_context=wf_context,
577
+ act_context=act_context,
578
+ run_context=run_context,
579
+ caching_key=caching_key,
565
580
  )
566
581
  return workdir.joinpath(project, ctx_path)
567
582
 
@@ -808,4 +823,10 @@ def async_enter_cm(
808
823
 
809
824
 
810
825
  def config_cache_key(config: BaseModel) -> str:
811
- return str(hash(config))
826
+ # BaseModel support deterministic hash we can call hash on it
827
+ config_label = (
828
+ to_snake(config.__class__.__name__.replace("Config", ""))
829
+ .lower()
830
+ .replace("_", "-")
831
+ )
832
+ return f"{config_label}-{str(hash(config))}"
Binary file
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: datashare-python
3
- Version: 0.10.6
3
+ Version: 0.10.7
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/
@@ -10,19 +10,19 @@ datashare_python/exceptions.py,sha256=bVHEAXxDPKfxeeMC0hJXEsrJkgsKO2ESAhxWU96GA4
10
10
  datashare_python/interceptors.py,sha256=-XC-y_MvGyHlZQ6jItfMRPAmKwQkQzzncpAGxceKlwM,16485
11
11
  datashare_python/logging_.py,sha256=96KNXhP-JR5ybu9dld4VLtF7v7PfiphOCR1Nio-mmUs,4483
12
12
  datashare_python/mimetypes_.py,sha256=mjQgaqnSFZEcl3LoLDGBaBBjTTzwYfSNZND9Fmkk2zs,49682
13
- datashare_python/objects.py,sha256=93-GeH-lX6vTVlHHhvftXKRd6l5kJggDR-kV3IQz_1Q,16434
13
+ datashare_python/objects.py,sha256=F5x7kdYOiXhdk1k9wqrN2Jpy89Fki9_jx5w1kVIgqsE,16662
14
14
  datashare_python/task_client.py,sha256=oTmP8bvZW0UyhLNMi1AV3XIAx7hrdbxNRss2Mw2azEc,8435
15
15
  datashare_python/template.py,sha256=N1uM8TRXh5tQPV7BC1oJj-Pdm2Gs_SkjaXv50RnNYso,4682
16
16
  datashare_python/types_.py,sha256=cPcCkIk6ecILrKetPnAsrb0njHYuWJU3eZicUXy2lF8,1278
17
- datashare_python/utils.py,sha256=fRQGNG1OR80S2y7VMnh6FLpwQfyFRdJl9EhaXUkfHEY,26772
18
- datashare_python/worker-template.tar.gz,sha256=NjG5Ds1-TW_QwG31yYYROfNurHu2U8fv2A57O85TEnU,280872
17
+ datashare_python/utils.py,sha256=NrQFMGzpp_r59zIS7CJcPbVo73SzZuNThYS-xL_yeoY,27345
18
+ datashare_python/worker-template.tar.gz,sha256=yAD952Qhc0NG5NwWkqZXiwENB-5UeFeE_k2BTgdWdaU,280874
19
19
  datashare_python/worker.py,sha256=ad36_yJOgwtj8KBheWndGkqaP_2aXTPSrYaHrbCXTvg,8389
20
20
  datashare_python/cli/__init__.py,sha256=9BPWtssDgsVfWMsZ1TtZCla0EC_kai4RHttr8oNLYOE,1401
21
21
  datashare_python/cli/project.py,sha256=w32Gy9AOL5B00uDT4in7YUCt2g68FnNbvwg2M3a8G6o,946
22
22
  datashare_python/cli/task.py,sha256=GsyR5o0fN4Pd8tJKAUgivAvCBKT3L4Ay5j_BCW1XBHk,5828
23
23
  datashare_python/cli/utils.py,sha256=p69CQb0zfixuyBkiZprhdMCc_NuYwXyAn6vC9H1UzAw,911
24
24
  datashare_python/cli/worker.py,sha256=x0p3a1_NsZPbmV7-WSVMRyW3_iadYcgyZKbDvWgymQc,5790
25
- datashare_python-0.10.6.dist-info/METADATA,sha256=eO-0j7ZIjMv6q6FBoP9-EQLhj88cn8zwLorTgqhm53Y,1012
26
- datashare_python-0.10.6.dist-info/WHEEL,sha256=zOwg4jB6zX2kU910N-cMawjivD6tO8NEWvE12je1bVk,87
27
- datashare_python-0.10.6.dist-info/entry_points.txt,sha256=ILE7auxabHWiu3GC-AunWnzjhOI_SbZp7D4GqZHlLw4,68
28
- datashare_python-0.10.6.dist-info/RECORD,,
25
+ datashare_python-0.10.7.dist-info/METADATA,sha256=VDBO1jkZX_4Vjp6iQUi_PnhGmuT9yfFw5nMB3q5725k,1012
26
+ datashare_python-0.10.7.dist-info/WHEEL,sha256=zOwg4jB6zX2kU910N-cMawjivD6tO8NEWvE12je1bVk,87
27
+ datashare_python-0.10.7.dist-info/entry_points.txt,sha256=ILE7auxabHWiu3GC-AunWnzjhOI_SbZp7D4GqZHlLw4,68
28
+ datashare_python-0.10.7.dist-info/RECORD,,