stouputils 1.19.1__py3-none-any.whl → 1.19.3__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.
stouputils/decorators.py CHANGED
@@ -619,15 +619,12 @@ def _get_wrapper_name(decorator_name: str, func: Callable[..., Any]) -> str:
619
619
 
620
620
 
621
621
  def _set_wrapper_name(wrapper: Callable[..., Any], name: str) -> None:
622
- """ Set the wrapper function's visible name, qualname and code object name for clearer tracebacks.
622
+ """ Set the wrapper function's visible name (code object name) for clearer tracebacks.
623
623
 
624
624
  Args:
625
625
  wrapper (Callable[..., Any]): Wrapper function to update
626
626
  name (str): New name to set
627
627
  """
628
- # __name__ affects repr and some introspection
629
- wrapper.__name__ = name
630
-
631
628
  # Update the code object's co_name so tracebacks show the new name
632
629
  try:
633
630
  wrapper.__code__ = wrapper.__code__.replace(co_name=name)
stouputils/decorators.pyi CHANGED
@@ -251,7 +251,7 @@ def _get_wrapper_name(decorator_name: str, func: Callable[..., Any]) -> str:
251
251
  \t\tstr: Combined name for the wrapper function (e.g., "stouputils.decorators.handle_error@function_name")
252
252
  \t'''
253
253
  def _set_wrapper_name(wrapper: Callable[..., Any], name: str) -> None:
254
- """ Set the wrapper function's visible name, qualname and code object name for clearer tracebacks.
254
+ """ Set the wrapper function's visible name (code object name) for clearer tracebacks.
255
255
 
256
256
  \tArgs:
257
257
  \t\twrapper\t(Callable[..., Any]):\tWrapper function to update
@@ -27,13 +27,23 @@ class CaptureOutput:
27
27
  The class creates an os.pipe(), marks fds as inheritable (for spawn method),
28
28
  provides methods to start a listener thread that reads from the pipe and writes
29
29
  to the main process's sys.stdout/sys.stderr, and to close/join the listener.
30
+
31
+ >>> capturer = CaptureOutput(encoding="utf-8", errors="replace")
32
+
33
+ >>> pass # send capturer object to subprocess
34
+ >>> capturer.redirect() # Redirects sys.stdout/sys.stderr to the pipe
35
+
36
+ >>> pass # in parent process:
37
+ >>> capturer.parent_close_write() # Close parent's write end
38
+ >>> capturer.start_listener() # Start listener thread to read from pipe
39
+ >>> ... # do other work
40
+ >>> capturer.join_listener() # Wait for listener to finish (on EOF)
30
41
  """
31
- def __init__(self, encoding: str = "utf-8", errors: str = "replace", chunk_size: int = 1024):
42
+ def __init__(self, encoding: str = "utf-8", errors: str = "replace"):
32
43
  import multiprocessing as mp
33
44
  import threading
34
45
  self.encoding: str = encoding
35
46
  self.errors: str = errors
36
- self.chunk_size: int = chunk_size
37
47
  self.read_conn, self.write_conn = mp.Pipe(duplex=False)
38
48
  self.read_fd = self.read_conn.fileno()
39
49
  self.write_fd = self.write_conn.fileno()
@@ -91,10 +101,11 @@ class CaptureOutput:
91
101
  nonlocal buffer
92
102
  try:
93
103
  while True:
94
- # Read a chunk from the pipe, stop loop on error
104
+ # Read the next message from the pipe. Use recv_bytes() without a maxlength
105
+ # so we don't error when a single message is larger than our chunk size.
95
106
  try:
96
- data: bytes = self.read_conn.recv_bytes(self.chunk_size)
97
- except EOFError:
107
+ data: bytes = self.read_conn.recv_bytes()
108
+ except (EOFError, OSError, BrokenPipeError):
98
109
  _handle_buffer()
99
110
  break
100
111
 
@@ -104,10 +115,6 @@ class CaptureOutput:
104
115
  except Exception:
105
116
  chunk = data.decode(self.encoding, errors="replace")
106
117
  buffer += chunk
107
-
108
- # Periodically flush large buffers to avoid holding too much memory
109
- if len(buffer) > self.chunk_size * 4:
110
- _handle_buffer()
111
118
  finally:
112
119
  safe_close(self.read_conn)
113
120
  self.read_fd = -1
@@ -12,20 +12,30 @@ class PipeWriter:
12
12
  def flush(self) -> None: ...
13
13
 
14
14
  class CaptureOutput:
15
- """ Utility to capture stdout/stderr from a subprocess and relay it to the parent's stdout.
15
+ ''' Utility to capture stdout/stderr from a subprocess and relay it to the parent\'s stdout.
16
16
 
17
17
  \tThe class creates an os.pipe(), marks fds as inheritable (for spawn method),
18
18
  \tprovides methods to start a listener thread that reads from the pipe and writes
19
- \tto the main process's sys.stdout/sys.stderr, and to close/join the listener.
20
- \t"""
19
+ \tto the main process\'s sys.stdout/sys.stderr, and to close/join the listener.
20
+
21
+ \t>>> capturer = CaptureOutput(encoding="utf-8", errors="replace")
22
+
23
+ \t>>> pass # send capturer object to subprocess
24
+ \t>>> capturer.redirect() # Redirects sys.stdout/sys.stderr to the pipe
25
+
26
+ \t>>> pass # in parent process:
27
+ \t>>> capturer.parent_close_write() # Close parent\'s write end
28
+ \t>>> capturer.start_listener() # Start listener thread to read from pipe
29
+ \t>>> ... # do other work
30
+ \t>>> capturer.join_listener() # Wait for listener to finish (on EOF)
31
+ \t'''
21
32
  encoding: str
22
33
  errors: str
23
- chunk_size: int
24
34
  read_fd: Incomplete
25
35
  write_fd: Incomplete
26
36
  _thread: threading.Thread | None
27
37
  _reader_file: IO[Any] | None
28
- def __init__(self, encoding: str = 'utf-8', errors: str = 'replace', chunk_size: int = 1024) -> None: ...
38
+ def __init__(self, encoding: str = 'utf-8', errors: str = 'replace') -> None: ...
29
39
  def __repr__(self) -> str: ...
30
40
  def __getstate__(self) -> dict[str, Any]: ...
31
41
  def redirect(self) -> None:
stouputils/typing.py CHANGED
@@ -3,7 +3,7 @@ This module provides utilities for typing enhancements such as JSON type aliases
3
3
  - JsonDict
4
4
  - JsonList
5
5
  - JsonMap
6
- - MutJsonMap
6
+ - JsonMutMap
7
7
  - IterAny
8
8
  """
9
9
 
@@ -19,7 +19,7 @@ JsonList = list[Any]
19
19
  """ A type alias for JSON lists """
20
20
  JsonMap = Mapping[str, Any]
21
21
  """ A type alias for JSON mapping """
22
- MutJsonMap = MutableMapping[str, Any]
22
+ JsonMutMap = MutableMapping[str, Any]
23
23
  """ A type alias for mutable JSON mapping """
24
24
  IterAny = Iterable[Any]
25
25
  """ A type alias for iterable of any type """
stouputils/typing.pyi CHANGED
@@ -4,7 +4,7 @@ from typing import Any
4
4
  JsonDict = dict[str, Any]
5
5
  JsonList = list[Any]
6
6
  JsonMap = Mapping[str, Any]
7
- MutJsonMap = MutableMapping[str, Any]
7
+ JsonMutMap = MutableMapping[str, Any]
8
8
  IterAny = Iterable[Any]
9
9
 
10
10
  def convert_to_serializable(obj: Any) -> Any:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: stouputils
3
- Version: 1.19.1
3
+ Version: 1.19.3
4
4
  Summary: Stouputils is a collection of utility modules designed to simplify and enhance the development process. It includes a range of tools for tasks such as execution of doctests, display utilities, decorators, as well as context managers, and many more.
5
5
  Keywords: utilities,tools,helpers,development,python
6
6
  Author: Stoupy51
@@ -109,8 +109,8 @@ stouputils/data_science/scripts/exhaustive_process.py,sha256=Dc5gceIlIiP8U0m1qt3
109
109
  stouputils/data_science/scripts/preprocess_dataset.py,sha256=OLC2KjEtSMeyHHPpNOATfNDuq0lZ09utKhsuzBA4MN4,2929
110
110
  stouputils/data_science/scripts/routine.py,sha256=FkTLzmcdm_qUp69D-dPAKJm2RfXZZLtPgje6lEopu2I,7662
111
111
  stouputils/data_science/utils.py,sha256=HFXI2RQZ53RbBOn_4Act2bi0z4xQlTtsuR5Am80v9JU,11084
112
- stouputils/decorators.py,sha256=t1MIMrh_veMkIAA-kHxVcYUtS6LmLi9XaT_kqA4u0C8,22529
113
- stouputils/decorators.pyi,sha256=cFPYyQOR6hFq2sOmDXjT9Ozfl2UcU1avPwbd5ffL6ho,11249
112
+ stouputils/decorators.py,sha256=rr0CoxFGmcZdk0si8WBpS_Zhw2OlEDbeseLzPzBKLQs,22440
113
+ stouputils/decorators.pyi,sha256=IFevgctRPIJU2GHoc-yIE2-8CSa8MDTZ2NsILWun1wo,11237
114
114
  stouputils/image.py,sha256=E6RYfLhE19KGxn9VdgPCTYXVmOUNK8Qe3RrwSp9OiPs,16479
115
115
  stouputils/image.pyi,sha256=bGbNTG4piQ2PCLFqZCE360O8yE635cKX94SGK0aHNJ8,8311
116
116
  stouputils/installer/__init__.py,sha256=DBwI9w3xvw0NR_jDMxmURwPi1F79kPLe7EuNjmrxW_U,502
@@ -141,8 +141,8 @@ stouputils/lock/shared.py,sha256=G8Mcy7dXtNESyU7hSaeihNrCU4l98VhyQyO_vQYPJ7g,788
141
141
  stouputils/lock/shared.pyi,sha256=0CV6TpTaDEkcGA35Q-ijp8ckImZ32umlMA4U-8C_O-I,545
142
142
  stouputils/parallel/__init__.py,sha256=myD8KiVfPPKF26Xu8Clu0p-VaYDK74loMUjUkl6-9XU,1013
143
143
  stouputils/parallel/__init__.pyi,sha256=UtZKtl9i__OH0Edypap9oZUcTF1h91qfpItG1-x7TfE,97
144
- stouputils/parallel/capturer.py,sha256=1ON8QuMrk9B0WS5lCIKtItzKRmlddrHsJAhMHYvKFyE,4127
145
- stouputils/parallel/capturer.pyi,sha256=DWa3biPFzrGJBmkaFhAWwhbX4gbKQAipBAOJm4_XBy8,1665
144
+ stouputils/parallel/capturer.py,sha256=cJCcauRRkhpUkrPLiAj84CMOPiv4FaYoEUX1jQJoJpY,4539
145
+ stouputils/parallel/capturer.pyi,sha256=c7TADm1YmyOn3LXdV2lnIsvalsRCzvqfldpSbfh2Rx4,2129
146
146
  stouputils/parallel/common.py,sha256=niDcAiEX3flX0ow91gXOB4umlOrR8PIYvpcKPClJHfM,4910
147
147
  stouputils/parallel/common.pyi,sha256=jbyftOYHKP2qaA8YC1f1f12-BDBkhfsQsnPdsR4oet8,2493
148
148
  stouputils/parallel/multi.py,sha256=tHJgcQJwsI6QeKEHoGJC4tsVK_6t1Fazkb06i1u-W_8,12610
@@ -152,11 +152,11 @@ stouputils/parallel/subprocess.pyi,sha256=gzRtpTslvoENLtSNk79fe3Xz8lV3IwuopT9uMH
152
152
  stouputils/print.py,sha256=86Qjyyj_riU7w3RQdYIHTlPVICUzKsfEBF6NBwZc20g,26745
153
153
  stouputils/print.pyi,sha256=qu7Pr1c6let2fLcBvbfrrcfCg0s3rf_1jD8FDhR1bgk,11188
154
154
  stouputils/py.typed,sha256=frcCV1k9oG9oKj3dpUqdJg1PxRT2RSN_XKdLCPjaYaY,2
155
- stouputils/typing.py,sha256=TwvxrvxhBRkyHkoOpfyXebN13M3xJb8MAjKXiNIWjew,2205
156
- stouputils/typing.pyi,sha256=U2UmFZausMYpnsUQROQE2JOwHcjx2hKV0rJuOdR57Ew,1341
155
+ stouputils/typing.py,sha256=9sj6-_lW9pyQFmxW2K1SinGCy7IWeRouUfWjPU2qDsk,2205
156
+ stouputils/typing.pyi,sha256=XRKhGA7jWjcE-DtS2UznevBxBIFqj8IZI8-J48_3GQc,1341
157
157
  stouputils/version_pkg.py,sha256=Jsp-s03L14DkiZ94vQgrlQmaxApfn9DC8M_nzT1SJLk,7014
158
158
  stouputils/version_pkg.pyi,sha256=QPvqp1U3QA-9C_CC1dT9Vahv1hXEhstbM7x5uzMZSsQ,755
159
- stouputils-1.19.1.dist-info/WHEEL,sha256=fAguSjoiATBe7TNBkJwOjyL1Tt4wwiaQGtNtjRPNMQA,80
160
- stouputils-1.19.1.dist-info/entry_points.txt,sha256=tx0z9VOnE-sfkmbFbA93zaBMzV3XSsKEJa_BWIqUzxw,57
161
- stouputils-1.19.1.dist-info/METADATA,sha256=DiuTmyM9i-i6KGOHsuRpQ0qep1tNX9BM-pOomVbbqX0,13931
162
- stouputils-1.19.1.dist-info/RECORD,,
159
+ stouputils-1.19.3.dist-info/WHEEL,sha256=fAguSjoiATBe7TNBkJwOjyL1Tt4wwiaQGtNtjRPNMQA,80
160
+ stouputils-1.19.3.dist-info/entry_points.txt,sha256=tx0z9VOnE-sfkmbFbA93zaBMzV3XSsKEJa_BWIqUzxw,57
161
+ stouputils-1.19.3.dist-info/METADATA,sha256=IVC9UMDtcp6Sauoeg7ocG0OFT9o3jXtgzQUC2aD0-yk,13931
162
+ stouputils-1.19.3.dist-info/RECORD,,