Skip to content

Commit

Permalink
Merge branch 'main' of github.com:saezlab/cache-manager
Browse files Browse the repository at this point in the history
  • Loading branch information
npalacioescat committed Oct 17, 2024
2 parents 77da628 + 7a55724 commit 72d170d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
5 changes: 3 additions & 2 deletions cache_manager/_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import datetime
import functools as ft
import collections
from collections.abc import Mapping

from pypath_common import _misc
import platformdirs
Expand Down Expand Up @@ -1108,15 +1109,15 @@ def update(
(
0,
self._quotes(group)
if isinstance(vals, dict)
if isinstance(vals, Mapping)
else 'NULL',
k,
v
)
for group, vals in update.get('attrs', {}).items()
for k, v in (
vals
if isinstance(vals, dict) else
if isinstance(vals, Mapping) else
{group: vals}
).items()
if (
Expand Down
13 changes: 13 additions & 0 deletions cache_manager/_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,19 @@ def path(self) -> str:

return os.path.join(d, self.cache_fname)

@property
def size(self) -> int | None:
"""
Size of the file in bytes.
Returns:
Size of the file in bytes.
"""

if os.path.exists(path := self.path):

return os.path.getsize(path)


@property
def rstatus(self) -> int:
Expand Down
15 changes: 15 additions & 0 deletions tests/test_item.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import os

import pytest

def test_size(test_cache):
it = test_cache.create('test-file-size')
path = it.path

assert it.size is None

with open(path, 'w') as fp:
fp.write('something')

assert os.path.exists(path)
assert it.size > 8

0 comments on commit 72d170d

Please sign in to comment.