Skip to content

Commit

Permalink
Mandatorily wrap _read_chunk in a check_chunk_n decorator (#758)
Browse files Browse the repository at this point in the history
  • Loading branch information
dachengx authored Sep 19, 2023
1 parent 1ca53c6 commit e3692be
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
7 changes: 7 additions & 0 deletions strax/storage/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,13 @@ class StorageBackend:
these have to be hardcoded (or made part of the key).
"""

def __new__(cls, *args, **kwargs):
"""Mandatorily wrap _read_chunk in a check_chunk_n decorator"""
if '_read_chunk' in cls.__dict__:
method = getattr(cls, '_read_chunk')
setattr(cls, '_read_chunk', strax.check_chunk_n(method))
return super(StorageBackend, cls).__new__(cls)

def loader(self,
backend_key,
time_range=None,
Expand Down
1 change: 0 additions & 1 deletion strax/storage/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ def _read_and_format_chunk(self, *args, **kwargs):
chunk.target_size_mb = self.set_chunk_size_mb
return chunk

@strax.check_chunk_n
def _read_chunk(self, dirname, chunk_info, dtype, compressor):
fn = osp.join(dirname, chunk_info['filename'])
return strax.load_file(fn, dtype=dtype, compressor=compressor)
Expand Down
1 change: 0 additions & 1 deletion strax/storage/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ def __init__(self, uri: str, database: str, col_name: str):
self._buff_mb = DEFAULT_MONGO_BACKEND_BUFFER_MB
self._buff_nruns = DEFAULT_MONGO_BACKEND_BUFFER_NRUNS

@strax.check_chunk_n
def _read_chunk(self, backend_key, chunk_info, dtype, compressor):
"""See strax.Backend"""
chunk_i = chunk_info["chunk_i"]
Expand Down
2 changes: 0 additions & 2 deletions strax/storage/zipfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,6 @@ def zip_dir(input_dir, output_zipfile, delete=False):

@export
class ZipFileBackend(strax.StorageBackend):

@strax.check_chunk_n
def _read_chunk(self, zipn_and_dirn, chunk_info, dtype, compressor):
zipn, dirn = zipn_and_dirn
with zipfile.ZipFile(zipn) as zp:
Expand Down

0 comments on commit e3692be

Please sign in to comment.