stouputils 1.17.0__py3-none-any.whl → 1.18.1__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.
@@ -0,0 +1,64 @@
1
+ from .capturer import CaptureOutput as CaptureOutput
2
+ from collections.abc import Callable as Callable
3
+ from typing import Any
4
+
5
+ def run_in_subprocess[R](func: Callable[..., R], *args: Any, timeout: float | None = None, no_join: bool = False, capture_output: bool = False, **kwargs: Any) -> R:
6
+ ''' Execute a function in a subprocess with positional and keyword arguments.
7
+
8
+ \tThis is useful when you need to run a function in isolation to avoid memory leaks,
9
+ \tresource conflicts, or to ensure a clean execution environment. The subprocess will
10
+ \tbe created, run the function with the provided arguments, and return the result.
11
+
12
+ \tArgs:
13
+ \t\tfunc (Callable): The function to execute in a subprocess.
14
+ \t\t\t(SHOULD BE A TOP-LEVEL FUNCTION TO BE PICKLABLE)
15
+ \t\t*args (Any): Positional arguments to pass to the function.
16
+ \t\ttimeout (float | None): Maximum time in seconds to wait for the subprocess.
17
+ \t\t\tIf None, wait indefinitely. If the subprocess exceeds this time, it will be terminated.
18
+ \t\tno_join (bool): If True, do not wait for the subprocess to finish (fire-and-forget).
19
+ \t\tcapture_output (bool): If True, capture the subprocess\' stdout/stderr and relay it
20
+ \t\t\tin real time to the parent\'s stdout. This enables seeing print() output
21
+ \t\t\tfrom the subprocess in the main process.
22
+ \t\t**kwargs (Any): Keyword arguments to pass to the function.
23
+
24
+ \tReturns:
25
+ \t\tR: The return value of the function.
26
+
27
+ \tRaises:
28
+ \t\tRuntimeError: If the subprocess exits with a non-zero exit code or times out.
29
+ \t\tTimeoutError: If the subprocess exceeds the specified timeout.
30
+
31
+ \tExamples:
32
+ \t\t.. code-block:: python
33
+
34
+ \t\t\t> # Simple function execution
35
+ \t\t\t> run_in_subprocess(doctest_square, 5)
36
+ \t\t\t25
37
+
38
+ \t\t\t> # Function with multiple arguments
39
+ \t\t\t> def add(a: int, b: int) -> int:
40
+ \t\t\t. return a + b
41
+ \t\t\t> run_in_subprocess(add, 10, 20)
42
+ \t\t\t30
43
+
44
+ \t\t\t> # Function with keyword arguments
45
+ \t\t\t> def greet(name: str, greeting: str = "Hello") -> str:
46
+ \t\t\t. return f"{greeting}, {name}!"
47
+ \t\t\t> run_in_subprocess(greet, "World", greeting="Hi")
48
+ \t\t\t\'Hi, World!\'
49
+
50
+ \t\t\t> # With timeout to prevent hanging
51
+ \t\t\t> run_in_subprocess(some_gpu_func, data, timeout=300.0)
52
+ \t'''
53
+ def _subprocess_wrapper[R](result_queue: Any, func: Callable[..., R], args: tuple[Any, ...], kwargs: dict[str, Any], _capturer: CaptureOutput | None = None) -> None:
54
+ """ Wrapper function to execute the target function and store the result in the queue.
55
+
56
+ \tMust be at module level to be pickable on Windows (spawn context).
57
+
58
+ \tArgs:
59
+ \t\tresult_queue (multiprocessing.Queue | None): Queue to store the result or exception (None if detached).
60
+ \t\tfunc (Callable): The target function to execute.
61
+ \t\targs (tuple): Positional arguments for the function.
62
+ \t\tkwargs (dict): Keyword arguments for the function.
63
+ \t\t_capturer (CaptureOutput | None): Optional CaptureOutput instance for stdout capture.
64
+ \t"""
stouputils/print.py CHANGED
@@ -17,7 +17,7 @@ import os
17
17
  import sys
18
18
  import time
19
19
  from collections.abc import Callable, Iterable, Iterator
20
- from typing import IO, Any, TextIO, TypeVar, cast
20
+ from typing import IO, Any, TextIO, cast
21
21
 
22
22
  # Colors constants
23
23
  RESET: str = "\033[0m"
@@ -32,7 +32,6 @@ BOLD: str = "\033[1m"
32
32
 
33
33
  # Constants
34
34
  BAR_FORMAT: str = "{l_bar}{bar}" + MAGENTA + "| {n_fmt}/{total_fmt} [{rate_fmt}{postfix}, {elapsed}<{remaining}]" + RESET
35
- T = TypeVar("T")
36
35
 
37
36
  # Enable colors on Windows 10 terminal if applicable
38
37
  if os.name == "nt":
@@ -443,7 +442,7 @@ def whatisit(
443
442
  try:
444
443
  if not isinstance(value, str | bytes | bytearray | dict | int | float):
445
444
  import numpy as np
446
- mini, maxi = np.min(value), np.max(value)
445
+ mini, maxi = np.min(value), np.max(value) # type: ignore
447
446
  if mini != maxi:
448
447
  metadata_parts.append(f"min: {mini}")
449
448
  metadata_parts.append(f"max: {maxi}")
stouputils/print.pyi CHANGED
@@ -1,5 +1,5 @@
1
1
  from collections.abc import Callable as Callable, Iterable, Iterator
2
- from typing import Any, IO, TextIO, TypeVar
2
+ from typing import Any, IO, TextIO
3
3
 
4
4
  RESET: str
5
5
  RED: str
@@ -11,7 +11,6 @@ CYAN: str
11
11
  LINE_UP: str
12
12
  BOLD: str
13
13
  BAR_FORMAT: str
14
- T = TypeVar('T')
15
14
  previous_args_kwards: tuple[Any, Any]
16
15
  nb_values: int
17
16
  import_time: float
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: stouputils
3
- Version: 1.17.0
3
+ Version: 1.18.1
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
@@ -25,6 +25,7 @@ Requires-Dist: mlflow ; extra == 'data-science'
25
25
  Requires-Dist: tensorflow ; extra == 'data-science'
26
26
  Requires-Dist: scikit-learn ; extra == 'data-science'
27
27
  Requires-Dist: pywavelets ; extra == 'data-science'
28
+ Requires-Dist: mypy ; extra == 'docs'
28
29
  Requires-Dist: m2r2 ; extra == 'docs'
29
30
  Requires-Dist: myst-parser ; extra == 'docs'
30
31
  Requires-Dist: sphinx-copybutton ; extra == 'docs'
@@ -21,8 +21,8 @@ stouputils/archive.py,sha256=uDrPFxbY_C8SwUZRH4FWnYSoJKkFWynCx751zP9AHaY,12144
21
21
  stouputils/archive.pyi,sha256=Z2BbQAiErRYntv53QC9uf_XPw3tx3Oy73wB0Bbil11c,3246
22
22
  stouputils/backup.py,sha256=AE5WKMLiyk0VkRUfhmNfO2EUeUbZY5GTFVIuI5z7axA,20947
23
23
  stouputils/backup.pyi,sha256=-SLVykkR5U8479T84zjNPVBNnV193s0zyWjathY2DDA,4923
24
- stouputils/collections.py,sha256=rAIz4acCxGjZkuvUrb3u5laD130TaNKbng3AITMWffY,9851
25
- stouputils/collections.pyi,sha256=g29fctQAjoJmx-CKh4S6buLSwH2SmivrTGYwc92KqxE,4323
24
+ stouputils/collections.py,sha256=73799uJ5ryQoNBo7N4Cz41Q992QP_kSsw_hy33ZpDyw,11121
25
+ stouputils/collections.pyi,sha256=jPzyaeesz1IqutuT69Bt4DFOguURjXbcYO2l2sifXRA,5448
26
26
  stouputils/continuous_delivery/__init__.py,sha256=JqPww29xZ-pp6OJDGhUj2dxyV9rgTTMUz0YDDVr9RaA,731
27
27
  stouputils/continuous_delivery/__init__.pyi,sha256=_Sz2D10n1CDEyY8qDFwXNKdr01HVxanY4qdq9aN19cc,117
28
28
  stouputils/continuous_delivery/cd_utils.py,sha256=fkaHk2V3j66uFAUsM2c_UddNhXW2KAQcrh7jVsH79pU,8594
@@ -33,10 +33,10 @@ stouputils/continuous_delivery/pypi.py,sha256=H19RwvJN6QS-qcqvjtIaSLfZTA398jXu-S
33
33
  stouputils/continuous_delivery/pypi.pyi,sha256=3zFRz3L_gF_JuSe1J3RZAKTVsFMFiqEdCJbwHRYBj7g,2478
34
34
  stouputils/continuous_delivery/pyproject.py,sha256=olD3QqzLfCLnTBw8IkSKSLBPWyeMv6uS7A0yGdFuIvQ,4802
35
35
  stouputils/continuous_delivery/pyproject.pyi,sha256=bMWwqyG0Auo46dt-dWGePQ9yJ8rSrgb7mnJTfbiS3TQ,2053
36
- stouputils/continuous_delivery/stubs.py,sha256=N0qPBORNYmGIhoY0h40JVvNIS9CS_ixHlxNWQN1bPRE,3514
36
+ stouputils/continuous_delivery/stubs.py,sha256=4FweEA64tU9h4vQuVZqZVa1dXJn2g6ilp5g2GxR_bW8,3515
37
37
  stouputils/continuous_delivery/stubs.pyi,sha256=UrL2dowLC6hsiKe-gfWeVCudz7tKmt4rsiCL9gsBLv4,2392
38
- stouputils/ctx.py,sha256=KVVDmL3pAPX2WM_QzjsmctbG-YfjJ-4aWBSoI7eU_ws,15586
39
- stouputils/ctx.pyi,sha256=-7AJwD9bKzKBFsYlgyULPznstq3LvXRXe2r_2at72FI,9799
38
+ stouputils/ctx.py,sha256=FcoUQoy9lNo-spzacCJPGezOTupNQn3F2Bf24wy8y8I,15521
39
+ stouputils/ctx.pyi,sha256=iXlTfK9Rf1da5kTUGlRw7zwPMVzsfZ1jHmac7zlm6PQ,9770
40
40
  stouputils/data_science/config/get.py,sha256=smdWcu5bBlY38WGtC3GzIF2el-gpvSlDMRNsypmr0JM,1773
41
41
  stouputils/data_science/config/set.py,sha256=PBBnWhgSptWTPkMtq3N1UxmEz_E4ywUcl3daS43wA2M,4175
42
42
  stouputils/data_science/data_processing/image/__init__.py,sha256=ovzV48Bn0tyKXnAMMdujzwT89-1g-PK7GYNlHBrMt9Q,1889
@@ -111,8 +111,8 @@ stouputils/data_science/scripts/routine.py,sha256=FkTLzmcdm_qUp69D-dPAKJm2RfXZZL
111
111
  stouputils/data_science/utils.py,sha256=HFXI2RQZ53RbBOn_4Act2bi0z4xQlTtsuR5Am80v9JU,11084
112
112
  stouputils/decorators.py,sha256=Emgr0XfUOh-MBqkznVOCNmwdHf7o3h1AyIoQklxgULw,21838
113
113
  stouputils/decorators.pyi,sha256=vbPRsvox4dotqcln3StgE6iZ1cWCOeAn56M9zMpdw2U,10948
114
- stouputils/image.py,sha256=CWTpnBys9bBYa7fsGPP6FseYn2Ak0TMwcFg2YnbQLpc,16630
115
- stouputils/image.pyi,sha256=XeSfv23IJvEJUINNLw4hrdgVnrzP4rBcKv5jX_2c8jw,8466
114
+ stouputils/image.py,sha256=E6RYfLhE19KGxn9VdgPCTYXVmOUNK8Qe3RrwSp9OiPs,16479
115
+ stouputils/image.pyi,sha256=bGbNTG4piQ2PCLFqZCE360O8yE635cKX94SGK0aHNJ8,8311
116
116
  stouputils/installer/__init__.py,sha256=DBwI9w3xvw0NR_jDMxmURwPi1F79kPLe7EuNjmrxW_U,502
117
117
  stouputils/installer/__init__.pyi,sha256=ZB-8frAUOW-0pCEJL-e2AdbFodivv46v3EBYwEXCxRo,117
118
118
  stouputils/installer/common.py,sha256=UJr5u02h4LQZQdkmVOkJ3vvW_0-ROGgVMMh0PNoVS1A,2209
@@ -125,8 +125,8 @@ stouputils/installer/main.py,sha256=8wrx_cnQo1dFGRf6x8vtxh6-96tQ-AzMyvJ0S64j0io,
125
125
  stouputils/installer/main.pyi,sha256=r3j4GoMBpU06MpOqjSwoDTiSMOmbA3WWUA87970b6KE,3134
126
126
  stouputils/installer/windows.py,sha256=r2AIuoyAmtMEuoCtQBH9GWQWI-JUT2J9zoH28j9ruOU,4880
127
127
  stouputils/installer/windows.pyi,sha256=tHogIFhPVDQS0I10liLkAxnpaFFAvmFtEVMpPIae5LU,1616
128
- stouputils/io.py,sha256=4GfHaZF-xeyR4K6bj9k9ohgXjOCb966a5XyQUPz_oZw,17187
129
- stouputils/io.pyi,sha256=qKHshtvby6A2OMFLCF7KqIHmOyGkKONYBGENLM8H7Z8,9061
128
+ stouputils/io.py,sha256=Q0Erzy7k8MTEw50s1O_CbuP2bh7oxt42tbcXcUeX97E,17782
129
+ stouputils/io.pyi,sha256=zsId531UOFs-P5kc5cCl3W6oA0X47T_RD2HPDpElZX8,9308
130
130
  stouputils/lock/__init__.py,sha256=8EvKPwnd5oHAWP-2vs6ULUDCSNyUh-mw12nYvBqgVAc,1029
131
131
  stouputils/lock/__init__.pyi,sha256=qcTm6JcGXfwQB2dUCa2wFEInSwJF2pOrYnejSpvGd7k,120
132
132
  stouputils/lock/base.py,sha256=hjSXRzOLVTMNrxpf4QcmfCfdlSRHFT9e130Zz_cqxY8,20483
@@ -139,16 +139,24 @@ stouputils/lock/redis_fifo.py,sha256=AA_McheTa9SHEgO141oUZmi2oYXR_IwzqC5dBWvvPZE
139
139
  stouputils/lock/redis_fifo.pyi,sha256=qFMClixGyYePXi0D4A48RW6FRRDm8Fyf9KCcoxXE5yc,6493
140
140
  stouputils/lock/shared.py,sha256=G8Mcy7dXtNESyU7hSaeihNrCU4l98VhyQyO_vQYPJ7g,788
141
141
  stouputils/lock/shared.pyi,sha256=0CV6TpTaDEkcGA35Q-ijp8ckImZ32umlMA4U-8C_O-I,545
142
- stouputils/parallel.py,sha256=CJUhoB270QT6XXpg0fHOlJdwbvoFd6qFQhCAZDFZng4,21648
143
- stouputils/parallel.pyi,sha256=BTAtl4TFr71LgV3nVBY-yjpxUxlt9m6O2q82tNFHlbE,12420
144
- stouputils/print.py,sha256=q-qSkUGeyn-lBMU5GU36ccm_dTmWS2i_RMxMYUhncfY,24564
145
- stouputils/print.pyi,sha256=SRAAdObriW_LPcqvDGrCpjfGLrswRhIyJmCvC9_3OpM,10232
142
+ stouputils/parallel/__init__.py,sha256=myD8KiVfPPKF26Xu8Clu0p-VaYDK74loMUjUkl6-9XU,1013
143
+ stouputils/parallel/__init__.pyi,sha256=UtZKtl9i__OH0Edypap9oZUcTF1h91qfpItG1-x7TfE,97
144
+ stouputils/parallel/capturer.py,sha256=lo7D1x2RGo9SHkr2sIrY6wL4V5wbsxngnmBMbn5-o_I,4177
145
+ stouputils/parallel/capturer.pyi,sha256=DWa3biPFzrGJBmkaFhAWwhbX4gbKQAipBAOJm4_XBy8,1665
146
+ stouputils/parallel/common.py,sha256=niDcAiEX3flX0ow91gXOB4umlOrR8PIYvpcKPClJHfM,4910
147
+ stouputils/parallel/common.pyi,sha256=jbyftOYHKP2qaA8YC1f1f12-BDBkhfsQsnPdsR4oet8,2493
148
+ stouputils/parallel/multi.py,sha256=tHJgcQJwsI6QeKEHoGJC4tsVK_6t1Fazkb06i1u-W_8,12610
149
+ stouputils/parallel/multi.pyi,sha256=DWolZn1UoXxOfuw7LqEJcU8aQJsN-_DRhPGJlJCA5pQ,8021
150
+ stouputils/parallel/subprocess.py,sha256=YD9mda-zMRpudlby4cLwLJxIY5BjPwn8K11eJ-3k-6E,5790
151
+ stouputils/parallel/subprocess.pyi,sha256=9g5FDYfcnIikd9OOtDP1u_NPT2elk5YjUsQN9eIMSso,3145
152
+ stouputils/print.py,sha256=PNyKvKheI7ior_-jQQ0Xu8ym7tSctheyHXTFykw2MKc,24552
153
+ stouputils/print.pyi,sha256=0z-BFpOEZ48GBGcD08C4Be67cPKX4ZxSHqKyOLRS_M8,10205
146
154
  stouputils/py.typed,sha256=frcCV1k9oG9oKj3dpUqdJg1PxRT2RSN_XKdLCPjaYaY,2
147
155
  stouputils/typing.py,sha256=TwvxrvxhBRkyHkoOpfyXebN13M3xJb8MAjKXiNIWjew,2205
148
156
  stouputils/typing.pyi,sha256=U2UmFZausMYpnsUQROQE2JOwHcjx2hKV0rJuOdR57Ew,1341
149
157
  stouputils/version_pkg.py,sha256=Jsp-s03L14DkiZ94vQgrlQmaxApfn9DC8M_nzT1SJLk,7014
150
158
  stouputils/version_pkg.pyi,sha256=QPvqp1U3QA-9C_CC1dT9Vahv1hXEhstbM7x5uzMZSsQ,755
151
- stouputils-1.17.0.dist-info/WHEEL,sha256=XV0cjMrO7zXhVAIyyc8aFf1VjZ33Fen4IiJk5zFlC3g,80
152
- stouputils-1.17.0.dist-info/entry_points.txt,sha256=tx0z9VOnE-sfkmbFbA93zaBMzV3XSsKEJa_BWIqUzxw,57
153
- stouputils-1.17.0.dist-info/METADATA,sha256=l8yYMpNjDjypUTnO1zC1Xlp2s3QdqS_z8wqYYTMUu-4,13973
154
- stouputils-1.17.0.dist-info/RECORD,,
159
+ stouputils-1.18.1.dist-info/WHEEL,sha256=XV0cjMrO7zXhVAIyyc8aFf1VjZ33Fen4IiJk5zFlC3g,80
160
+ stouputils-1.18.1.dist-info/entry_points.txt,sha256=tx0z9VOnE-sfkmbFbA93zaBMzV3XSsKEJa_BWIqUzxw,57
161
+ stouputils-1.18.1.dist-info/METADATA,sha256=PWMcVUM25QN5JXf9cDGGl-xPQQc3evJlWk8QX6FliFQ,14011
162
+ stouputils-1.18.1.dist-info/RECORD,,