pygenutils 16.2.2__tar.gz → 16.2.4__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.
- {pygenutils-16.2.2/pygenutils.egg-info → pygenutils-16.2.4}/PKG-INFO +3 -3
- {pygenutils-16.2.2 → pygenutils-16.2.4}/pygenutils/__init__.py +1 -1
- {pygenutils-16.2.2 → pygenutils-16.2.4}/pygenutils/number_bases/base_converters.py +37 -18
- {pygenutils-16.2.2 → pygenutils-16.2.4}/pygenutils/strings/text_formatters.py +4 -2
- {pygenutils-16.2.2 → pygenutils-16.2.4}/pygenutils/time_handling/countdown.py +17 -7
- {pygenutils-16.2.2 → pygenutils-16.2.4/pygenutils.egg-info}/PKG-INFO +3 -3
- {pygenutils-16.2.2 → pygenutils-16.2.4}/pygenutils.egg-info/requires.txt +2 -2
- {pygenutils-16.2.2 → pygenutils-16.2.4}/pyproject.toml +3 -3
- {pygenutils-16.2.2 → pygenutils-16.2.4}/LICENSE +0 -0
- {pygenutils-16.2.2 → pygenutils-16.2.4}/MANIFEST.in +0 -0
- {pygenutils-16.2.2 → pygenutils-16.2.4}/README.md +0 -0
- {pygenutils-16.2.2 → pygenutils-16.2.4}/pygenutils/arrays_and_lists/__init__.py +0 -0
- {pygenutils-16.2.2 → pygenutils-16.2.4}/pygenutils/arrays_and_lists/conversions.py +0 -0
- {pygenutils-16.2.2 → pygenutils-16.2.4}/pygenutils/arrays_and_lists/data_manipulation.py +0 -0
- {pygenutils-16.2.2 → pygenutils-16.2.4}/pygenutils/arrays_and_lists/maths.py +0 -0
- {pygenutils-16.2.2 → pygenutils-16.2.4}/pygenutils/arrays_and_lists/patterns.py +0 -0
- {pygenutils-16.2.2 → pygenutils-16.2.4}/pygenutils/audio_and_video/__init__.py +0 -0
- {pygenutils-16.2.2 → pygenutils-16.2.4}/pygenutils/audio_and_video/audio_and_video_manipulation.py +0 -0
- {pygenutils-16.2.2 → pygenutils-16.2.4}/pygenutils/audio_and_video/merge_audio_and_video.py +0 -0
- {pygenutils-16.2.2 → pygenutils-16.2.4}/pygenutils/audio_and_video/merge_audio_or_video.py +0 -0
- {pygenutils-16.2.2 → pygenutils-16.2.4}/pygenutils/audio_and_video/trim_media.py +0 -0
- {pygenutils-16.2.2 → pygenutils-16.2.4}/pygenutils/dictionaries/__init__.py +0 -0
- {pygenutils-16.2.2 → pygenutils-16.2.4}/pygenutils/dictionaries/dict_handler.py +0 -0
- {pygenutils-16.2.2 → pygenutils-16.2.4}/pygenutils/dictionaries/dict_operators.py +0 -0
- {pygenutils-16.2.2 → pygenutils-16.2.4}/pygenutils/number_bases/__init__.py +0 -0
- {pygenutils-16.2.2 → pygenutils-16.2.4}/pygenutils/number_bases/binary_operations.py +0 -0
- {pygenutils-16.2.2 → pygenutils-16.2.4}/pygenutils/number_bases/bitwise_operators.py +0 -0
- {pygenutils-16.2.2 → pygenutils-16.2.4}/pygenutils/number_bases/mathematical_utils.py +0 -0
- {pygenutils-16.2.2 → pygenutils-16.2.4}/pygenutils/operative_systems/__init__.py +0 -0
- {pygenutils-16.2.2 → pygenutils-16.2.4}/pygenutils/operative_systems/os_operations.py +0 -0
- {pygenutils-16.2.2 → pygenutils-16.2.4}/pygenutils/sets_and_intervals/__init__.py +0 -0
- {pygenutils-16.2.2 → pygenutils-16.2.4}/pygenutils/sets_and_intervals/interval_handler.py +0 -0
- {pygenutils-16.2.2 → pygenutils-16.2.4}/pygenutils/sets_and_intervals/sets_handler.py +0 -0
- {pygenutils-16.2.2 → pygenutils-16.2.4}/pygenutils/strings/__init__.py +0 -0
- {pygenutils-16.2.2 → pygenutils-16.2.4}/pygenutils/strings/string_handler.py +0 -0
- {pygenutils-16.2.2 → pygenutils-16.2.4}/pygenutils/time_handling/__init__.py +0 -0
- {pygenutils-16.2.2 → pygenutils-16.2.4}/pygenutils/time_handling/calendar_utils.py +0 -0
- {pygenutils-16.2.2 → pygenutils-16.2.4}/pygenutils/time_handling/date_and_time_maths.py +0 -0
- {pygenutils-16.2.2 → pygenutils-16.2.4}/pygenutils/time_handling/date_and_time_utils.py +0 -0
- {pygenutils-16.2.2 → pygenutils-16.2.4}/pygenutils/time_handling/program_snippet_exec_timers.py +0 -0
- {pygenutils-16.2.2 → pygenutils-16.2.4}/pygenutils/time_handling/time_formatters.py +0 -0
- {pygenutils-16.2.2 → pygenutils-16.2.4}/pygenutils/time_handling/time_utils.py +0 -0
- {pygenutils-16.2.2 → pygenutils-16.2.4}/pygenutils.egg-info/SOURCES.txt +0 -0
- {pygenutils-16.2.2 → pygenutils-16.2.4}/pygenutils.egg-info/dependency_links.txt +0 -0
- {pygenutils-16.2.2 → pygenutils-16.2.4}/pygenutils.egg-info/top_level.txt +0 -0
- {pygenutils-16.2.2 → pygenutils-16.2.4}/setup.cfg +0 -0
- {pygenutils-16.2.2 → pygenutils-16.2.4}/setup.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pygenutils
|
|
3
|
-
Version: 16.2.
|
|
3
|
+
Version: 16.2.4
|
|
4
4
|
Summary: A comprehensive Python utility library for general-purpose and specialised tasks
|
|
5
5
|
Author-email: Jon Ander Gabantxo <jagabantxo@gmail.com>
|
|
6
6
|
License: MIT License
|
|
@@ -45,8 +45,8 @@ License-File: LICENSE
|
|
|
45
45
|
Requires-Dist: more_itertools>=10.0.0
|
|
46
46
|
Requires-Dist: numpy<2.0.0,>=1.21.0
|
|
47
47
|
Requires-Dist: pandas<2.0.0,>=1.3.0
|
|
48
|
-
Requires-Dist: filewise>=3.11.
|
|
49
|
-
Requires-Dist: paramlib>=3.4.
|
|
48
|
+
Requires-Dist: filewise>=3.11.6
|
|
49
|
+
Requires-Dist: paramlib>=3.4.10
|
|
50
50
|
Provides-Extra: xarray
|
|
51
51
|
Requires-Dist: xarray>=2024.2.0; extra == "xarray"
|
|
52
52
|
Provides-Extra: arrow
|
|
@@ -92,7 +92,7 @@ def _check_input_int(x):
|
|
|
92
92
|
# Procedure checker #
|
|
93
93
|
#-#-#-#-#-#-#-#-#-#-#
|
|
94
94
|
|
|
95
|
-
def _procedure_checker(arg):
|
|
95
|
+
def _procedure_checker(arg, procedure_opts):
|
|
96
96
|
"""
|
|
97
97
|
Checks if the provided procedure is valid.
|
|
98
98
|
|
|
@@ -105,8 +105,8 @@ def _procedure_checker(arg):
|
|
|
105
105
|
------
|
|
106
106
|
ValueError : If the procedure is not valid.
|
|
107
107
|
"""
|
|
108
|
-
if arg not in
|
|
109
|
-
raise ValueError(f"Unsupported procedure. Choose one from {
|
|
108
|
+
if arg not in procedure_opts:
|
|
109
|
+
raise ValueError(f"Unsupported procedure. Choose one from {procedure_opts}.")
|
|
110
110
|
|
|
111
111
|
# Frequently used bases #
|
|
112
112
|
#-----------------------#
|
|
@@ -130,15 +130,12 @@ def dec2bin_basic(n):
|
|
|
130
130
|
The binary representation of the input number.
|
|
131
131
|
"""
|
|
132
132
|
n_checked = _check_input_int(n)
|
|
133
|
-
b = ''
|
|
134
|
-
while
|
|
133
|
+
b = "" # or '_bin', so that we understand the var name better?
|
|
134
|
+
while n_checked >= 1:
|
|
135
135
|
floordiv, mod = divmod(n_checked,2)
|
|
136
136
|
b += str(mod)
|
|
137
|
-
if floordiv == 0:
|
|
138
|
-
break
|
|
139
137
|
n_checked //= 2
|
|
140
|
-
|
|
141
|
-
return b_actual
|
|
138
|
+
return b[::-1]
|
|
142
139
|
|
|
143
140
|
# Advanced #
|
|
144
141
|
#-#-#-#-#-#-
|
|
@@ -162,7 +159,7 @@ def base2bin(n, procedure="format_string", zero_pad=4):
|
|
|
162
159
|
str
|
|
163
160
|
The binary representation of the input number.
|
|
164
161
|
"""
|
|
165
|
-
_procedure_checker(procedure)
|
|
162
|
+
_procedure_checker(procedure, NUMBER_CONVERSION_PROCEDURE_OPTS)
|
|
166
163
|
|
|
167
164
|
if procedure == "default":
|
|
168
165
|
n_bin = bin(n)
|
|
@@ -188,7 +185,7 @@ def base2oct(n, procedure="format_string", zero_pad=4):
|
|
|
188
185
|
str
|
|
189
186
|
The octal representation of the input number.
|
|
190
187
|
"""
|
|
191
|
-
_procedure_checker(procedure)
|
|
188
|
+
_procedure_checker(procedure, NUMBER_CONVERSION_PROCEDURE_OPTS)
|
|
192
189
|
|
|
193
190
|
if procedure == "default":
|
|
194
191
|
n_oct = oct(n)
|
|
@@ -214,7 +211,7 @@ def base2hex(n, procedure="format_string", zero_pad=4):
|
|
|
214
211
|
str
|
|
215
212
|
The hexadecimal representation of the input number.
|
|
216
213
|
"""
|
|
217
|
-
_procedure_checker(procedure)
|
|
214
|
+
_procedure_checker(procedure, NUMBER_CONVERSION_PROCEDURE_OPTS)
|
|
218
215
|
|
|
219
216
|
if procedure == "default":
|
|
220
217
|
if isinstance(n, float):
|
|
@@ -246,7 +243,7 @@ def bin2dec(n_bin):
|
|
|
246
243
|
n = int(n_bin, base=2)
|
|
247
244
|
return n
|
|
248
245
|
|
|
249
|
-
def bin2dec_basic(b):
|
|
246
|
+
def bin2dec_basic(b, procedure="loop"):
|
|
250
247
|
"""
|
|
251
248
|
Converts a binary number to decimal, using mathematical operations
|
|
252
249
|
by definition (hence the name 'basic').
|
|
@@ -257,6 +254,12 @@ def bin2dec_basic(b):
|
|
|
257
254
|
The binary number as a string.
|
|
258
255
|
It can contain the 'b' or '0b' prefix. If so, the function
|
|
259
256
|
will take into account the string without the prefix.
|
|
257
|
+
procedure : str
|
|
258
|
+
The procedure to use for conversion. Options are:
|
|
259
|
+
- 'list_comprehension': Uses a list comprehension with enumerate for a more
|
|
260
|
+
functional approach. Might be more memory intensive for large numbers.
|
|
261
|
+
- 'loop': Uses a traditional for loop with enumerate. More memory efficient
|
|
262
|
+
as it doesn't create an intermediate list.
|
|
260
263
|
|
|
261
264
|
Returns
|
|
262
265
|
-------
|
|
@@ -264,13 +267,28 @@ def bin2dec_basic(b):
|
|
|
264
267
|
The decimal equivalent of the binary number.
|
|
265
268
|
"""
|
|
266
269
|
|
|
270
|
+
# Validations #
|
|
271
|
+
###############
|
|
272
|
+
|
|
273
|
+
# Procedure #
|
|
274
|
+
_procedure_checker(procedure, BIN2DEC_PROCEDURE_OPTS)
|
|
275
|
+
|
|
276
|
+
# Number input #
|
|
267
277
|
b_checked = _check_input_binary(b)
|
|
268
278
|
lb = len(b_checked)
|
|
269
279
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
280
|
+
# Calculation #
|
|
281
|
+
###############
|
|
282
|
+
|
|
283
|
+
if procedure == "list_comprehension":
|
|
284
|
+
summands_iter = [int(b_checked[i]) * 2 ** pos for pos, i in enumerate(range(lb-1,-1,-1))]
|
|
285
|
+
res = sum(summands_iter)
|
|
286
|
+
|
|
287
|
+
elif procedure == "loop":
|
|
288
|
+
res = 0
|
|
289
|
+
for pos, i in enumerate(range(lb-1,-1,-1)):
|
|
290
|
+
res += int(b_checked[i]) * 2 ** pos
|
|
291
|
+
return res
|
|
274
292
|
|
|
275
293
|
|
|
276
294
|
def oct2dec(n_oct):
|
|
@@ -360,4 +378,5 @@ def convert_among_arbitraries(x, base):
|
|
|
360
378
|
# Parameters and constants #
|
|
361
379
|
#--------------------------#
|
|
362
380
|
|
|
363
|
-
|
|
381
|
+
BIN2DEC_PROCEDURE_OPTS = ['list_comprehension', 'loop']
|
|
382
|
+
NUMBER_CONVERSION_PROCEDURE_OPTS = ['default', 'format_string']
|
|
@@ -99,7 +99,7 @@ def format_string(string2format, arg_obj):
|
|
|
99
99
|
raise SyntaxError(SYNTAX_ERROR_STR)
|
|
100
100
|
|
|
101
101
|
|
|
102
|
-
def print_format_string(string2format, arg_obj, end="\n"):
|
|
102
|
+
def print_format_string(string2format, arg_obj, end="\n", flush=False):
|
|
103
103
|
"""
|
|
104
104
|
Format and print a string using Python's format method.
|
|
105
105
|
|
|
@@ -111,6 +111,8 @@ def print_format_string(string2format, arg_obj, end="\n"):
|
|
|
111
111
|
The object used to fill in the placeholders in string2format.
|
|
112
112
|
end : str, optional
|
|
113
113
|
String appended after the last value, default is "\n".
|
|
114
|
+
flush : bool, optional
|
|
115
|
+
Whether to forcibly flush the stream.
|
|
114
116
|
|
|
115
117
|
Raises
|
|
116
118
|
------
|
|
@@ -123,7 +125,7 @@ def print_format_string(string2format, arg_obj, end="\n"):
|
|
|
123
125
|
except Exception as e:
|
|
124
126
|
raise Exception(f"An error occurred: {e}") from e
|
|
125
127
|
else:
|
|
126
|
-
print(formatted_string, end=end)
|
|
128
|
+
print(formatted_string, end=end, flush=flush)
|
|
127
129
|
|
|
128
130
|
|
|
129
131
|
# %-strings (percent-strings) #
|
|
@@ -12,7 +12,7 @@ from time import sleep
|
|
|
12
12
|
# Import project modules #
|
|
13
13
|
#------------------------#
|
|
14
14
|
|
|
15
|
-
from pygenutils.strings.text_formatters import
|
|
15
|
+
from pygenutils.strings.text_formatters import format_string
|
|
16
16
|
from pygenutils.time_handling.time_formatters import parse_dt_string
|
|
17
17
|
|
|
18
18
|
#------------------#
|
|
@@ -56,10 +56,10 @@ def return_dt_string_parts(datetime_str, dt_fmt_str):
|
|
|
56
56
|
except ValueError:
|
|
57
57
|
raise ValueError("Non-numeric values encountered in the datetime string.")
|
|
58
58
|
else:
|
|
59
|
-
dt_obj = parse_dt_string(time_str, dt_fmt_str
|
|
59
|
+
dt_obj = parse_dt_string(time_str, dt_fmt_str)
|
|
60
60
|
return days, dt_obj
|
|
61
61
|
else:
|
|
62
|
-
dt_obj = parse_dt_string(datetime_str, dt_fmt_str
|
|
62
|
+
dt_obj = parse_dt_string(datetime_str, dt_fmt_str)
|
|
63
63
|
return 0, dt_obj # No days component, default to 0.
|
|
64
64
|
|
|
65
65
|
|
|
@@ -79,7 +79,7 @@ def __countdown(time_str, dt_fmt_str):
|
|
|
79
79
|
|
|
80
80
|
Functionality
|
|
81
81
|
-------------
|
|
82
|
-
- Displays the remaining time in the format "D days H
|
|
82
|
+
- Displays the remaining time in the format "D days H:M:S" or "H:M:S".
|
|
83
83
|
- Updates every second using `time.sleep(1)`.
|
|
84
84
|
- Decrements the time until it reaches zero, at which point it prints "Time up!".
|
|
85
85
|
|
|
@@ -89,15 +89,25 @@ def __countdown(time_str, dt_fmt_str):
|
|
|
89
89
|
If the user manually interrupts the countdown (Ctrl+C).
|
|
90
90
|
"""
|
|
91
91
|
days, dt_obj = return_dt_string_parts(time_str, dt_fmt_str)
|
|
92
|
+
|
|
93
|
+
# Calculate maximum width to prevent leftover characters
|
|
94
|
+
max_width = 20 # Sufficient for most countdown formats
|
|
95
|
+
|
|
92
96
|
while days > 0 or (dt_obj.hour, dt_obj.minute, dt_obj.second) != (0, 0, 0):
|
|
93
97
|
# Calculate the time components
|
|
94
98
|
hours, minutes, seconds = dt_obj.hour, dt_obj.minute, dt_obj.second
|
|
99
|
+
|
|
95
100
|
if days > 0:
|
|
96
101
|
DT_ARGS_DAY = [days, hours, minutes, seconds]
|
|
97
|
-
|
|
102
|
+
time_display = format_string(TIME_STR_PARTS_FMTS[0], *DT_ARGS_DAY)
|
|
98
103
|
else:
|
|
99
104
|
DT_ARGS_NODAY = [hours, minutes, seconds]
|
|
100
|
-
|
|
105
|
+
time_display = format_string(TIME_STR_PARTS_FMTS[1], *DT_ARGS_NODAY)
|
|
106
|
+
|
|
107
|
+
# Rellenar la cadena de visualización para limpiar caracteres sobrantes
|
|
108
|
+
# Pad the display string to clear any leftover characters
|
|
109
|
+
padded_display = time_display.ljust(max_width)
|
|
110
|
+
print(padded_display, end="\r", flush=True)
|
|
101
111
|
|
|
102
112
|
# Simulate time passing
|
|
103
113
|
sleep(1)
|
|
@@ -109,7 +119,7 @@ def __countdown(time_str, dt_fmt_str):
|
|
|
109
119
|
if ((hours, minutes, seconds) == (0,0,0) and days > 0):
|
|
110
120
|
days -= 1
|
|
111
121
|
|
|
112
|
-
print("
|
|
122
|
+
print("\nTime up!")
|
|
113
123
|
|
|
114
124
|
#-------------------------#
|
|
115
125
|
# Countdown functionality #
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pygenutils
|
|
3
|
-
Version: 16.2.
|
|
3
|
+
Version: 16.2.4
|
|
4
4
|
Summary: A comprehensive Python utility library for general-purpose and specialised tasks
|
|
5
5
|
Author-email: Jon Ander Gabantxo <jagabantxo@gmail.com>
|
|
6
6
|
License: MIT License
|
|
@@ -45,8 +45,8 @@ License-File: LICENSE
|
|
|
45
45
|
Requires-Dist: more_itertools>=10.0.0
|
|
46
46
|
Requires-Dist: numpy<2.0.0,>=1.21.0
|
|
47
47
|
Requires-Dist: pandas<2.0.0,>=1.3.0
|
|
48
|
-
Requires-Dist: filewise>=3.11.
|
|
49
|
-
Requires-Dist: paramlib>=3.4.
|
|
48
|
+
Requires-Dist: filewise>=3.11.6
|
|
49
|
+
Requires-Dist: paramlib>=3.4.10
|
|
50
50
|
Provides-Extra: xarray
|
|
51
51
|
Requires-Dist: xarray>=2024.2.0; extra == "xarray"
|
|
52
52
|
Provides-Extra: arrow
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "pygenutils"
|
|
7
|
-
version = "16.2.
|
|
7
|
+
version = "16.2.4"
|
|
8
8
|
license = {file = "LICENSE"}
|
|
9
9
|
description = "A comprehensive Python utility library for general-purpose and specialised tasks"
|
|
10
10
|
keywords = ["utilities", "python", "general-purpose", "file handling", "string processing"]
|
|
@@ -29,8 +29,8 @@ dependencies = [
|
|
|
29
29
|
"more_itertools>=10.0.0",
|
|
30
30
|
"numpy>=1.21.0,<2.0.0",
|
|
31
31
|
"pandas>=1.3.0,<2.0.0",
|
|
32
|
-
"filewise>=3.11.
|
|
33
|
-
"paramlib>=3.4.
|
|
32
|
+
"filewise>=3.11.6",
|
|
33
|
+
"paramlib>=3.4.10",
|
|
34
34
|
]
|
|
35
35
|
|
|
36
36
|
[project.optional-dependencies]
|
|
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
|
{pygenutils-16.2.2 → pygenutils-16.2.4}/pygenutils/audio_and_video/audio_and_video_manipulation.py
RENAMED
|
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
|
|
File without changes
|
|
File without changes
|
{pygenutils-16.2.2 → pygenutils-16.2.4}/pygenutils/time_handling/program_snippet_exec_timers.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|