stouputils 1.2.20__tar.gz → 1.2.22__tar.gz
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-1.2.20 → stouputils-1.2.22}/PKG-INFO +1 -1
- {stouputils-1.2.20 → stouputils-1.2.22}/pyproject.toml +1 -1
- {stouputils-1.2.20 → stouputils-1.2.22}/stouputils/ctx.py +8 -4
- {stouputils-1.2.20 → stouputils-1.2.22}/stouputils/parallel.py +1 -1
- {stouputils-1.2.20 → stouputils-1.2.22}/stouputils/print.py +25 -8
- {stouputils-1.2.20 → stouputils-1.2.22}/.gitignore +0 -0
- {stouputils-1.2.20 → stouputils-1.2.22}/LICENSE +0 -0
- {stouputils-1.2.20 → stouputils-1.2.22}/README.md +0 -0
- {stouputils-1.2.20 → stouputils-1.2.22}/stouputils/__init__.py +0 -0
- {stouputils-1.2.20 → stouputils-1.2.22}/stouputils/all_doctests.py +0 -0
- {stouputils-1.2.20 → stouputils-1.2.22}/stouputils/applications/__init__.py +0 -0
- {stouputils-1.2.20 → stouputils-1.2.22}/stouputils/applications/automatic_docs.py +0 -0
- {stouputils-1.2.20 → stouputils-1.2.22}/stouputils/archive.py +0 -0
- {stouputils-1.2.20 → stouputils-1.2.22}/stouputils/backup.py +0 -0
- {stouputils-1.2.20 → stouputils-1.2.22}/stouputils/collections.py +0 -0
- {stouputils-1.2.20 → stouputils-1.2.22}/stouputils/continuous_delivery/__init__.py +0 -0
- {stouputils-1.2.20 → stouputils-1.2.22}/stouputils/continuous_delivery/cd_utils.py +0 -0
- {stouputils-1.2.20 → stouputils-1.2.22}/stouputils/continuous_delivery/github.py +0 -0
- {stouputils-1.2.20 → stouputils-1.2.22}/stouputils/continuous_delivery/pypi.py +0 -0
- {stouputils-1.2.20 → stouputils-1.2.22}/stouputils/continuous_delivery/pyproject.py +0 -0
- {stouputils-1.2.20 → stouputils-1.2.22}/stouputils/decorators.py +0 -0
- {stouputils-1.2.20 → stouputils-1.2.22}/stouputils/dont_look/zip_file_override.py +0 -0
- {stouputils-1.2.20 → stouputils-1.2.22}/stouputils/image.py +0 -0
- {stouputils-1.2.20 → stouputils-1.2.22}/stouputils/io.py +0 -0
- {stouputils-1.2.20 → stouputils-1.2.22}/stouputils/py.typed +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: stouputils
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.22
|
|
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
|
Project-URL: Homepage, https://github.com/Stoupy51/stouputils
|
|
6
6
|
Project-URL: Issues, https://github.com/Stoupy51/stouputils/issues
|
|
@@ -5,7 +5,7 @@ build-backend = "hatchling.build"
|
|
|
5
5
|
|
|
6
6
|
[project]
|
|
7
7
|
name = "stouputils"
|
|
8
|
-
version = "1.2.
|
|
8
|
+
version = "1.2.22"
|
|
9
9
|
description = "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."
|
|
10
10
|
readme = "README.md"
|
|
11
11
|
requires-python = ">=3.10"
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
This module provides context managers for temporarily silencing output.
|
|
3
3
|
|
|
4
4
|
- Muffle: Context manager that temporarily silences output (alternative to stouputils.decorators.silent())
|
|
5
|
-
- LogToFile: Context manager to log to a file every
|
|
5
|
+
- LogToFile: Context manager to log to a file every print call (with LINE_UP handling)
|
|
6
6
|
|
|
7
7
|
.. image:: https://raw.githubusercontent.com/Stoupy51/stouputils/refs/heads/main/assets/ctx_module.gif
|
|
8
8
|
:alt: stouputils ctx examples
|
|
@@ -69,6 +69,7 @@ class LogToFile:
|
|
|
69
69
|
encoding (str): Encoding to use for the file (default: "utf-8")
|
|
70
70
|
tee_stdout (bool): Whether to redirect stdout to the file (default: True)
|
|
71
71
|
tee_stderr (bool): Whether to redirect stderr to the file (default: True)
|
|
72
|
+
ignore_lineup (bool): Whether to ignore lines containing LINE_UP escape sequence in files (default: False)
|
|
72
73
|
|
|
73
74
|
Examples:
|
|
74
75
|
.. code-block:: python
|
|
@@ -84,7 +85,8 @@ class LogToFile:
|
|
|
84
85
|
mode: str = "w",
|
|
85
86
|
encoding: str = "utf-8",
|
|
86
87
|
tee_stdout: bool = True,
|
|
87
|
-
tee_stderr: bool = True
|
|
88
|
+
tee_stderr: bool = True,
|
|
89
|
+
ignore_lineup: bool = True
|
|
88
90
|
) -> None:
|
|
89
91
|
self.path: str = path
|
|
90
92
|
""" Attribute remembering path to the log file """
|
|
@@ -96,6 +98,8 @@ class LogToFile:
|
|
|
96
98
|
""" Whether to redirect stdout to the file """
|
|
97
99
|
self.tee_stderr: bool = tee_stderr
|
|
98
100
|
""" Whether to redirect stderr to the file """
|
|
101
|
+
self.ignore_lineup: bool = ignore_lineup
|
|
102
|
+
""" Whether to ignore lines containing LINE_UP escape sequence in files """
|
|
99
103
|
self.file: IO[Any] = super_open(self.path, mode=self.mode, encoding=self.encoding)
|
|
100
104
|
""" Attribute remembering opened file """
|
|
101
105
|
self.original_stdout: TextIO = sys.stdout
|
|
@@ -107,10 +111,10 @@ class LogToFile:
|
|
|
107
111
|
""" Enter context manager which opens the log file and redirects stdout/stderr """
|
|
108
112
|
# Redirect stdout and stderr if requested
|
|
109
113
|
if self.tee_stdout:
|
|
110
|
-
sys.stdout = TeeMultiOutput(self.original_stdout, self.file)
|
|
114
|
+
sys.stdout = TeeMultiOutput(self.original_stdout, self.file, ignore_lineup=self.ignore_lineup)
|
|
111
115
|
|
|
112
116
|
if self.tee_stderr:
|
|
113
|
-
sys.stderr = TeeMultiOutput(self.original_stderr, self.file)
|
|
117
|
+
sys.stderr = TeeMultiOutput(self.original_stderr, self.file, ignore_lineup=self.ignore_lineup)
|
|
114
118
|
|
|
115
119
|
def __exit__(self, exc_type: type[BaseException]|None, exc_val: BaseException|None, exc_tb: Any|None) -> None:
|
|
116
120
|
""" Exit context manager which closes the log file and restores stdout/stderr """
|
|
@@ -15,7 +15,7 @@ from .print import MAGENTA, RESET
|
|
|
15
15
|
from .decorators import handle_error, LogLevels
|
|
16
16
|
from multiprocessing import Pool, cpu_count
|
|
17
17
|
from typing import Callable, TypeVar
|
|
18
|
-
from tqdm import tqdm
|
|
18
|
+
from tqdm.auto import tqdm
|
|
19
19
|
from tqdm.contrib.concurrent import process_map # type: ignore
|
|
20
20
|
from concurrent.futures import ThreadPoolExecutor
|
|
21
21
|
import time
|
|
@@ -226,13 +226,13 @@ def breakpoint(*values: Any, print_function: Callable[..., None] = warning, **pr
|
|
|
226
226
|
|
|
227
227
|
# TeeMultiOutput class to duplicate output to multiple file-like objects
|
|
228
228
|
class TeeMultiOutput(object):
|
|
229
|
-
""" File-like object that duplicates output to multiple file objects.
|
|
229
|
+
""" File-like object that duplicates output to multiple file-like objects.
|
|
230
230
|
|
|
231
231
|
Args:
|
|
232
232
|
*files (IO[Any]): One or more file-like objects that have write and flush methods
|
|
233
233
|
strip_colors (bool): Whether to strip ANSI color codes from output sent to non-stdout/stderr files
|
|
234
|
-
force_tty (bool): Whether to force reporting as a TTY device (helps with tqdm)
|
|
235
234
|
ascii_only (bool): Whether to replace non-ASCII characters with their ASCII equivalents for non-stdout/stderr files
|
|
235
|
+
ignore_lineup (bool): Whether to ignore lines containing LINE_UP escape sequence in non-terminal outputs
|
|
236
236
|
|
|
237
237
|
Examples:
|
|
238
238
|
>>> f = open("logfile.txt", "w")
|
|
@@ -242,13 +242,27 @@ class TeeMultiOutput(object):
|
|
|
242
242
|
>>> sys.stdout = original_stdout
|
|
243
243
|
>>> f.close()
|
|
244
244
|
"""
|
|
245
|
-
def __init__(self, *files: IO[Any], strip_colors: bool = True, ascii_only: bool = True) -> None:
|
|
245
|
+
def __init__(self, *files: IO[Any], strip_colors: bool = True, ascii_only: bool = True, ignore_lineup: bool = True) -> None:
|
|
246
246
|
self.files: tuple[IO[Any], ...] = files
|
|
247
247
|
""" File-like objects to write to """
|
|
248
248
|
self.strip_colors: bool = strip_colors
|
|
249
249
|
""" Whether to strip ANSI color codes from output sent to non-stdout/stderr files """
|
|
250
250
|
self.ascii_only: bool = ascii_only
|
|
251
251
|
""" Whether to replace non-ASCII characters with their ASCII equivalents for non-stdout/stderr files """
|
|
252
|
+
self.ignore_lineup: bool = ignore_lineup
|
|
253
|
+
""" Whether to ignore lines containing LINE_UP escape sequence in non-terminal outputs """
|
|
254
|
+
|
|
255
|
+
@property
|
|
256
|
+
def encoding(self) -> str:
|
|
257
|
+
""" Get the encoding of the first file, or "utf-8" as fallback.
|
|
258
|
+
|
|
259
|
+
Returns:
|
|
260
|
+
str: The encoding, ex: "utf-8", "ascii", "latin1", etc.
|
|
261
|
+
"""
|
|
262
|
+
try:
|
|
263
|
+
return self.files[0].encoding # type: ignore
|
|
264
|
+
except (IndexError, AttributeError):
|
|
265
|
+
return "utf-8"
|
|
252
266
|
|
|
253
267
|
def write(self, obj: str) -> None:
|
|
254
268
|
""" Write the object to all files while stripping colors if needed.
|
|
@@ -263,6 +277,10 @@ class TeeMultiOutput(object):
|
|
|
263
277
|
# First file (i = 0) (often stdout/stderr) gets the original content
|
|
264
278
|
# Other files (i != 0) get processed content
|
|
265
279
|
|
|
280
|
+
# Skip content if it contains LINE_UP and ignore_lineup is True
|
|
281
|
+
if self.ignore_lineup and (LINE_UP in content or "\r" in content):
|
|
282
|
+
continue
|
|
283
|
+
|
|
266
284
|
# Strip colors if needed
|
|
267
285
|
if self.strip_colors:
|
|
268
286
|
content = remove_colors(content)
|
|
@@ -282,11 +300,10 @@ class TeeMultiOutput(object):
|
|
|
282
300
|
def flush(self) -> None:
|
|
283
301
|
""" Flush all files. """
|
|
284
302
|
for f in self.files:
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
pass
|
|
303
|
+
try:
|
|
304
|
+
f.flush()
|
|
305
|
+
except Exception:
|
|
306
|
+
pass
|
|
290
307
|
|
|
291
308
|
def fileno(self) -> int:
|
|
292
309
|
""" Return the file descriptor of the first file. """
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|