|
21 | 21 | import sys
|
22 | 22 | from dataclasses import asdict
|
23 | 23 | from functools import lru_cache
|
24 |
| -from typing import TYPE_CHECKING |
| 24 | +from typing import TYPE_CHECKING, Any |
25 | 25 |
|
26 | 26 | import cpuinfo
|
27 | 27 | import numpy as np
|
| 28 | +import platformdirs |
28 | 29 |
|
29 | 30 | import blosc2
|
30 | 31 | from blosc2 import blosc2_ext
|
|
36 | 37 | import torch
|
37 | 38 |
|
38 | 39 |
|
| 40 | +_USER_CACHE_DIR: pathlib.Path = platformdirs.user_cache_path( |
| 41 | + appname="python-blosc2", |
| 42 | + appauthor="blosc", |
| 43 | +) |
| 44 | + |
| 45 | + |
39 | 46 | def _check_typesize(typesize):
|
40 | 47 | if not 1 <= typesize <= blosc2_ext.MAX_TYPESIZE:
|
41 | 48 | raise ValueError(f"typesize can only be in the 1-{blosc2_ext.MAX_TYPESIZE} range.")
|
@@ -1170,14 +1177,15 @@ def _get_cpu_info():
|
1170 | 1177 | return cpu_info
|
1171 | 1178 |
|
1172 | 1179 |
|
1173 |
| -def write_cached_cpu_info(cpu_info_dict: dict[str, any]) -> None: |
1174 |
| - with open(pathlib.Path.home() / ".blosc2-cpuinfo.json", "w") as f: |
| 1180 | +def write_cached_cpu_info(cpu_info_dict: dict[str, Any]) -> None: |
| 1181 | + _USER_CACHE_DIR.mkdir(parents=True, exist_ok=True) |
| 1182 | + with (_USER_CACHE_DIR / "cpuinfo.json").open("w") as f: |
1175 | 1183 | json.dump(cpu_info_dict, f, indent=4)
|
1176 | 1184 |
|
1177 | 1185 |
|
1178 |
| -def read_cached_cpu_info() -> dict: |
| 1186 | +def read_cached_cpu_info() -> dict[str, Any]: |
1179 | 1187 | try:
|
1180 |
| - with open(pathlib.Path.home() / ".blosc2-cpuinfo.json") as f: |
| 1188 | + with (_USER_CACHE_DIR / "cpuinfo.json").open() as f: |
1181 | 1189 | return json.load(f)
|
1182 | 1190 | except (FileNotFoundError, json.JSONDecodeError):
|
1183 | 1191 | return {}
|
|
0 commit comments