Skip to content

Commit 326393c

Browse files
authored
Remove unused utils (#324)
* remove unused core utils * remove unused dependency * remove config.toml
1 parent 1a843e6 commit 326393c

4 files changed

Lines changed: 78 additions & 200 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ dependencies = [
1313
"numpy>=2.2.6",
1414
"pandas>=2.2.3",
1515
"pytest>=8.3.5",
16+
"pytz>=2025.2",
1617
"pyyaml>=6.0.2",
1718
"scipy>=1.15.3",
1819
"soundfile>=0.13.1",
1920
"soxr>=0.5.0.post1",
20-
"tomlkit>=0.13.2",
2121
"tqdm>=4.67.1",
2222
]
2323
classifiers = [

src/osekit/config.toml

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

src/osekit/utils/core_utils.py

Lines changed: 6 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,19 @@
1+
"""Core utils used in OSEkit backend."""
2+
13
from __future__ import annotations
24

3-
import json
45
import os
5-
import shutil
66
import time
77
from bisect import bisect
8-
from importlib.resources import as_file
98
from importlib.util import find_spec
10-
from pathlib import Path
11-
from typing import NamedTuple
12-
13-
try:
14-
import tomllib
15-
except ModuleNotFoundError:
16-
import tomli as tomllib
17-
9+
from typing import TYPE_CHECKING
1810

1911
from osekit.config import global_logging_context as glc
20-
from osekit.config import print_logger
21-
22-
_is_grp_supported = bool(find_spec("grp"))
23-
24-
25-
@glc.set_logger(print_logger)
26-
def display_folder_storage_info(dir_path: str) -> None:
27-
"""Print a detail of the current disk usage."""
28-
usage = shutil.disk_usage(dir_path)
29-
30-
def str_usage(key: str, value: int) -> str:
31-
return f"{f'{key} storage space:':<30}{f'{round(value / (1024**4), 1)} TB':>10}"
3212

33-
total = str_usage("Total", usage.total)
34-
used = str_usage("Used", usage.used)
35-
free = str_usage("Available", usage.free)
36-
glc.logger.info("%s\n%s\n%s\n%s", total, used, f"{'-' * 30:^40}", free)
13+
if TYPE_CHECKING:
14+
from pathlib import Path
3715

38-
39-
def read_config(raw_config: str | dict | Path) -> NamedTuple:
40-
"""Read the given configuration file or dict and converts it to a namedtuple. Only TOML and JSON formats are accepted for now.
41-
42-
Parameter
43-
---------
44-
raw_config : `str` or `Path` or `dict`
45-
The path of the configuration file, or the dict object containing the configuration.
46-
47-
Returns
48-
-------
49-
config : `namedtuple`
50-
The configuration as a `namedtuple` object.
51-
52-
Raises
53-
------
54-
FileNotFoundError
55-
Raised if the raw_config is a string that does not correspond to a valid path, or the raw_config file is not in TOML, JSON or YAML formats.
56-
TypeError
57-
Raised if the raw_config is anything else than a string, a PurePath or a dict.
58-
NotImplementedError
59-
Raised if the raw_config file is in YAML format
60-
61-
"""
62-
match raw_config:
63-
case Path():
64-
with as_file(raw_config) as input_config:
65-
raw_config = input_config
66-
67-
case str():
68-
if not Path(raw_config).is_file:
69-
raise FileNotFoundError(
70-
f"The configuration file {raw_config} does not exist.",
71-
)
72-
73-
case dict():
74-
pass
75-
case _:
76-
raise TypeError(
77-
"The raw_config must be either of type str, dict or Traversable.",
78-
)
79-
80-
if not isinstance(raw_config, dict):
81-
with open(raw_config, "rb") as input_config:
82-
match Path(raw_config).suffix:
83-
case ".toml":
84-
raw_config = tomllib.load(input_config)
85-
case ".json":
86-
raw_config = json.load(input_config)
87-
case ".yaml":
88-
raise NotImplementedError(
89-
"YAML support will eventually get there (unfortunately)",
90-
)
91-
case _:
92-
raise FileNotFoundError(
93-
f"The provided configuration file extension ({Path(raw_config).suffix} is not a valid extension. Please use .toml or .json files.",
94-
)
95-
96-
return raw_config
16+
_is_grp_supported = bool(find_spec("grp"))
9717

9818

9919
def chmod_if_needed(path: Path, mode: int) -> None:

0 commit comments

Comments
 (0)