bear-utils 0.7.15__py3-none-any.whl → 0.7.16__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -46,6 +46,7 @@ class FileHandlerFactory:
46
46
  try:
47
47
  from .json_file_handler import JsonFileHandler
48
48
  from .log_file_handler import LogFileHandler
49
+ from .toml_file_handler import TomlFileHandler
49
50
  from .txt_file_handler import TextFileHandler
50
51
  from .yaml_file_handler import YamlFileHandler
51
52
 
@@ -53,6 +54,7 @@ class FileHandlerFactory:
53
54
  self.register_handler(TextFileHandler)
54
55
  self.register_handler(YamlFileHandler)
55
56
  self.register_handler(LogFileHandler)
57
+ self.register_handler(TomlFileHandler)
56
58
 
57
59
  except ImportError as e:
58
60
  warnings.warn(f"Could not import all default handlers: {e}")
@@ -0,0 +1,68 @@
1
+ from dataclasses import dataclass
2
+ from pathlib import Path
3
+ from typing import Any, ClassVar
4
+
5
+ import toml
6
+
7
+ from ._base_file_handler import FileHandler
8
+
9
+
10
+ class TomlFileHandler(FileHandler):
11
+ """Class for handling .toml files with read, write, and present methods"""
12
+
13
+ valid_extensions: ClassVar[list[str]] = ["toml"]
14
+
15
+ @FileHandler.ValidateFileType
16
+ def read_file(self, file_path: Path) -> dict:
17
+ try:
18
+ super().read_file(file_path)
19
+
20
+ return toml.load(file_path)
21
+ except Exception as e:
22
+ raise ValueError(f"Error reading file: {e}")
23
+
24
+ @FileHandler.ValidateFileType
25
+ def write_file(self, file_path: Path, data: dict[str, Any] | str, **kwargs) -> None:
26
+ try:
27
+ super().write_file(file_path, data)
28
+
29
+ with open(file_path, "w", encoding="utf-8") as file:
30
+ if isinstance(data, dict):
31
+ toml.dump(data, file, **kwargs)
32
+ else:
33
+ file.write(data)
34
+ except Exception as e:
35
+ raise ValueError(f"Error writing file: {e}")
36
+
37
+ def present_file(self, data: dict[str, Any] | str, **kwargs) -> str:
38
+ raise NotImplementedError("Presenting TOML files is not implemented. Not needed.")
39
+
40
+
41
+ @dataclass
42
+ class PyProjectToml:
43
+ """Dataclass for handling pyproject.toml files"""
44
+
45
+ name: str
46
+ version: str
47
+ description: str | None = None
48
+ author_name: str | None = None
49
+ author_email: str | None = None
50
+ dependencies: list[str] | None = None
51
+
52
+ def __post_init__(self):
53
+ if self.dependencies:
54
+ self.dependencies = [dep.split(" ")[0] for dep in self.dependencies if isinstance(dep, str)]
55
+ self.dependencies = [dep.split(">=")[0] for dep in self.dependencies]
56
+
57
+ @classmethod
58
+ def from_dict(cls, data: dict[str, Any]) -> "PyProjectToml":
59
+ data = data.get("project", {})
60
+ authors: dict = data.get("authors", {})[0]
61
+ return cls(
62
+ name=data.get("name", ""),
63
+ version=data.get("version", ""),
64
+ description=data.get("description"),
65
+ author_name=authors.get("name") if authors else None,
66
+ author_email=authors.get("email") if authors else None,
67
+ dependencies=data.get("dependencies", []),
68
+ )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: bear-utils
3
- Version: 0.7.15
3
+ Version: 0.7.16
4
4
  Summary: Various utilities for Bear programmers, including a rich logging utility, a disk cache, and a SQLite database wrapper amongst other things.
5
5
  Author-email: chaz <bright.lid5647@fastmail.com>
6
6
  Requires-Python: >=3.12
@@ -17,9 +17,10 @@ Requires-Dist: pyyaml>=6.0.2
17
17
  Requires-Dist: rich<15.0.0,>=14.0.0
18
18
  Requires-Dist: singleton-base>=1.0.5
19
19
  Requires-Dist: sqlalchemy<3.0.0,>=2.0.40
20
+ Requires-Dist: toml>=0.10.2
20
21
  Description-Content-Type: text/markdown
21
22
 
22
- # Bear Utils v# Bear Utils v0.7.15
23
+ # Bear Utils v# Bear Utils v0.7.16
23
24
 
24
25
  Personal set of tools and utilities for Python projects, focusing on modularity and ease of use. This library includes components for caching, database management, logging, time handling, file operations, CLI prompts, image processing, clipboard interaction, gradient utilities, event systems, and async helpers.
25
26
 
@@ -37,9 +37,10 @@ bear_utils/files/__init__.py,sha256=Xzo1229NTq-NaeQIvsqUSaFxwm8DFmpxEIfnhDb_uHg,
37
37
  bear_utils/files/ignore_parser.py,sha256=W8SQDUm-_R9abUwvcaA7zr8me281N0kLIP823_sAoyA,10678
38
38
  bear_utils/files/file_handlers/__init__.py,sha256=hXoxBoUP343DyjjBFxQRF7cCB1tEMNor2huYOdlGvqo,87
39
39
  bear_utils/files/file_handlers/_base_file_handler.py,sha256=jNmdYfpN6DRplKNR590Yy3Vd9wuPg27DwnSlm79Ed3o,3164
40
- bear_utils/files/file_handlers/file_handler_factory.py,sha256=8ZY1N6b6onDmNNCDDtsAahv4BdaBmI09YxsqqQxjLbw,9746
40
+ bear_utils/files/file_handlers/file_handler_factory.py,sha256=OJ8Gj0gIpWIr-rlhw52iiR02YJ6nTQuVpylPKCpvFSA,9856
41
41
  bear_utils/files/file_handlers/json_file_handler.py,sha256=YUz4yFHHzO6HcQl0kiiWZCMp57FEaUJ6_yNGhw6tJz4,1482
42
42
  bear_utils/files/file_handlers/log_file_handler.py,sha256=hScsVnJkO17y9tovJatY7VpMyO5kzFGv_1OnQ9oQCiU,1246
43
+ bear_utils/files/file_handlers/toml_file_handler.py,sha256=TWg7dG6OV4diK1NBjDxYPJnYtYVXOYwXmUmeEz_d_g4,2287
43
44
  bear_utils/files/file_handlers/txt_file_handler.py,sha256=dsw1sO6KwzMcqmwt5_UZSv9SF1xisN2Zo2cRNYcO_XI,1250
44
45
  bear_utils/files/file_handlers/yaml_file_handler.py,sha256=Oe8U0fYtDv7q8sFWs_rO3uRQa9olEbrGWF1JuQ2iyTk,2083
45
46
  bear_utils/graphics/__init__.py,sha256=N6EXOyAVoytsKecFKvi4P9Q0biEZeLkLBDor5YFUqYg,218
@@ -73,6 +74,6 @@ bear_utils/logging/logger_manager/loggers/_sub_logger.pyi,sha256=-SCh73lTkqolDq-
73
74
  bear_utils/monitoring/__init__.py,sha256=cj7UYsipfYFwxQmXtMpziAv4suRtGzWEdjdwOCbxJN4,168
74
75
  bear_utils/monitoring/host_monitor.py,sha256=GwIK9X8rATUhYIbOXi4MINfACWgO3T1vzUK1gSK_TQc,12902
75
76
  bear_utils/time/__init__.py,sha256=EHzc9KiGG3l6mAPhiIeFcYqxQG_w0QQ1ES3yRFVr8ug,721
76
- bear_utils-0.7.15.dist-info/METADATA,sha256=zkTMI9QRUXnenC5O2XjZ7zLTwmIhiQaAzJiZ1AVBOz0,7298
77
- bear_utils-0.7.15.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
78
- bear_utils-0.7.15.dist-info/RECORD,,
77
+ bear_utils-0.7.16.dist-info/METADATA,sha256=S7g4ny5792tsaI6u-NxZVP7Yds5zU8SvGC83NtE5R90,7326
78
+ bear_utils-0.7.16.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
79
+ bear_utils-0.7.16.dist-info/RECORD,,