Skip to content

Commit 0235514

Browse files
authored
Dev (#294)
* Start work on HTTPX utils improvements (#290) * Update demo(). Add vscode workspace. Update httpx validators. Move file_utils -> path_utils * Merge changes from main (#293) * Dev (#291) * Start work on HTTPX utils improvements (#290) * Update demo(). Add vscode workspace. Update httpx validators. Move file_utils -> path_utils * release(v0.2.9): (#292) Rename file_utils -> path_utils. Improve validators. Add core.constants, with directory consts like DATA_DIR and CACHE_DIR. TODO: replace any data/cache/serialize dir references with the new constants * remove old references to hardcoded data/cache/serialize dirs. Replace references with new core.constant values * Fix LOG_DIR import
1 parent 8ab6e25 commit 0235514

File tree

11 files changed

+25
-16
lines changed

11 files changed

+25
-16
lines changed

red_utils/core/__init__.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,11 @@
22

33
from . import dataclass_utils, constants
44

5-
from .constants import DATA_DIR, CACHE_DIR, SERIALIZE_DIR, JSON_DIR, ENSURE_EXIST_DIRS
5+
from .constants import (
6+
DATA_DIR,
7+
CACHE_DIR,
8+
SERIALIZE_DIR,
9+
JSON_DIR,
10+
ENSURE_EXIST_DIRS,
11+
LOG_DIR,
12+
)

red_utils/core/constants.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
CACHE_DIR: Path = Path(".cache")
55
SERIALIZE_DIR: Path = Path(".serialize")
66
JSON_DIR: Path = Path(f"{DATA_DIR}/json")
7+
LOG_DIR: Path = Path("logs")
78

8-
ENSURE_EXIST_DIRS: list[Path] = [DATA_DIR, CACHE_DIR, SERIALIZE_DIR]
9+
ENSURE_EXIST_DIRS: list[Path] = [DATA_DIR, CACHE_DIR, SERIALIZE_DIR, LOG_DIR]

red_utils/ext/diskcache_utils/__init__.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44

55
from .classes import CacheInstance
66
from .constants import (
7-
default_cache_dir,
87
default_timeout_dict,
98
valid_key_types,
109
valid_tag_types,
1110
valid_val_types,
1211
)
12+
from red_utils.core.constants import CACHE_DIR
13+
1314
from .operations import (
1415
check_cache,
1516
check_cache_key_exists,
@@ -36,7 +37,7 @@
3637

3738
## Define a default cache object
3839
default_cache_conf: dict[str, Any] = {
39-
"directory": default_cache_dir,
40+
"directory": CACHE_DIR,
4041
"timeout": convert_to_seconds(
4142
unit=default_timeout_dict["unit"], amount=default_timeout_dict["amount"]
4243
),

red_utils/ext/diskcache_utils/classes.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
from typing import Any, Union
66

77
from red_utils.std.dataclass_mixins import DictMixin
8+
from red_utils.core.constants import CACHE_DIR
89

9-
from .constants import default_cache_dir
1010
from .operations import (
1111
check_cache,
1212
check_cache_key_exists,
@@ -34,6 +34,7 @@
3434
from diskcache import Cache
3535
from diskcache.core import warnings
3636

37+
3738
def default_timeout() -> int:
3839
timeout = convert_to_seconds(amount=24, unit="hours")
3940
return timeout
@@ -46,7 +47,7 @@ class CacheInstanceBase(DictMixin):
4647
Implement functionality from operations.py, such as get_val and set_val.
4748
"""
4849

49-
cache_dir: Union[str, Path] | None = field(default=default_cache_dir)
50+
cache_dir: Union[str, Path] | None = field(default=CACHE_DIR)
5051
index: bool = field(default=True)
5152
cache: Cache | None = field(default=None)
5253
cache_timeout: int | None = field(default_factory=default_timeout)

red_utils/ext/diskcache_utils/constants.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class TimeoutConf(DictMixin):
2121
amount: int | None = field(default=15)
2222

2323

24-
default_cache_dir: str = ".cache"
24+
# default_cache_dir: str = ".cache"
2525
## Set default timeout to 24 hours
2626
# default_timeout_dict: dict[str, Union[str, int]] = {"unit": "minutes", "amount": 15}
2727

red_utils/ext/diskcache_utils/operations.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
from pathlib import Path
99
from typing import Optional, Type, Union
1010

11+
from red_utils.core.constants import CACHE_DIR
12+
1113
from .constants import (
12-
default_cache_dir,
1314
default_timeout_dict,
1415
valid_key_types,
1516
valid_tag_types,
@@ -30,6 +31,7 @@
3031

3132
from diskcache import Cache
3233

34+
3335
def convert_to_seconds(amount: int = None, unit: str = None) -> int:
3436
"""Convert an amount of time to seconds.
3537
@@ -77,7 +79,7 @@ def convert_to_seconds(amount: int = None, unit: str = None) -> int:
7779

7880

7981
def new_cache(
80-
cache_dir: str = default_cache_dir,
82+
cache_dir: str = CACHE_DIR,
8183
cache_conf: dict = None,
8284
index: bool = True,
8385
) -> diskcache.core.Cache:

red_utils/ext/loguru_utils/__init__.py

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
LogLevel,
77
default_color_fmt,
88
default_fmt,
9-
default_log_dir,
109
log_levels,
1110
uvicorn_log_conf,
1211
valid_compression_strs,

red_utils/ext/loguru_utils/constants.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
default_color_fmt: str = f"<green>{_ts}</green> <level>{_level}</level> > <level>{_name_line}</level>: {_msg}"
2020
# default_fmt: str = "[{time:YYYY-MM-DD_HH:mm:ss}] [{level}] | [{name}:{line}]: {message}"
2121
# default_color_fmt: str = "<green>[{time:YYYY-MM-DD_HH:mm:ss}]</green> <level>[{level}]</level> | [{name}:{line}]: {message}"
22-
default_log_dir: str = "logs"
22+
# default_log_dir: str = "logs"
2323

2424

2525
@dataclass

red_utils/ext/msgpack_utils/__init__.py

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from . import classes, constants, operations, validators
44
from .classes import SerialFunctionResponse
5-
from .constants import default_serialize_dir
65
from .operations import (
76
ensure_path,
87
msgpack_deserialize,
-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
11
from __future__ import annotations
2-
3-
default_serialize_dir: str = ".serialize"

red_utils/ext/msgpack_utils/operations.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
from uuid import uuid4
66

77
from .classes import SerialFunctionResponse
8-
from .constants import default_serialize_dir
8+
from red_utils.core.constants import SERIALIZE_DIR
99

1010
import msgpack
1111

12+
1213
def ensure_path(dir: Union[str, Path] = None) -> bool:
1314
"""Ensure a directory path exists.
1415
@@ -76,7 +77,7 @@ def msgpack_serialize(
7677

7778

7879
def msgpack_serialize_file(
79-
_json: dict = None, output_dir: str = default_serialize_dir, filename: str = None
80+
_json: dict = None, output_dir: str = SERIALIZE_DIR, filename: str = None
8081
) -> (
8182
SerialFunctionResponse
8283
): ## dict[str, Union[bool, str, dict[str, Union[str, dict]]]]:

0 commit comments

Comments
 (0)