Skip to content

Commit e06dc1c

Browse files
redjaxredjax
and
redjax
authored
Feat/fn rename (#184)
* chore(pyproject): Update pyproject, pdm lock. (#148) Co-authored-by: redjax <[email protected]> * Feat/pre commit (#149) * chore(pyproject): Update pyproject, pdm lock. (#147) Co-authored-by: redjax <[email protected]> * feat(pre-commit): Add pre-commit config Add hooks for cleaning up code with ruff, black, & file checkers. File checkers include encoding checks, syntax of TOML & YAML files, & mixed line endings. --------- Co-authored-by: redjax <[email protected]> * Fix/git clean (#154) * chore(pyproject): Update pyproject, pdm lock. (#145) Co-authored-by: redjax <[email protected]> * Topic/utils (#151) * chore(pyproject): Update pyproject, pdm lock. (#148) Co-authored-by: redjax <[email protected]> * Feat/pre commit (#149) * chore(pyproject): Update pyproject, pdm lock. (#147) Co-authored-by: redjax <[email protected]> * feat(pre-commit): Add pre-commit config Add hooks for cleaning up code with ruff, black, & file checkers. File checkers include encoding checks, syntax of TOML & YAML files, & mixed line endings. --------- Co-authored-by: redjax <[email protected]> --------- Co-authored-by: redjax <[email protected]> * feat(safeguard): Add prompt to verify user wishes to remove all local files not found on remote. --------- Co-authored-by: redjax <[email protected]> * fix(pre-commit): Rename pre-commit-config file (#157) Co-authored-by: redjax <[email protected]> * fix(pre-commit): Rename pre-commit-config file (#159) Co-authored-by: redjax <[email protected]> * Fix/pre commit (#160) * chore(pyproject): Update pyproject, pdm lock. (#145) Co-authored-by: redjax <[email protected]> * Topic/utils (#151) * chore(pyproject): Update pyproject, pdm lock. (#148) Co-authored-by: redjax <[email protected]> * Feat/pre commit (#149) * chore(pyproject): Update pyproject, pdm lock. (#147) Co-authored-by: redjax <[email protected]> * feat(pre-commit): Add pre-commit config Add hooks for cleaning up code with ruff, black, & file checkers. File checkers include encoding checks, syntax of TOML & YAML files, & mixed line endings. --------- Co-authored-by: redjax <[email protected]> --------- Co-authored-by: redjax <[email protected]> * feat(safeguard): Add prompt to verify user wishes to remove all local files not found on remote. (#152) Co-authored-by: redjax <[email protected]> * fix(pre-commit): Rename pre-commit-config file --------- Co-authored-by: redjax <[email protected]> * Update pyproject: Remove extra dev dependencies. Update lock file. * Repo/pyproject (#163) * fix(pre-commit): Rename pre-commit-config file (#159) Co-authored-by: redjax <[email protected]> * Update pyproject: Remove extra dev dependencies. Update lock file. --------- Co-authored-by: redjax <[email protected]> * fix(pre-commit): Run pre-commit autoupdate * Fix/pre commit (#174) * fix(pre-commit): Run pre-commit autoupdate (#166) Co-authored-by: redjax <[email protected]> * fix(pre-commit): Fix black hook Remove --exit-non-zero-on-fix --------- Co-authored-by: redjax <[email protected]> * Fix/module imports (#181) * fix(pre-commit): Rename pre-commit-config file (#158) Co-authored-by: redjax <[email protected]> * Repo/pyproject (#164) * fix(pre-commit): Rename pre-commit-config file (#159) Co-authored-by: redjax <[email protected]> * Update pyproject: Remove extra dev dependencies. Update lock file. --------- Co-authored-by: redjax <[email protected]> * Fix/pre commit (#175) * fix(pre-commit): Run pre-commit autoupdate (#166) Co-authored-by: redjax <[email protected]> * fix(pre-commit): Fix black hook Remove --exit-non-zero-on-fix --------- Co-authored-by: redjax <[email protected]> * fix(imports): Use pkgutil.find_loader() for imports. Only import modules when a package is installed. --------- Co-authored-by: redjax <[email protected]> * chore(rename): Rename diskcache_utils functions --------- Co-authored-by: redjax <[email protected]>
1 parent 81934e4 commit e06dc1c

File tree

3 files changed

+12
-35
lines changed

3 files changed

+12
-35
lines changed

red_utils/diskcache_utils/__init__.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33
from typing import Any
44

55
from .src import (
6-
cache_tag_index,
76
check_cache,
8-
check_exists,
7+
check_cache_key_exists,
98
clear_cache,
109
convert_to_seconds,
1110
default_cache_conf,
1211
default_cache_dir,
1312
default_timeout_dict,
1413
delete_val,
15-
get_cache,
1614
get_cache_size,
1715
get_val,
16+
manage_cache_tag_index,
17+
new_cache,
1818
set_expire,
1919
set_val,
2020
valid_key_types,

red_utils/diskcache_utils/src/__init__.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010
valid_val_types,
1111
)
1212
from .operations import (
13-
cache_tag_index,
1413
check_cache,
15-
check_exists,
14+
check_cache_key_exists,
1615
clear_cache,
1716
convert_to_seconds,
1817
delete_val,
19-
get_cache,
2018
get_cache_size,
2119
get_val,
20+
manage_cache_tag_index,
21+
new_cache,
2222
set_expire,
2323
set_val,
2424
)

red_utils/diskcache_utils/src/operations.py

+6-29
Original file line numberDiff line numberDiff line change
@@ -69,30 +69,7 @@ def convert_to_seconds(unit: str = None, amount: int = None) -> int:
6969
return _amount
7070

7171

72-
# def get_cache(
73-
# cache_dir: str = default_cache_dir,
74-
# index: bool = True,
75-
# ) -> diskcache.core.Cache:
76-
# """Prepare and return a diskcache.Cache object."""
77-
# if not cache_dir:
78-
# raise ValueError("Missing cache directory")
79-
80-
# if not isinstance(cache_dir, Union[str, Path]):
81-
# raise TypeError(f"cache_dir must be of type str or Path, not {type(cache_dir)}")
82-
83-
# try:
84-
# _cache: diskcache.core.Cache = Cache(directory=cache_dir)
85-
86-
# if index:
87-
# cache_tag_index(cache=_cache)
88-
89-
# return _cache
90-
91-
# except Exception as exc:
92-
# raise Exception(f"Unhandled exception creating cache. Details: {exc}")
93-
94-
95-
def get_cache(
72+
def new_cache(
9673
cache_dir: str = default_cache_dir,
9774
cache_conf: dict = None,
9875
index: bool = True,
@@ -117,7 +94,7 @@ def get_cache(
11794
_cache: diskcache.core.Cache = Cache(**cache_conf)
11895

11996
if index:
120-
cache_tag_index(cache=_cache)
97+
manage_cache_tag_index(cache=_cache)
12198

12299
return _cache
123100

@@ -140,7 +117,7 @@ def clear_cache(cache: Cache = None) -> bool:
140117
)
141118

142119

143-
def check_exists(key: str = None, cache: diskcache.core.Cache = None) -> bool:
120+
def check_cache_key_exists(key: str = None, cache: diskcache.core.Cache = None) -> bool:
144121
"""Check if a key exists in a cache."""
145122
## Key validation
146123
validate_key(key=key)
@@ -153,7 +130,7 @@ def check_exists(key: str = None, cache: diskcache.core.Cache = None) -> bool:
153130
return False
154131

155132

156-
def cache_tag_index(operation: str = "create", cache: Cache = None) -> None:
133+
def manage_cache_tag_index(operation: str = "create", cache: Cache = None) -> None:
157134
valid_operations: list[str] = ["create", "delete"]
158135

159136
validate_cache(cache=cache)
@@ -222,7 +199,7 @@ def set_expire(
222199
validate_cache(cache)
223200
validate_expire(expire)
224201

225-
if not check_exists(key=key, cache=cache):
202+
if not check_cache_key_exists(key=key, cache=cache):
226203
return {
227204
"warning": f"Cache item with key [{key}] does not exist in cache at {cache.directory}/"
228205
}
@@ -242,7 +219,7 @@ def get_val(key: valid_key_types = None, cache: Cache = None, tags: list[str] =
242219
validate_cache(cache)
243220
validate_tags(tags)
244221

245-
if check_exists(key=key, cache=cache):
222+
if check_cache_key_exists(key=key, cache=cache):
246223
try:
247224
with cache as ref:
248225
_val = ref.get(key=key)

0 commit comments

Comments
 (0)