bear-utils 0.7.13__py3-none-any.whl → 0.7.15__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.
@@ -1,4 +1,4 @@
1
- from .commands import MaskShellCommand, OPShellCommand, UVShellCommand
1
+ from .commands import GitCommand, MaskShellCommand, OPShellCommand, UVShellCommand
2
2
  from .shell._base_command import BaseShellCommand
3
3
  from .shell._base_shell import SimpleShellSession, shell_session
4
4
  from .shell._common import DEFAULT_SHELL
@@ -52,8 +52,48 @@ class MaskShellCommand(BaseShellCommand):
52
52
  return cls.sub("init", *args, **kwargs)
53
53
 
54
54
 
55
+ class GitCommand(BaseShellCommand):
56
+ """Base class for Git commands"""
57
+
58
+ command_name = "git"
59
+
60
+ def __init__(self, *args, **kwargs):
61
+ super().__init__(*args, **kwargs)
62
+
63
+ @classmethod
64
+ def init(cls, *args, **kwargs) -> "GitCommand":
65
+ """Initialize a new Git repository"""
66
+ return cls.sub("init", *args, **kwargs)
67
+
68
+ @classmethod
69
+ def status(cls, *args, **kwargs) -> "GitCommand":
70
+ """Get the status of the Git repository"""
71
+ return cls.sub("status", *args, **kwargs)
72
+
73
+ @classmethod
74
+ def log(cls, *args, **kwargs) -> "GitCommand":
75
+ """Show the commit logs"""
76
+ return cls.sub("log", *args, **kwargs)
77
+
78
+ @classmethod
79
+ def add(cls, files, *args, **kwargs) -> "GitCommand":
80
+ """Add files to the staging area"""
81
+ return cls.sub("add", *args, **kwargs).value(files)
82
+
83
+ @classmethod
84
+ def diff(cls, *args, **kwargs) -> "GitCommand":
85
+ """Show changes between commits, commit and working tree, etc."""
86
+ return cls.sub("diff", *args, **kwargs)
87
+
88
+ @classmethod
89
+ def commit(cls, message: str, *args, **kwargs) -> "GitCommand":
90
+ """Commit changes with a message"""
91
+ return cls.sub("commit -m", *args, **kwargs).value(f"'{message}'")
92
+
93
+
55
94
  __all__ = [
56
95
  "MaskShellCommand",
57
96
  "OPShellCommand",
58
97
  "UVShellCommand",
98
+ "GitCommand",
59
99
  ]
@@ -1,3 +1,5 @@
1
+ from asyncio.subprocess import Process
2
+ from subprocess import CompletedProcess
1
3
  from typing import ClassVar, Generic, Self, TypeVar
2
4
 
3
5
  T = TypeVar("T", bound=str)
@@ -56,13 +58,12 @@ class BaseShellCommand(Generic[T]):
56
58
  return f"{joined} {self.suffix}"
57
59
  return joined
58
60
 
59
- def do(self) -> Self:
61
+ def do(self, **kwargs) -> Self:
60
62
  """Run the command using subprocess"""
61
63
  from ._base_shell import shell_session
62
64
 
63
- with shell_session() as session:
64
- session.add(str(self))
65
- self.result = session.run()
65
+ with shell_session(**kwargs) as session:
66
+ self.result: CompletedProcess[str] | Process = session.add(self.cmd).run()
66
67
  return self
67
68
 
68
69
  def get(self) -> str:
@@ -284,17 +284,14 @@ class AsyncShellSession(SimpleShellSession):
284
284
  if self.empty_history and cmd is None:
285
285
  raise ValueError("No commands to run")
286
286
 
287
- self.logger.debug(f"Running command: {cmd} with args: {args}")
288
287
  if self.has_history and cmd is not None:
289
288
  raise ValueError("Use `amp` to chain commands, not `run`")
290
289
  if self.has_history and cmd is None:
291
290
  command = self.cmd
292
291
  elif self.empty_history and cmd is not None:
293
292
  self.cmd_buffer.write(f"{cmd}")
294
- self.logger.info(f"{self.cmd_buffer.getvalue()}")
295
293
  if args:
296
294
  self.cmd_buffer.write(" ".join(map(str, args)))
297
-
298
295
  command = self.cmd
299
296
  else:
300
297
  raise ValueError("Unexpected state")
@@ -305,7 +302,9 @@ class AsyncShellSession(SimpleShellSession):
305
302
  """Communicate with the process, sending input and waiting for completion"""
306
303
  if self.process is None:
307
304
  raise ValueError("No process has been started yet")
308
- stdout, stderr = await self.process.communicate(input=stdin.encode("utf-8"))
305
+ bytes_stdin = stdin.encode("utf-8") if isinstance(stdin, str) else stdin
306
+
307
+ stdout, stderr = await self.process.communicate(input=bytes_stdin)
309
308
  return_code = await self.process.wait()
310
309
 
311
310
  self.result = FancyCompletedProcess(
@@ -332,7 +331,7 @@ class AsyncShellSession(SimpleShellSession):
332
331
  if not line: # EOF
333
332
  break
334
333
  yield line.decode("utf-8").rstrip("\n")
335
- except Exception as e:
334
+ except Exception:
336
335
  break
337
336
 
338
337
  async def stream_stdout(self) -> AsyncGenerator[str, None]:
@@ -1,5 +1,6 @@
1
1
  import asyncio
2
2
  import shutil
3
+ from asyncio.subprocess import PIPE
3
4
  from collections import deque
4
5
  from functools import cached_property
5
6
  from subprocess import CompletedProcess
@@ -79,7 +80,7 @@ class ClipboardManager:
79
80
  Returns:
80
81
  int: The return code of the command.
81
82
  """
82
- await self.shell.run(self._copy)
83
+ await self.shell.run(self._copy, stdin=PIPE)
83
84
  result: CompletedProcess[str] = await self.shell.communicate(stdin=output)
84
85
  if result.returncode == 0:
85
86
  self.clipboard_history.append(output) # Only append to history if the copy was successful
@@ -125,7 +126,7 @@ def copy_to_clipboard(output: str) -> int:
125
126
  int: The return code of the command.
126
127
  """
127
128
  clipboard_manager = ClipboardManager()
128
- loop = asyncio.get_event_loop()
129
+ loop: asyncio.AbstractEventLoop = asyncio.get_event_loop()
129
130
  return loop.run_until_complete(clipboard_manager.copy(output))
130
131
 
131
132
 
@@ -151,7 +152,7 @@ def paste_from_clipboard() -> str:
151
152
  str: The content of the clipboard.
152
153
  """
153
154
  clipboard_manager = ClipboardManager()
154
- loop = asyncio.get_event_loop()
155
+ loop: asyncio.AbstractEventLoop = asyncio.get_event_loop()
155
156
  return loop.run_until_complete(clipboard_manager.paste())
156
157
 
157
158
 
@@ -174,7 +175,7 @@ def clear_clipboard() -> int:
174
175
  int: The return code of the command.
175
176
  """
176
177
  clipboard_manager = ClipboardManager()
177
- loop = asyncio.get_event_loop()
178
+ loop: asyncio.AbstractEventLoop = asyncio.get_event_loop()
178
179
  return loop.run_until_complete(clipboard_manager.clear())
179
180
 
180
181
 
@@ -1,29 +1,25 @@
1
- Metadata-Version: 2.3
1
+ Metadata-Version: 2.4
2
2
  Name: bear-utils
3
- Version: 0.7.13
3
+ Version: 0.7.15
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
- Author: chaz
6
- Author-email: bright.lid5647@fastmail.com
5
+ Author-email: chaz <bright.lid5647@fastmail.com>
7
6
  Requires-Python: >=3.12
8
- Classifier: Programming Language :: Python :: 3
9
- Classifier: Programming Language :: Python :: 3.12
10
- Classifier: Programming Language :: Python :: 3.13
11
- Requires-Dist: bear-epoch-time (>=1.0.1)
12
- Requires-Dist: diskcache (>=5.6.3,<6.0.0)
13
- Requires-Dist: httpx (>=0.28.1)
14
- Requires-Dist: pathspec (>=0.12.1)
15
- Requires-Dist: pillow (>=11.2.1,<12.0.0)
16
- Requires-Dist: prompt-toolkit (>=3.0.51,<4.0.0)
17
- Requires-Dist: pydantic (>=2.11.5)
18
- Requires-Dist: pyglm (>=2.8.2,<3.0.0)
19
- Requires-Dist: pyqt6 (>=6.9.0)
20
- Requires-Dist: pyyaml (>=6.0.2)
21
- Requires-Dist: rich (>=14.0.0,<15.0.0)
22
- Requires-Dist: singleton-base (>=1.0.5)
23
- Requires-Dist: sqlalchemy (>=2.0.40,<3.0.0)
7
+ Requires-Dist: bear-epoch-time>=1.0.1
8
+ Requires-Dist: diskcache<6.0.0,>=5.6.3
9
+ Requires-Dist: httpx>=0.28.1
10
+ Requires-Dist: pathspec>=0.12.1
11
+ Requires-Dist: pillow<12.0.0,>=11.2.1
12
+ Requires-Dist: prompt-toolkit<4.0.0,>=3.0.51
13
+ Requires-Dist: pydantic>=2.11.5
14
+ Requires-Dist: pyglm<3.0.0,>=2.8.2
15
+ Requires-Dist: pyqt6>=6.9.0
16
+ Requires-Dist: pyyaml>=6.0.2
17
+ Requires-Dist: rich<15.0.0,>=14.0.0
18
+ Requires-Dist: singleton-base>=1.0.5
19
+ Requires-Dist: sqlalchemy<3.0.0,>=2.0.40
24
20
  Description-Content-Type: text/markdown
25
21
 
26
- # Bear Utils v# Bear Utils v0.7.13
22
+ # Bear Utils v# Bear Utils v0.7.15
27
23
 
28
24
  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.
29
25
 
@@ -257,4 +253,3 @@ def handle_function(func):
257
253
  # Handle sync function
258
254
  pass
259
255
  ```
260
-
@@ -6,12 +6,12 @@ bear_utils/ai/ai_helpers/_config.py,sha256=UX7wPIiEr2Uqt2kZWtMaYagmRFmUsQKSuopQ4
6
6
  bear_utils/ai/ai_helpers/_parsers.py,sha256=aWbbrB44pRI-CZpmPuVCQalcEd17BDUtE2FVQstq3rU,7993
7
7
  bear_utils/ai/ai_helpers/_types.py,sha256=yTvB00bKIZXu-BKoXtZv6I3vHrxBwxO0gpl61bEslrY,550
8
8
  bear_utils/cache/__init__.py,sha256=PRXhqzVCoMLlu1AwLcNz1w39n4dvjkj3__uYUFQk8Nk,4109
9
- bear_utils/cli/__init__.py,sha256=Lsp03rSXrTikOKI8XFR74-iZoI3IWzNRVgSLlEIzc8M,227
10
- bear_utils/cli/commands.py,sha256=B0eI6iPeE5uaEa7JvfwKZavHe4ZsK_fLFBWxojW1Cx8,1537
9
+ bear_utils/cli/__init__.py,sha256=umMR79Zskl2YY2gWh3e8yI_DEEi5kfb9mPKWlTPxIfY,239
10
+ bear_utils/cli/commands.py,sha256=2uVYhU3qXdpkmQ3gKaUgsplfJMpEVxVGvdnJl-3H7to,2806
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
- bear_utils/cli/shell/_base_command.py,sha256=96zlL6BFWVkC_pJzxlxQy1o3oxu-P4e80mRcLEvS0PY,2251
14
- bear_utils/cli/shell/_base_shell.py,sha256=8PEny2MciOig8r1gN5YHbk3j3L5fFE6mHh2v3XxLAXU,14596
13
+ bear_utils/cli/shell/_base_command.py,sha256=4VsInKhWRSzPyllnXXdueCDKwJz6i7ioZP1bZN-K5T4,2360
14
+ bear_utils/cli/shell/_base_shell.py,sha256=XW55HapnW2_1UnM-SKFQtQgqtOl6uUpUmT0Mn-Mfj6s,14529
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
@@ -29,11 +29,12 @@ bear_utils/events/events_class.py,sha256=pEdZNS8l5wwrn3I4WrFspZlNiy3Lzcwjxr6E2hT
29
29
  bear_utils/events/events_module.py,sha256=NtWqlBpTWAtaC_KVJnweReQe6OU2PXt04yNtAEcATuc,1852
30
30
  bear_utils/extras/__init__.py,sha256=OzjuT-GSI6lT8lmOLBR4-ikA-QrpByy0YRlgiFd7cF4,547
31
31
  bear_utils/extras/_async_helpers.py,sha256=OcgPmCfdAKcTsqGA3Fm8ORkePgaJSok_1t9-sbf-zNQ,416
32
- bear_utils/extras/_tools.py,sha256=yWv-vH0KG_op3zwyxPTYVR1LLGUP6E9tYO5tWVr7Sp4,6965
32
+ bear_utils/extras/_tools.py,sha256=PdOX9KCB5uGEGzJ7SA9qeBukxyYRo160ePqBZU8dJCw,7094
33
33
  bear_utils/extras/platform_utils.py,sha256=vRLybOm_Kk4ysVyNdsv1oTrMHD64vPeGre23fg-kJxI,1257
34
34
  bear_utils/extras/wrappers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
35
35
  bear_utils/extras/wrappers/add_methods.py,sha256=8JI9oFakHRBHcyix6sgqfiXZyXW5antLbyRdFL4F1_M,4222
36
36
  bear_utils/files/__init__.py,sha256=Xzo1229NTq-NaeQIvsqUSaFxwm8DFmpxEIfnhDb_uHg,142
37
+ bear_utils/files/ignore_parser.py,sha256=W8SQDUm-_R9abUwvcaA7zr8me281N0kLIP823_sAoyA,10678
37
38
  bear_utils/files/file_handlers/__init__.py,sha256=hXoxBoUP343DyjjBFxQRF7cCB1tEMNor2huYOdlGvqo,87
38
39
  bear_utils/files/file_handlers/_base_file_handler.py,sha256=jNmdYfpN6DRplKNR590Yy3Vd9wuPg27DwnSlm79Ed3o,3164
39
40
  bear_utils/files/file_handlers/file_handler_factory.py,sha256=8ZY1N6b6onDmNNCDDtsAahv4BdaBmI09YxsqqQxjLbw,9746
@@ -41,7 +42,6 @@ bear_utils/files/file_handlers/json_file_handler.py,sha256=YUz4yFHHzO6HcQl0kiiWZ
41
42
  bear_utils/files/file_handlers/log_file_handler.py,sha256=hScsVnJkO17y9tovJatY7VpMyO5kzFGv_1OnQ9oQCiU,1246
42
43
  bear_utils/files/file_handlers/txt_file_handler.py,sha256=dsw1sO6KwzMcqmwt5_UZSv9SF1xisN2Zo2cRNYcO_XI,1250
43
44
  bear_utils/files/file_handlers/yaml_file_handler.py,sha256=Oe8U0fYtDv7q8sFWs_rO3uRQa9olEbrGWF1JuQ2iyTk,2083
44
- bear_utils/files/ignore_parser.py,sha256=W8SQDUm-_R9abUwvcaA7zr8me281N0kLIP823_sAoyA,10678
45
45
  bear_utils/graphics/__init__.py,sha256=N6EXOyAVoytsKecFKvi4P9Q0biEZeLkLBDor5YFUqYg,218
46
46
  bear_utils/graphics/bear_gradient.py,sha256=bwjJobhgMguEA0FQnjpGzyU3CzFG4bxEvxJtJXAKBcc,4808
47
47
  bear_utils/graphics/image_helpers.py,sha256=fy96H_BkuiCXecDXCMmrlH-SWGsA5SkEUSxlKGzcibI,1374
@@ -54,6 +54,7 @@ bear_utils/gui/gui_tools/qt_color_picker.py,sha256=c_-VMaSqSiceDc3mmu7SPRJ3E_ZWj
54
54
  bear_utils/gui/gui_tools/qt_file_handler.py,sha256=vOYSlQTFiRi-FtXqagp1M_jRSOjz7W-LCb8KXlEtr50,4325
55
55
  bear_utils/gui/gui_tools/qt_input_dialog.py,sha256=MwZ2myLEKRZlldYH_rZtEzPeaz3-fRBP06xBmkTKyAk,9224
56
56
  bear_utils/logging/__init__.py,sha256=o5MX0ow4ugo3JhS2k9vFO0HMzTwUBVnzdhoJBCmqW1g,492
57
+ bear_utils/logging/loggers.py,sha256=oFdKrm9ot7F4pKghzYQrq-BK7RfevKQSBaHsmSolHTA,3196
57
58
  bear_utils/logging/logger_manager/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
58
59
  bear_utils/logging/logger_manager/_common.py,sha256=6r69PIqk6IaIauxax35c5Paz1J1iv87ukbvoZ3uWI_Q,1582
59
60
  bear_utils/logging/logger_manager/_console_junk.py,sha256=vMChuVTNxyxly-onEad1u2tsb6syalXjFVfxOS2-qHw,4821
@@ -69,10 +70,9 @@ bear_utils/logging/logger_manager/loggers/_level_sin.py,sha256=n4EJUZc_z2YQkTzbV
69
70
  bear_utils/logging/logger_manager/loggers/_logger.py,sha256=RbqfrHSyaxIbXEDO63WK5oGMVXsMJIL1Rx8_frYacsQ,547
70
71
  bear_utils/logging/logger_manager/loggers/_sub_logger.py,sha256=YMW03UP9fh_c51Ls1KEoMr-bcAfMt4tTT0OIELpDa_k,3471
71
72
  bear_utils/logging/logger_manager/loggers/_sub_logger.pyi,sha256=-SCh73lTkqolDq-5Ll-lstfl-88gi-E3y1FIknBoI5w,1520
72
- bear_utils/logging/loggers.py,sha256=oFdKrm9ot7F4pKghzYQrq-BK7RfevKQSBaHsmSolHTA,3196
73
73
  bear_utils/monitoring/__init__.py,sha256=cj7UYsipfYFwxQmXtMpziAv4suRtGzWEdjdwOCbxJN4,168
74
74
  bear_utils/monitoring/host_monitor.py,sha256=GwIK9X8rATUhYIbOXi4MINfACWgO3T1vzUK1gSK_TQc,12902
75
75
  bear_utils/time/__init__.py,sha256=EHzc9KiGG3l6mAPhiIeFcYqxQG_w0QQ1ES3yRFVr8ug,721
76
- bear_utils-0.7.13.dist-info/METADATA,sha256=dHAvl1Tw3g0DKioUO3m7KkQay-L_wTFCMxDIoKQy_qc,7494
77
- bear_utils-0.7.13.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
78
- bear_utils-0.7.13.dist-info/RECORD,,
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,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry-core 2.1.3
2
+ Generator: hatchling 1.27.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any