bear-utils 0.8.4__py3-none-any.whl → 0.8.6__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_command.py +15 -6
- bear_utils/cli/shell/_base_shell.py +4 -4
- bear_utils/extras/responses/function_response.py +4 -4
- {bear_utils-0.8.4.dist-info → bear_utils-0.8.6.dist-info}/METADATA +2 -2
- {bear_utils-0.8.4.dist-info → bear_utils-0.8.6.dist-info}/RECORD +6 -6
- {bear_utils-0.8.4.dist-info → bear_utils-0.8.6.dist-info}/WHEEL +0 -0
@@ -1,4 +1,5 @@
|
|
1
|
-
from
|
1
|
+
from subprocess import CompletedProcess
|
2
|
+
from typing import TYPE_CHECKING, Any, ClassVar, Self
|
2
3
|
|
3
4
|
if TYPE_CHECKING:
|
4
5
|
from subprocess import CompletedProcess
|
@@ -49,9 +50,9 @@ class BaseShellCommand[T: str]:
|
|
49
50
|
@property
|
50
51
|
def cmd(self) -> str:
|
51
52
|
"""Return the full command as a string"""
|
52
|
-
cmd_parts = [self.command_name, self.sub_command, *self.args]
|
53
|
-
cmd_parts = [part for part in cmd_parts if part]
|
54
|
-
joined:
|
53
|
+
cmd_parts: list[str] = [self.command_name, self.sub_command, *self.args]
|
54
|
+
cmd_parts: list[str] = [part for part in cmd_parts if part]
|
55
|
+
joined: str = " ".join(cmd_parts).strip()
|
55
56
|
if self.suffix:
|
56
57
|
return f"{joined} {self.suffix}"
|
57
58
|
return joined
|
@@ -61,11 +62,19 @@ class BaseShellCommand[T: str]:
|
|
61
62
|
from ._base_shell import shell_session # noqa: PLC0415
|
62
63
|
|
63
64
|
with shell_session(**kwargs) as session:
|
64
|
-
result = session.add(self.cmd).run()
|
65
|
+
result: CompletedProcess[str] = session.add(self.cmd).run()
|
65
66
|
if result is not None:
|
66
|
-
self.result =
|
67
|
+
self.result = result
|
67
68
|
return self
|
68
69
|
|
70
|
+
def get_result(self) -> CompletedProcess[str]:
|
71
|
+
"""Get the result of the command execution"""
|
72
|
+
if self.result is None:
|
73
|
+
self.do()
|
74
|
+
if self.result is None:
|
75
|
+
raise RuntimeError("Command execution failed for some reason.")
|
76
|
+
return self.result
|
77
|
+
|
69
78
|
def get(self) -> str:
|
70
79
|
"""Get the result of the command execution"""
|
71
80
|
if self.result is None:
|
@@ -147,7 +147,7 @@ class SimpleShellSession:
|
|
147
147
|
self.cmd_buffer.write(str(c))
|
148
148
|
return self
|
149
149
|
|
150
|
-
def _run(self, command: str) -> CompletedProcess[str]
|
150
|
+
def _run(self, command: str) -> CompletedProcess[str]:
|
151
151
|
"""Internal method to run the accumulated command"""
|
152
152
|
self.logger.verbose(f"Executing: {command}")
|
153
153
|
self.next_cmd()
|
@@ -180,7 +180,7 @@ class SimpleShellSession:
|
|
180
180
|
self.reset_buffer()
|
181
181
|
return self.result
|
182
182
|
|
183
|
-
def run(self, cmd: str | BaseShellCommand | None = None, *args) -> CompletedProcess[str]
|
183
|
+
def run(self, cmd: str | BaseShellCommand | None = None, *args) -> CompletedProcess[str]:
|
184
184
|
"""Run the accumulated command history"""
|
185
185
|
if self.empty_history and cmd is None:
|
186
186
|
raise ValueError("No commands to run")
|
@@ -191,12 +191,12 @@ class SimpleShellSession:
|
|
191
191
|
)
|
192
192
|
|
193
193
|
if self.has_history and cmd is None:
|
194
|
-
result: CompletedProcess[str]
|
194
|
+
result: CompletedProcess[str] = self._run(self.cmd)
|
195
195
|
elif self.empty_history and cmd is not None:
|
196
196
|
self.cmd_buffer.write(f"{cmd} ")
|
197
197
|
if args:
|
198
198
|
self.cmd_buffer.write(" ".join(map(str, args)))
|
199
|
-
result: CompletedProcess[str]
|
199
|
+
result: CompletedProcess[str] = self._run(self.cmd)
|
200
200
|
else:
|
201
201
|
raise ValueError("Unexpected state")
|
202
202
|
self.reset_buffer()
|
@@ -269,15 +269,15 @@ class FunctionResponse(BaseModel):
|
|
269
269
|
if content is not None and error is None:
|
270
270
|
if isinstance(content, list):
|
271
271
|
for item in content:
|
272
|
-
logger.info(
|
272
|
+
logger.info(f"{self.name}: {item}" if self.name else item)
|
273
273
|
elif isinstance(content, str):
|
274
|
-
logger.info(
|
274
|
+
logger.info(f"{self.name}: {content}" if self.name else content)
|
275
275
|
elif error is not None and content is None:
|
276
276
|
if isinstance(error, list):
|
277
277
|
for err in error:
|
278
|
-
logger.error(
|
278
|
+
logger.error(f"{self.name}: {err}" if self.name else err)
|
279
279
|
elif isinstance(error, str):
|
280
|
-
logger.error(
|
280
|
+
logger.error(f"{self.name}: {error}" if self.name else error)
|
281
281
|
|
282
282
|
@overload
|
283
283
|
def done(self, to_dict: Literal[True], suppress: list[str] | None = None) -> dict[str, Any]: ...
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: bear-utils
|
3
|
-
Version: 0.8.
|
3
|
+
Version: 0.8.6
|
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
|
@@ -20,7 +20,7 @@ Requires-Dist: tinydb>=4.8.2
|
|
20
20
|
Requires-Dist: toml>=0.10.2
|
21
21
|
Description-Content-Type: text/markdown
|
22
22
|
|
23
|
-
# Bear Utils v# Bear Utils v0.8.
|
23
|
+
# Bear Utils v# Bear Utils v0.8.6
|
24
24
|
|
25
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.
|
26
26
|
|
@@ -14,8 +14,8 @@ bear_utils/cli/__init__.py,sha256=H2QpLyHpQS_Yn3sF2px7n4KqT97LEe7Oyzafg2iHcpc,50
|
|
14
14
|
bear_utils/cli/commands.py,sha256=5ppEjvVV_g28WLaIFtKgz-ctzwoo-g-KpHTXNx9xBzo,3161
|
15
15
|
bear_utils/cli/prompt_helpers.py,sha256=DVdg1f5yZElVyFNao6RTPfrc6mKy4PoXLgY6az-ejo8,6580
|
16
16
|
bear_utils/cli/shell/__init__.py,sha256=2s3oR6CqLKj1iyERy7YafWT3t3KzTr70Z1yaLKa6IiQ,42
|
17
|
-
bear_utils/cli/shell/_base_command.py,sha256=
|
18
|
-
bear_utils/cli/shell/_base_shell.py,sha256=
|
17
|
+
bear_utils/cli/shell/_base_command.py,sha256=T1bwY9UX355Mv2u7JjSgI4U7VoWCTibszG8WvC3IEo4,2789
|
18
|
+
bear_utils/cli/shell/_base_shell.py,sha256=GW2kgj_KR33FtJLvV-ljSs_wzo5WQ8--H-K2hDPOblQ,16697
|
19
19
|
bear_utils/cli/shell/_common.py,sha256=_KQyL5lvqOfjonFIwlEOyp3K9G3TSOj19RhgVzfNNpg,669
|
20
20
|
bear_utils/config/__init__.py,sha256=HC_lWpmLF0kbPr5i1Wa2FLER2b446E_GecgU9EPmc04,353
|
21
21
|
bear_utils/config/config_manager.py,sha256=Xj0xOmY-wo_rwfcWiXyxNZWX9NknX_Jm9W56Gx8yyHQ,8244
|
@@ -37,7 +37,7 @@ bear_utils/extras/_async_helpers.py,sha256=cxq5d24NHkECmZqTVXEazv6K-XUa7skFnX6KQ
|
|
37
37
|
bear_utils/extras/_tools.py,sha256=kxJ1jaqx3PvLpc0CZUIV8XQUwjQGrNCRLoka11aNtoc,7672
|
38
38
|
bear_utils/extras/platform_utils.py,sha256=Ai7ow7S-_cKb5zFwFh8dkC8xmbMJFy-0_-w3NCERdEw,1362
|
39
39
|
bear_utils/extras/responses/__init__.py,sha256=XbE4VKemrKRwx9E5jqy__OiM_AAjA58ebnqQ2hytnT0,225
|
40
|
-
bear_utils/extras/responses/function_response.py,sha256=
|
40
|
+
bear_utils/extras/responses/function_response.py,sha256=D6123VaOaJeeSQ9Gp1gtrvCSv7HF5Iw7dZlGbxHVQDk,14121
|
41
41
|
bear_utils/extras/wrappers/__init__.py,sha256=crh4sKOLvuhNMVX5bJYjCFWtXtH7G47UgNPOHq3HXTk,43
|
42
42
|
bear_utils/extras/wrappers/add_methods.py,sha256=z2XZG2ZoYOB1MaGiLli4NRyyTeRgBy7tuYsiy8mTa9s,4422
|
43
43
|
bear_utils/files/__init__.py,sha256=mIdnFSXoDE64ElM43bN2m6KuafURnN82ki0pdqN8q2o,201
|
@@ -80,6 +80,6 @@ bear_utils/monitoring/__init__.py,sha256=9DKNIWTp_voLnaWgiP-wJ-o_N0hYixo-MzjUmg8
|
|
80
80
|
bear_utils/monitoring/_common.py,sha256=LYQFxgTP9fk0cH71IQTuGwBYYPWCqHP_mMRNecoD76M,657
|
81
81
|
bear_utils/monitoring/host_monitor.py,sha256=e0TYRJw9iDj5Ga6y3ck1TBFEeH42Cax5mQYaNU8yams,13241
|
82
82
|
bear_utils/time/__init__.py,sha256=d9Ovv-Dlx5NWgnOl1hY-evznVm9hboS6ypNp1wDFxQQ,934
|
83
|
-
bear_utils-0.8.
|
84
|
-
bear_utils-0.8.
|
85
|
-
bear_utils-0.8.
|
83
|
+
bear_utils-0.8.6.dist-info/METADATA,sha256=QG8sOkLV4XiFr490DziS-jSq9tIaICPgMvz--TgyaZI,8634
|
84
|
+
bear_utils-0.8.6.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
85
|
+
bear_utils-0.8.6.dist-info/RECORD,,
|
File without changes
|