bear-utils 0.7.15__py3-none-any.whl → 0.7.17__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.
- bear_utils/cli/shell/_base_shell.py +2 -1
- bear_utils/files/file_handlers/file_handler_factory.py +2 -0
- bear_utils/files/file_handlers/toml_file_handler.py +68 -0
- {bear_utils-0.7.15.dist-info → bear_utils-0.7.17.dist-info}/METADATA +3 -2
- {bear_utils-0.7.15.dist-info → bear_utils-0.7.17.dist-info}/RECORD +6 -5
- {bear_utils-0.7.15.dist-info → bear_utils-0.7.17.dist-info}/WHEEL +0 -0
@@ -1,5 +1,6 @@
|
|
1
1
|
import asyncio
|
2
2
|
import os
|
3
|
+
import shlex
|
3
4
|
import subprocess
|
4
5
|
from asyncio.streams import StreamReader
|
5
6
|
from asyncio.subprocess import Process
|
@@ -187,7 +188,7 @@ class SimpleShellSession:
|
|
187
188
|
"""Return the combined command as a string"""
|
188
189
|
if not self.cmd_buffer:
|
189
190
|
raise ValueError("No commands have been run yet")
|
190
|
-
full_command: str = f
|
191
|
+
full_command: str = f"{self.shell} -c {shlex.quote(self.cmd_buffer.getvalue())}"
|
191
192
|
return full_command
|
192
193
|
|
193
194
|
@property
|
@@ -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.
|
3
|
+
Version: 0.7.17
|
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.
|
23
|
+
# Bear Utils v# Bear Utils v0.7.17
|
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
|
|
@@ -11,7 +11,7 @@ bear_utils/cli/commands.py,sha256=2uVYhU3qXdpkmQ3gKaUgsplfJMpEVxVGvdnJl-3H7to,28
|
|
11
11
|
bear_utils/cli/prompt_helpers.py,sha256=aGfa4tnO24kFKC-CBJhoiKtll8kc_uU5RvXmxSoD5BM,6094
|
12
12
|
bear_utils/cli/shell/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
13
13
|
bear_utils/cli/shell/_base_command.py,sha256=4VsInKhWRSzPyllnXXdueCDKwJz6i7ioZP1bZN-K5T4,2360
|
14
|
-
bear_utils/cli/shell/_base_shell.py,sha256=
|
14
|
+
bear_utils/cli/shell/_base_shell.py,sha256=nNiG0e9E6GENp7QQqlt9u4XAvpjVEJ-go4y0hpylTOs,14553
|
15
15
|
bear_utils/cli/shell/_common.py,sha256=_KQyL5lvqOfjonFIwlEOyp3K9G3TSOj19RhgVzfNNpg,669
|
16
16
|
bear_utils/config/__init__.py,sha256=htYbcAhIAGXgA4BaSQMKRtwu5RjWwNsnAiD0JxZ82aE,289
|
17
17
|
bear_utils/config/config_manager.py,sha256=WojWwxsTo2Izf2EFxZJXjjUmhqcbbatZ-nBKq436BGw,2631
|
@@ -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=
|
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.
|
77
|
-
bear_utils-0.7.
|
78
|
-
bear_utils-0.7.
|
77
|
+
bear_utils-0.7.17.dist-info/METADATA,sha256=__Mej-Ota4rH8ISTxmBQr3bcK-efr7cUZoelAzCLRUA,7326
|
78
|
+
bear_utils-0.7.17.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
79
|
+
bear_utils-0.7.17.dist-info/RECORD,,
|
File without changes
|