persidict 0.17.4__py3-none-any.whl → 0.19.0__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.

Potentially problematic release.


This version of persidict might be problematic. Click here for more details.

@@ -12,6 +12,7 @@ from __future__ import annotations
12
12
  import os
13
13
  import random
14
14
  import time
15
+ from abc import abstractmethod
15
16
  from typing import Any, Optional
16
17
 
17
18
  import joblib
@@ -44,7 +45,7 @@ class FileDirDict(PersiDict):
44
45
  text files (either in jason format or as a plain text).
45
46
  """
46
47
 
47
- base_dir:str
48
+ _base_dir:str
48
49
  file_type:str
49
50
 
50
51
  def __init__(self
@@ -55,7 +56,7 @@ class FileDirDict(PersiDict):
55
56
  , base_class_for_values: Optional[type] = None):
56
57
  """A constructor defines location of the store and file format to use.
57
58
 
58
- base_dir is a directory that will contain all the files in
59
+ _base_dir is a directory that will contain all the files in
59
60
  the FileDirDict. If the directory does not exist, it will be created.
60
61
 
61
62
  base_class_for_values constraints the type of values that can be
@@ -97,35 +98,49 @@ class FileDirDict(PersiDict):
97
98
  os.mkdir(base_dir)
98
99
  assert os.path.isdir(base_dir)
99
100
 
100
- self.base_dir_param = base_dir
101
- self.base_dir = os.path.abspath(base_dir)
101
+ # self.base_dir_param = _base_dir
102
+ self._base_dir = os.path.abspath(base_dir)
103
+
102
104
 
103
105
  def __repr__(self):
104
106
  """Return repr(self)."""
105
107
 
106
108
  repr_str = super().__repr__()
107
- repr_str = repr_str[:-1] + f", base_dir={self.base_dir}"
109
+ repr_str = repr_str[:-1] + f", _base_dir={self._base_dir}"
108
110
  repr_str += f", file_type={self.file_type}"
109
111
  repr_str += " )"
110
112
 
111
113
  return repr_str
112
114
 
115
+
113
116
  def get_params(self):
114
117
  """Return configuration parameters of the dictionary."""
115
118
  params = super().get_params()
116
119
  additional_params = dict(
117
- base_dir=self.base_dir_param
120
+ base_dir=self.base_dir
118
121
  , file_type=self.file_type)
119
122
  params.update(additional_params)
120
123
  return params
121
124
 
122
125
 
126
+ @property
127
+ def base_url(self) -> str:
128
+ """Return dictionary's URL"""
129
+ return f"file://{self._base_dir}"
130
+
131
+
132
+ @property
133
+ def base_dir(self) -> str:
134
+ """Return dictionary's base directory"""
135
+ return self._base_dir
136
+
137
+
123
138
  def __len__(self) -> int:
124
- """ Get number of key-value pairs in the dictionary."""
139
+ """ Get the number of key-value pairs in the dictionary."""
125
140
 
126
141
  num_files = 0
127
142
  suffix = "." + self.file_type
128
- for subdir_info in os.walk(self.base_dir):
143
+ for subdir_info in os.walk(self._base_dir):
129
144
  files = subdir_info[2]
130
145
  files = [f_name for f_name in files
131
146
  if f_name.endswith(suffix)]
@@ -139,13 +154,13 @@ class FileDirDict(PersiDict):
139
154
  if self.immutable_items:
140
155
  raise KeyError("Can't clear a dict that contains immutable items")
141
156
 
142
- for subdir_info in os.walk(self.base_dir, topdown=False):
157
+ for subdir_info in os.walk(self._base_dir, topdown=False):
143
158
  (subdir_name, _, files) = subdir_info
144
159
  suffix = "." + self.file_type
145
160
  for f in files:
146
161
  if f.endswith(suffix):
147
162
  os.remove(os.path.join(subdir_name, f))
148
- if (subdir_name != self.base_dir) and (
163
+ if (subdir_name != self._base_dir) and (
149
164
  len(os.listdir(subdir_name)) == 0 ):
150
165
  os.rmdir(subdir_name)
151
166
 
@@ -156,7 +171,7 @@ class FileDirDict(PersiDict):
156
171
  """Convert a key into a filesystem path."""
157
172
 
158
173
  key = sign_safe_str_tuple(key, self.digest_len)
159
- key = [self.base_dir] + list(key.strings)
174
+ key = [self._base_dir] + list(key.strings)
160
175
  dir_names = key[:-1] if is_file_path else key
161
176
 
162
177
  if create_subdirs:
@@ -312,7 +327,7 @@ class FileDirDict(PersiDict):
312
327
  def _generic_iter(self, iter_type: str):
313
328
  """Underlying implementation for .items()/.keys()/.values() iterators"""
314
329
  assert iter_type in {"keys", "values", "items"}
315
- walk_results = os.walk(self.base_dir)
330
+ walk_results = os.walk(self._base_dir)
316
331
  ext_len = len(self.file_type) + 1
317
332
 
318
333
  def splitter(dir_path: str):
@@ -334,7 +349,7 @@ class FileDirDict(PersiDict):
334
349
  for f in files:
335
350
  if f.endswith(suffix):
336
351
  prefix_key = os.path.relpath(
337
- dir_name, start=self.base_dir)
352
+ dir_name, start=self._base_dir)
338
353
 
339
354
  result_key = (*splitter(prefix_key), f[:-ext_len])
340
355
  result_key = SafeStrTuple(result_key)
persidict/persi_dict.py CHANGED
@@ -93,6 +93,7 @@ class PersiDict(MutableMapping, ParameterizableClass):
93
93
  self.immutable_items = bool(immutable_items)
94
94
  self.base_class_for_values = base_class_for_values
95
95
 
96
+
96
97
  def get_params(self):
97
98
  """Return a dictionary of parameters for the PersiDict object."""
98
99
  params = dict(
@@ -103,6 +104,20 @@ class PersiDict(MutableMapping, ParameterizableClass):
103
104
  return params
104
105
 
105
106
 
107
+ @property
108
+ @abstractmethod
109
+ def base_url(self):
110
+ """Return dictionary's URL"""
111
+ raise NotImplementedError
112
+
113
+
114
+ @property
115
+ @abstractmethod
116
+ def base_dir(self):
117
+ """Return dictionary's base directory in the local filesystem"""
118
+ raise NotImplementedError
119
+
120
+
106
121
  def __repr__(self) -> str:
107
122
  """Return repr(self)"""
108
123
  repr_str = self.__class__.__name__ + "("
persidict/s3_dict.py CHANGED
@@ -1,6 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import os
4
+ from abc import abstractmethod
4
5
  from typing import Any, Optional
5
6
 
6
7
  import boto3
@@ -32,7 +33,7 @@ class S3Dict(PersiDict):
32
33
  bucket_name: str
33
34
  root_prefix: str
34
35
  file_type: str
35
- base_dir: str
36
+ _base_dir: str
36
37
 
37
38
  def __init__(self, bucket_name:str = "my_bucket"
38
39
  , region:str = None
@@ -51,7 +52,7 @@ class S3Dict(PersiDict):
51
52
 
52
53
  root_prefix is a common S3 prefix for all objectnames in a dictionary.
53
54
 
54
- base_dir is a local directory that will be used to store tmp files.
55
+ _base_dir is a local directory that will be used to store tmp files.
55
56
 
56
57
  base_class_for_values constraints the type of values that can be
57
58
  stored in the dictionary. If specified, it will be used to
@@ -98,7 +99,7 @@ class S3Dict(PersiDict):
98
99
  """Return repr(self)."""
99
100
 
100
101
  repr_str = super().__repr__()
101
- repr_str = repr_str[:-1] + f", base_dir={self.local_cache.base_dir}"
102
+ repr_str = repr_str[:-1] + f", _base_dir={self.local_cache._base_dir}"
102
103
  repr_str += f", file_type={self.file_type}"
103
104
  repr_str += f", region={self.region}"
104
105
  repr_str += f", bucket_name={self.bucket_name}"
@@ -107,6 +108,7 @@ class S3Dict(PersiDict):
107
108
 
108
109
  return repr_str
109
110
 
111
+
110
112
  def get_params(self):
111
113
  """Return configuration parameters of the object as a dictionary."""
112
114
  params = self.local_cache.get_params()
@@ -116,6 +118,18 @@ class S3Dict(PersiDict):
116
118
  return params
117
119
 
118
120
 
121
+ @property
122
+ def base_url(self):
123
+ """Return dictionary's URl"""
124
+ return f"s3://{self.bucket_name}/{self.root_prefix}"
125
+
126
+ @property
127
+ def base_dir(self) -> str:
128
+ """Return dictionary's base directory in the local filesystem"""
129
+ return self.local_cache.base_dir
130
+
131
+
132
+
119
133
  def _build_full_objectname(self, key:PersiDictKey) -> str:
120
134
  """ Convert PersiDictKey into an S3 objectname. """
121
135
  key = SafeStrTuple(key)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: persidict
3
- Version: 0.17.4
3
+ Version: 0.19.0
4
4
  Summary: Simple persistent key-value store for Python. Values are stored as files on a disk or as S3 objects on AWS cloud.
5
5
  Keywords: persistence,dicts,distributed,parallel
6
6
  Author: Vlad (Volodymyr) Pavlov
@@ -0,0 +1,11 @@
1
+ persidict/.DS_Store,sha256=d65165279105ca6773180500688df4bdc69a2c7b771752f0a46ef120b7fd8ec3,6148
2
+ persidict/__init__.py,sha256=f589b6292bef0ee7c6f6ef087dacbecc5943a64deed8839b02f8342db3032b25,1155
3
+ persidict/file_dir_dict.py,sha256=441c311572b61be643f6536dfd0c157c03faebe4a01c26fa22d77386cbdd5a5d,14043
4
+ persidict/persi_dict.py,sha256=040fb1ed1358fa36a4d445d9fd3b899087a1030c7e76fb39da7e15c766aec41a,11600
5
+ persidict/s3_dict.py,sha256=fb84d32ff0aa0d873d7d0742a374fab12d9aae272dbcde82ddee7f7af7487eba,11745
6
+ persidict/safe_chars.py,sha256=59a20e96205d2e5675d827a911ad42ddbd553f1bd7e2cda1be765a9c2c4ce814,565
7
+ persidict/safe_str_tuple.py,sha256=71393904bdebfb213ad8429fed59e04da52964076c01324f2238821aa4339325,3717
8
+ persidict/safe_str_tuple_signing.py,sha256=e6e0a3015651a8ea2ef8aa43670f84c5ba1cdfedefb9ac8932aaebb7c699d1c9,3742
9
+ persidict-0.19.0.dist-info/WHEEL,sha256=c133ef911c90b05f7e14d8679ba99146f9154fcd271b7398cf8f672283b94e05,79
10
+ persidict-0.19.0.dist-info/METADATA,sha256=f28075650e95b00558605e23225933e6e1a4fb0ba8e2fb5705c4acc86373edab,9096
11
+ persidict-0.19.0.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: uv 0.7.12
2
+ Generator: uv 0.7.13
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
@@ -1,11 +0,0 @@
1
- persidict/.DS_Store,sha256=d65165279105ca6773180500688df4bdc69a2c7b771752f0a46ef120b7fd8ec3,6148
2
- persidict/__init__.py,sha256=f589b6292bef0ee7c6f6ef087dacbecc5943a64deed8839b02f8342db3032b25,1155
3
- persidict/file_dir_dict.py,sha256=d1f85ace6909dddd95ac90cd8c8113e27e0faec53c70d51906510a8a14f67fd6,13745
4
- persidict/persi_dict.py,sha256=5d1b3a0426b066e917c5032ae56c22b54063739c0b2da56635fb05b662644b6d,11300
5
- persidict/s3_dict.py,sha256=223b465f18b0f08c87490eff698570c781590ff16a7fde525658ba1eb0744379,11409
6
- persidict/safe_chars.py,sha256=59a20e96205d2e5675d827a911ad42ddbd553f1bd7e2cda1be765a9c2c4ce814,565
7
- persidict/safe_str_tuple.py,sha256=71393904bdebfb213ad8429fed59e04da52964076c01324f2238821aa4339325,3717
8
- persidict/safe_str_tuple_signing.py,sha256=e6e0a3015651a8ea2ef8aa43670f84c5ba1cdfedefb9ac8932aaebb7c699d1c9,3742
9
- persidict-0.17.4.dist-info/WHEEL,sha256=b43a490154aa5cdf2e66332f4b8e5b7f1bd1f11398f8ae4d8c5943554e998b5a,79
10
- persidict-0.17.4.dist-info/METADATA,sha256=7cb92ac2a36a71f073934bac6c467b4139d84f973605c5f03a5fa96aece91051,9096
11
- persidict-0.17.4.dist-info/RECORD,,