persidict 0.18.0__tar.gz → 0.19.0__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.

Potentially problematic release.


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

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: persidict
3
- Version: 0.18.0
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
@@ -4,7 +4,7 @@ build-backend = "uv_build"
4
4
 
5
5
  [project]
6
6
  name = "persidict"
7
- version = "0.18.0"
7
+ version = "0.19.0"
8
8
  description = "Simple persistent key-value store for Python. Values are stored as files on a disk or as S3 objects on AWS cloud."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -45,7 +45,7 @@ class FileDirDict(PersiDict):
45
45
  text files (either in jason format or as a plain text).
46
46
  """
47
47
 
48
- base_dir:str
48
+ _base_dir:str
49
49
  file_type:str
50
50
 
51
51
  def __init__(self
@@ -56,7 +56,7 @@ class FileDirDict(PersiDict):
56
56
  , base_class_for_values: Optional[type] = None):
57
57
  """A constructor defines location of the store and file format to use.
58
58
 
59
- 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
60
60
  the FileDirDict. If the directory does not exist, it will be created.
61
61
 
62
62
  base_class_for_values constraints the type of values that can be
@@ -98,14 +98,15 @@ class FileDirDict(PersiDict):
98
98
  os.mkdir(base_dir)
99
99
  assert os.path.isdir(base_dir)
100
100
 
101
- self.base_dir_param = base_dir
102
- 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
+
103
104
 
104
105
  def __repr__(self):
105
106
  """Return repr(self)."""
106
107
 
107
108
  repr_str = super().__repr__()
108
- repr_str = repr_str[:-1] + f", base_dir={self.base_dir}"
109
+ repr_str = repr_str[:-1] + f", _base_dir={self._base_dir}"
109
110
  repr_str += f", file_type={self.file_type}"
110
111
  repr_str += " )"
111
112
 
@@ -116,15 +117,22 @@ class FileDirDict(PersiDict):
116
117
  """Return configuration parameters of the dictionary."""
117
118
  params = super().get_params()
118
119
  additional_params = dict(
119
- base_dir=self.base_dir_param
120
+ base_dir=self.base_dir
120
121
  , file_type=self.file_type)
121
122
  params.update(additional_params)
122
123
  return params
123
124
 
125
+
124
126
  @property
125
127
  def base_url(self) -> str:
126
128
  """Return dictionary's URL"""
127
- return f"file://{self.base_dir}"
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
128
136
 
129
137
 
130
138
  def __len__(self) -> int:
@@ -132,7 +140,7 @@ class FileDirDict(PersiDict):
132
140
 
133
141
  num_files = 0
134
142
  suffix = "." + self.file_type
135
- for subdir_info in os.walk(self.base_dir):
143
+ for subdir_info in os.walk(self._base_dir):
136
144
  files = subdir_info[2]
137
145
  files = [f_name for f_name in files
138
146
  if f_name.endswith(suffix)]
@@ -146,13 +154,13 @@ class FileDirDict(PersiDict):
146
154
  if self.immutable_items:
147
155
  raise KeyError("Can't clear a dict that contains immutable items")
148
156
 
149
- for subdir_info in os.walk(self.base_dir, topdown=False):
157
+ for subdir_info in os.walk(self._base_dir, topdown=False):
150
158
  (subdir_name, _, files) = subdir_info
151
159
  suffix = "." + self.file_type
152
160
  for f in files:
153
161
  if f.endswith(suffix):
154
162
  os.remove(os.path.join(subdir_name, f))
155
- if (subdir_name != self.base_dir) and (
163
+ if (subdir_name != self._base_dir) and (
156
164
  len(os.listdir(subdir_name)) == 0 ):
157
165
  os.rmdir(subdir_name)
158
166
 
@@ -163,7 +171,7 @@ class FileDirDict(PersiDict):
163
171
  """Convert a key into a filesystem path."""
164
172
 
165
173
  key = sign_safe_str_tuple(key, self.digest_len)
166
- key = [self.base_dir] + list(key.strings)
174
+ key = [self._base_dir] + list(key.strings)
167
175
  dir_names = key[:-1] if is_file_path else key
168
176
 
169
177
  if create_subdirs:
@@ -319,7 +327,7 @@ class FileDirDict(PersiDict):
319
327
  def _generic_iter(self, iter_type: str):
320
328
  """Underlying implementation for .items()/.keys()/.values() iterators"""
321
329
  assert iter_type in {"keys", "values", "items"}
322
- walk_results = os.walk(self.base_dir)
330
+ walk_results = os.walk(self._base_dir)
323
331
  ext_len = len(self.file_type) + 1
324
332
 
325
333
  def splitter(dir_path: str):
@@ -341,7 +349,7 @@ class FileDirDict(PersiDict):
341
349
  for f in files:
342
350
  if f.endswith(suffix):
343
351
  prefix_key = os.path.relpath(
344
- dir_name, start=self.base_dir)
352
+ dir_name, start=self._base_dir)
345
353
 
346
354
  result_key = (*splitter(prefix_key), f[:-ext_len])
347
355
  result_key = SafeStrTuple(result_key)
@@ -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(
@@ -102,6 +103,7 @@ class PersiDict(MutableMapping, ParameterizableClass):
102
103
  )
103
104
  return params
104
105
 
106
+
105
107
  @property
106
108
  @abstractmethod
107
109
  def base_url(self):
@@ -109,6 +111,13 @@ class PersiDict(MutableMapping, ParameterizableClass):
109
111
  raise NotImplementedError
110
112
 
111
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
+
112
121
  def __repr__(self) -> str:
113
122
  """Return repr(self)"""
114
123
  repr_str = self.__class__.__name__ + "("
@@ -33,7 +33,7 @@ class S3Dict(PersiDict):
33
33
  bucket_name: str
34
34
  root_prefix: str
35
35
  file_type: str
36
- base_dir: str
36
+ _base_dir: str
37
37
 
38
38
  def __init__(self, bucket_name:str = "my_bucket"
39
39
  , region:str = None
@@ -52,7 +52,7 @@ class S3Dict(PersiDict):
52
52
 
53
53
  root_prefix is a common S3 prefix for all objectnames in a dictionary.
54
54
 
55
- 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.
56
56
 
57
57
  base_class_for_values constraints the type of values that can be
58
58
  stored in the dictionary. If specified, it will be used to
@@ -99,7 +99,7 @@ class S3Dict(PersiDict):
99
99
  """Return repr(self)."""
100
100
 
101
101
  repr_str = super().__repr__()
102
- 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}"
103
103
  repr_str += f", file_type={self.file_type}"
104
104
  repr_str += f", region={self.region}"
105
105
  repr_str += f", bucket_name={self.bucket_name}"
@@ -123,6 +123,11 @@ class S3Dict(PersiDict):
123
123
  """Return dictionary's URl"""
124
124
  return f"s3://{self.bucket_name}/{self.root_prefix}"
125
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
+
126
131
 
127
132
 
128
133
  def _build_full_objectname(self, key:PersiDictKey) -> str:
File without changes