Skip to content

Commit

Permalink
Fix pathlib call and minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
FrancescAlted committed Dec 12, 2024
1 parent 16528ff commit d00afa4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 54 deletions.
13 changes: 5 additions & 8 deletions src/blosc2/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# Avoid checking the name of type annotations at run time
from __future__ import annotations

import contextlib
import copy
import ctypes
import ctypes.util
Expand All @@ -22,7 +23,6 @@
from functools import lru_cache
from typing import TYPE_CHECKING

import cpuinfo
import numpy as np

import blosc2
Expand Down Expand Up @@ -1152,13 +1152,13 @@ def linux_cache_size(cache_level: int, default_size: int) -> int:


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


def read_cached_cpu_info() -> dict:
try:
with open(Path.home() / '.blosc2-cpuinfo.json', 'r') as f:
with open(pathlib.Path.home() / ".blosc2-cpuinfo.json") as f:
return json.load(f)
except (FileNotFoundError, json.JSONDecodeError):
return {}
Expand All @@ -1175,12 +1175,9 @@ def get_cpu_info() -> dict:
except ImportError:
return {}
cpu_info_dict = cpuinfo.get_cpu_info()
try:
with contextlib.suppress(OSError):
# In case cpu info cannot be stored, will need to be recomputed in the next process
write_cached_cpu_info(cpu_info_dict)
except IOError:
# cpu info cannot be stored.
# will need to be recomputed in the next process
pass
return cpu_info_dict


Expand Down
46 changes: 0 additions & 46 deletions tests/test_cpu_info_cache.py

This file was deleted.

0 comments on commit d00afa4

Please sign in to comment.