stouputils 1.2.20__tar.gz → 1.2.21__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.21}/PKG-INFO +1 -1
- {stouputils-1.2.20 → stouputils-1.2.21}/pyproject.toml +1 -1
- {stouputils-1.2.20 → stouputils-1.2.21}/stouputils/ctx.py +8 -4
- {stouputils-1.2.20 → stouputils-1.2.21}/stouputils/parallel.py +1 -1
- {stouputils-1.2.20 → stouputils-1.2.21}/stouputils/print.py +9 -3
- {stouputils-1.2.20 → stouputils-1.2.21}/.gitignore +0 -0
- {stouputils-1.2.20 → stouputils-1.2.21}/LICENSE +0 -0
- {stouputils-1.2.20 → stouputils-1.2.21}/README.md +0 -0
- {stouputils-1.2.20 → stouputils-1.2.21}/stouputils/__init__.py +0 -0
- {stouputils-1.2.20 → stouputils-1.2.21}/stouputils/all_doctests.py +0 -0
- {stouputils-1.2.20 → stouputils-1.2.21}/stouputils/applications/__init__.py +0 -0
- {stouputils-1.2.20 → stouputils-1.2.21}/stouputils/applications/automatic_docs.py +0 -0
- {stouputils-1.2.20 → stouputils-1.2.21}/stouputils/archive.py +0 -0
- {stouputils-1.2.20 → stouputils-1.2.21}/stouputils/backup.py +0 -0
- {stouputils-1.2.20 → stouputils-1.2.21}/stouputils/collections.py +0 -0
- {stouputils-1.2.20 → stouputils-1.2.21}/stouputils/continuous_delivery/__init__.py +0 -0
- {stouputils-1.2.20 → stouputils-1.2.21}/stouputils/continuous_delivery/cd_utils.py +0 -0
- {stouputils-1.2.20 → stouputils-1.2.21}/stouputils/continuous_delivery/github.py +0 -0
- {stouputils-1.2.20 → stouputils-1.2.21}/stouputils/continuous_delivery/pypi.py +0 -0
- {stouputils-1.2.20 → stouputils-1.2.21}/stouputils/continuous_delivery/pyproject.py +0 -0
- {stouputils-1.2.20 → stouputils-1.2.21}/stouputils/decorators.py +0 -0
- {stouputils-1.2.20 → stouputils-1.2.21}/stouputils/dont_look/zip_file_override.py +0 -0
- {stouputils-1.2.20 → stouputils-1.2.21}/stouputils/image.py +0 -0
- {stouputils-1.2.20 → stouputils-1.2.21}/stouputils/io.py +0 -0
- {stouputils-1.2.20 → stouputils-1.2.21}/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.21
|
|
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.21"
|
|
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,15 @@ 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 """
|
|
252
254
|
|
|
253
255
|
def write(self, obj: str) -> None:
|
|
254
256
|
""" Write the object to all files while stripping colors if needed.
|
|
@@ -263,6 +265,10 @@ class TeeMultiOutput(object):
|
|
|
263
265
|
# First file (i = 0) (often stdout/stderr) gets the original content
|
|
264
266
|
# Other files (i != 0) get processed content
|
|
265
267
|
|
|
268
|
+
# Skip content if it contains LINE_UP and ignore_lineup is True
|
|
269
|
+
if self.ignore_lineup and (LINE_UP in content or "\r" in content):
|
|
270
|
+
continue
|
|
271
|
+
|
|
266
272
|
# Strip colors if needed
|
|
267
273
|
if self.strip_colors:
|
|
268
274
|
content = remove_colors(content)
|
|
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
|