Skip to content

Commit d00afa4

Browse files
committed
Fix pathlib call and minor improvements
1 parent 16528ff commit d00afa4

File tree

2 files changed

+5
-54
lines changed

2 files changed

+5
-54
lines changed

src/blosc2/core.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
# Avoid checking the name of type annotations at run time
99
from __future__ import annotations
1010

11+
import contextlib
1112
import copy
1213
import ctypes
1314
import ctypes.util
@@ -22,7 +23,6 @@
2223
from functools import lru_cache
2324
from typing import TYPE_CHECKING
2425

25-
import cpuinfo
2626
import numpy as np
2727

2828
import blosc2
@@ -1152,13 +1152,13 @@ def linux_cache_size(cache_level: int, default_size: int) -> int:
11521152

11531153

11541154
def write_cached_cpu_info(cpu_info_dict: dict[str, any]) -> None:
1155-
with open(Path.home() / '.blosc2-cpuinfo.json', 'w') as f:
1155+
with open(pathlib.Path.home() / ".blosc2-cpuinfo.json", "w") as f:
11561156
json.dump(cpu_info_dict, f, indent=4)
11571157

11581158

11591159
def read_cached_cpu_info() -> dict:
11601160
try:
1161-
with open(Path.home() / '.blosc2-cpuinfo.json', 'r') as f:
1161+
with open(pathlib.Path.home() / ".blosc2-cpuinfo.json") as f:
11621162
return json.load(f)
11631163
except (FileNotFoundError, json.JSONDecodeError):
11641164
return {}
@@ -1175,12 +1175,9 @@ def get_cpu_info() -> dict:
11751175
except ImportError:
11761176
return {}
11771177
cpu_info_dict = cpuinfo.get_cpu_info()
1178-
try:
1178+
with contextlib.suppress(OSError):
1179+
# In case cpu info cannot be stored, will need to be recomputed in the next process
11791180
write_cached_cpu_info(cpu_info_dict)
1180-
except IOError:
1181-
# cpu info cannot be stored.
1182-
# will need to be recomputed in the next process
1183-
pass
11841181
return cpu_info_dict
11851182

11861183

tests/test_cpu_info_cache.py

Lines changed: 0 additions & 46 deletions
This file was deleted.

0 commit comments

Comments
 (0)