stouputils 1.2.1__tar.gz → 1.2.3__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.1 → stouputils-1.2.3}/PKG-INFO +1 -1
- {stouputils-1.2.1 → stouputils-1.2.3}/pyproject.toml +1 -1
- {stouputils-1.2.1 → stouputils-1.2.3}/stouputils/io.py +2 -3
- {stouputils-1.2.1 → stouputils-1.2.3}/stouputils/print.py +27 -8
- {stouputils-1.2.1 → stouputils-1.2.3}/.gitignore +0 -0
- {stouputils-1.2.1 → stouputils-1.2.3}/LICENSE +0 -0
- {stouputils-1.2.1 → stouputils-1.2.3}/README.md +0 -0
- {stouputils-1.2.1 → stouputils-1.2.3}/stouputils/__init__.py +0 -0
- {stouputils-1.2.1 → stouputils-1.2.3}/stouputils/all_doctests.py +0 -0
- {stouputils-1.2.1 → stouputils-1.2.3}/stouputils/applications/__init__.py +0 -0
- {stouputils-1.2.1 → stouputils-1.2.3}/stouputils/applications/automatic_docs.py +0 -0
- {stouputils-1.2.1 → stouputils-1.2.3}/stouputils/archive.py +0 -0
- {stouputils-1.2.1 → stouputils-1.2.3}/stouputils/backup.py +0 -0
- {stouputils-1.2.1 → stouputils-1.2.3}/stouputils/collections.py +0 -0
- {stouputils-1.2.1 → stouputils-1.2.3}/stouputils/continuous_delivery/__init__.py +0 -0
- {stouputils-1.2.1 → stouputils-1.2.3}/stouputils/continuous_delivery/cd_utils.py +0 -0
- {stouputils-1.2.1 → stouputils-1.2.3}/stouputils/continuous_delivery/github.py +0 -0
- {stouputils-1.2.1 → stouputils-1.2.3}/stouputils/continuous_delivery/pypi.py +0 -0
- {stouputils-1.2.1 → stouputils-1.2.3}/stouputils/continuous_delivery/pyproject.py +0 -0
- {stouputils-1.2.1 → stouputils-1.2.3}/stouputils/ctx.py +0 -0
- {stouputils-1.2.1 → stouputils-1.2.3}/stouputils/decorators.py +0 -0
- {stouputils-1.2.1 → stouputils-1.2.3}/stouputils/dont_look/zip_file_override.py +0 -0
- {stouputils-1.2.1 → stouputils-1.2.3}/stouputils/parallel.py +0 -0
- {stouputils-1.2.1 → stouputils-1.2.3}/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.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
|
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.3"
|
|
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"
|
|
@@ -16,7 +16,6 @@ This module provides utilities for file management.
|
|
|
16
16
|
import shutil
|
|
17
17
|
import json
|
|
18
18
|
import os
|
|
19
|
-
import io
|
|
20
19
|
from typing import IO, Any
|
|
21
20
|
|
|
22
21
|
# Function that replace the "~" by the user's home directory
|
|
@@ -173,13 +172,13 @@ def super_json_load(file_path: str) -> Any:
|
|
|
173
172
|
|
|
174
173
|
|
|
175
174
|
# JSON dump with indentation for levels
|
|
176
|
-
def super_json_dump(data: Any, file:
|
|
175
|
+
def super_json_dump(data: Any, file: IO[Any]|None = None, max_level: int = 2, indent: str = '\t') -> str:
|
|
177
176
|
""" Writes the provided data to a JSON file with a specified indentation depth.
|
|
178
177
|
For instance, setting max_level to 2 will limit the indentation to 2 levels.
|
|
179
178
|
|
|
180
179
|
Args:
|
|
181
180
|
data (Any): The data to dump (usually a dict or a list)
|
|
182
|
-
file (
|
|
181
|
+
file (IO[Any]): The file to dump the data to, if None, the data is returned as a string
|
|
183
182
|
max_level (int): The depth of indentation to stop at (-1 for infinite)
|
|
184
183
|
indent (str): The indentation character (default: '\t')
|
|
185
184
|
Returns:
|
|
@@ -83,15 +83,23 @@ def info(*values: Any, color: str = GREEN, text: str = "INFO ", prefix: str = ""
|
|
|
83
83
|
print(remove_colors(message), *(remove_colors(str(v)) for v in values), file=log_file, **print_kwargs)
|
|
84
84
|
|
|
85
85
|
def debug(*values: Any, **print_kwargs: Any) -> None:
|
|
86
|
-
""" Print a debug message looking like "[DEBUG HH:MM:SS] message" """
|
|
86
|
+
""" Print a debug message looking like "[DEBUG HH:MM:SS] message" in blue by default. """
|
|
87
87
|
if "text" not in print_kwargs:
|
|
88
88
|
print_kwargs["text"] = "DEBUG"
|
|
89
89
|
if "color" not in print_kwargs:
|
|
90
90
|
print_kwargs["color"] = BLUE
|
|
91
91
|
info(*values, **print_kwargs)
|
|
92
92
|
|
|
93
|
+
def alt_debug(*values: Any, **print_kwargs: Any) -> None:
|
|
94
|
+
""" Print a debug message looking like "[DEBUG HH:MM:SS] message" in cyan by default. """
|
|
95
|
+
if "text" not in print_kwargs:
|
|
96
|
+
print_kwargs["text"] = "DEBUG"
|
|
97
|
+
if "color" not in print_kwargs:
|
|
98
|
+
print_kwargs["color"] = CYAN
|
|
99
|
+
info(*values, **print_kwargs)
|
|
100
|
+
|
|
93
101
|
def suggestion(*values: Any, **print_kwargs: Any) -> None:
|
|
94
|
-
""" Print a suggestion message looking like "[SUGGESTION HH:MM:SS] message" """
|
|
102
|
+
""" Print a suggestion message looking like "[SUGGESTION HH:MM:SS] message" in cyan by default. """
|
|
95
103
|
if "text" not in print_kwargs:
|
|
96
104
|
print_kwargs["text"] = "SUGGESTION"
|
|
97
105
|
if "color" not in print_kwargs:
|
|
@@ -99,7 +107,7 @@ def suggestion(*values: Any, **print_kwargs: Any) -> None:
|
|
|
99
107
|
info(*values, **print_kwargs)
|
|
100
108
|
|
|
101
109
|
def progress(*values: Any, **print_kwargs: Any) -> None:
|
|
102
|
-
""" Print a progress message looking like "[PROGRESS HH:MM:SS] message" """
|
|
110
|
+
""" Print a progress message looking like "[PROGRESS HH:MM:SS] message" in magenta by default. """
|
|
103
111
|
if "text" not in print_kwargs:
|
|
104
112
|
print_kwargs["text"] = "PROGRESS"
|
|
105
113
|
if "color" not in print_kwargs:
|
|
@@ -107,7 +115,7 @@ def progress(*values: Any, **print_kwargs: Any) -> None:
|
|
|
107
115
|
info(*values, **print_kwargs)
|
|
108
116
|
|
|
109
117
|
def warning(*values: Any, **print_kwargs: Any) -> None:
|
|
110
|
-
""" Print a warning message looking like "[WARNING HH:MM:SS] message" in sys.stderr """
|
|
118
|
+
""" Print a warning message looking like "[WARNING HH:MM:SS] message" in yellow by default and in sys.stderr. """
|
|
111
119
|
if "file" not in print_kwargs:
|
|
112
120
|
print_kwargs["file"] = sys.stderr
|
|
113
121
|
if "text" not in print_kwargs:
|
|
@@ -117,7 +125,7 @@ def warning(*values: Any, **print_kwargs: Any) -> None:
|
|
|
117
125
|
info(*values, **print_kwargs)
|
|
118
126
|
|
|
119
127
|
def error(*values: Any, exit: bool = True, **print_kwargs: Any) -> None:
|
|
120
|
-
""" Print an error message (in sys.stderr) and optionally ask the user to continue or stop the program
|
|
128
|
+
""" Print an error message (in sys.stderr and in red by default) and optionally ask the user to continue or stop the program.
|
|
121
129
|
|
|
122
130
|
Args:
|
|
123
131
|
values (Any): Values to print (like the print function)
|
|
@@ -144,7 +152,7 @@ def error(*values: Any, exit: bool = True, **print_kwargs: Any) -> None:
|
|
|
144
152
|
print(file=file)
|
|
145
153
|
sys.exit(1)
|
|
146
154
|
|
|
147
|
-
def whatisit(*values: Any, print_function: Callable[..., None] = debug, max_length: int = 250, **print_kwargs: Any) -> None:
|
|
155
|
+
def whatisit(*values: Any, print_function: Callable[..., None] = debug, max_length: int = 250, color: str = CYAN, **print_kwargs: Any) -> None:
|
|
148
156
|
""" Print the type of each value and the value itself, with its id and length/shape.
|
|
149
157
|
|
|
150
158
|
The output format is: "type, <id id_number>: (length/shape) value"
|
|
@@ -153,10 +161,13 @@ def whatisit(*values: Any, print_function: Callable[..., None] = debug, max_leng
|
|
|
153
161
|
values (Any): Values to print
|
|
154
162
|
print_function (Callable): Function to use to print the values (default: debug())
|
|
155
163
|
max_length (int): Maximum length of the value string to print (default: 250)
|
|
164
|
+
color (str): Color of the message (default: CYAN)
|
|
156
165
|
print_kwargs (dict): Keyword arguments to pass to the print function
|
|
157
166
|
"""
|
|
158
167
|
def _internal(value: Any) -> str:
|
|
159
168
|
""" Get the string representation of the value, with length or shape instead of length if shape is available """
|
|
169
|
+
|
|
170
|
+
# Get the length or shape of the value
|
|
160
171
|
length: str = ""
|
|
161
172
|
try:
|
|
162
173
|
length = f"(length: {len(value)}) "
|
|
@@ -166,14 +177,22 @@ def whatisit(*values: Any, print_function: Callable[..., None] = debug, max_leng
|
|
|
166
177
|
length = f"(shape: {value.shape}) "
|
|
167
178
|
except (AttributeError, TypeError):
|
|
168
179
|
pass
|
|
180
|
+
|
|
181
|
+
# Get the string representation of the value
|
|
169
182
|
value_str: str = str(value)
|
|
170
183
|
if len(value_str) > max_length:
|
|
171
184
|
value_str = value_str[:max_length] + "..."
|
|
172
185
|
if "\n" in value_str:
|
|
173
|
-
|
|
186
|
+
value_str = "\n" + value_str # Add a newline before the value if there is a newline in it.
|
|
187
|
+
|
|
188
|
+
# Return the formatted string
|
|
174
189
|
return f"{type(value)}, <id {id(value)}>: {length}{value_str}"
|
|
175
190
|
|
|
176
|
-
#
|
|
191
|
+
# Add the color to the message
|
|
192
|
+
if "color" not in print_kwargs:
|
|
193
|
+
print_kwargs["color"] = color
|
|
194
|
+
|
|
195
|
+
# Print the values
|
|
177
196
|
if len(values) > 1:
|
|
178
197
|
print_function("(What is it?)", **print_kwargs)
|
|
179
198
|
for value in values:
|
|
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
|