utils-mystuff 1.0.0__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.
Potentially problematic release.
This version of utils-mystuff might be problematic. Click here for more details.
- utils_mystuff/__init__.py +51 -0
- utils_mystuff/convert_regex.py +241 -0
- utils_mystuff/logger_CLI.py +200 -0
- utils_mystuff/utils_GUI.py +442 -0
- utils_mystuff/utils_filehandling.py +204 -0
- utils_mystuff/utils_various.py +461 -0
- utils_mystuff/version.py +55 -0
- utils_mystuff-1.0.0.dist-info/METADATA +82 -0
- utils_mystuff-1.0.0.dist-info/RECORD +12 -0
- utils_mystuff-1.0.0.dist-info/WHEEL +4 -0
- utils_mystuff-1.0.0.dist-info/licenses/AUTHORS.md +3 -0
- utils_mystuff-1.0.0.dist-info/licenses/LICENSE.txt +32 -0
|
@@ -0,0 +1,461 @@
|
|
|
1
|
+
# utilities - miscellaneous
|
|
2
|
+
|
|
3
|
+
"""
|
|
4
|
+
Module contains a collection of miscellaneous utilties.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
# ruff and mypy per file settings
|
|
9
|
+
#
|
|
10
|
+
# empty lines
|
|
11
|
+
# ruff: noqa: E302, E303
|
|
12
|
+
# naming conventions
|
|
13
|
+
# ruff: noqa: N801, N802, N803, N806, N812, N813, N815, N816, N818, N999
|
|
14
|
+
# boolean-type arguments
|
|
15
|
+
# ruff: noqa: FBT001, FBT002
|
|
16
|
+
# others
|
|
17
|
+
# ruff: noqa: B006 DTZ007 E501 PLW0602 SIM102 SIM105
|
|
18
|
+
|
|
19
|
+
# docsig: disable=SIG501
|
|
20
|
+
|
|
21
|
+
# fmt: off
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
from typing import Any, Callable, Optional, Union
|
|
26
|
+
|
|
27
|
+
import sys
|
|
28
|
+
import os
|
|
29
|
+
import configparser
|
|
30
|
+
import logging
|
|
31
|
+
import tempfile
|
|
32
|
+
|
|
33
|
+
from functools import wraps
|
|
34
|
+
|
|
35
|
+
import threading
|
|
36
|
+
from contextlib import contextmanager
|
|
37
|
+
|
|
38
|
+
import locale
|
|
39
|
+
import datetime
|
|
40
|
+
import calendar
|
|
41
|
+
import dateutil.parser
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
# threadsafe access to locale setting
|
|
46
|
+
# https://stackoverflow.com/questions/18593661/how-do-i-strftime-a-date-object-in-a-different-locale
|
|
47
|
+
LOCALE_LOCK = threading.Lock()
|
|
48
|
+
|
|
49
|
+
# switch locale threadsafe
|
|
50
|
+
@contextmanager
|
|
51
|
+
def setlocale(locale_value: str):
|
|
52
|
+
"""
|
|
53
|
+
setlocale - switch locale threadsafe
|
|
54
|
+
|
|
55
|
+
Args:
|
|
56
|
+
locale_value (str): target locale
|
|
57
|
+
"""
|
|
58
|
+
|
|
59
|
+
with LOCALE_LOCK:
|
|
60
|
+
saved_locale_value = locale.setlocale(locale.LC_ALL)
|
|
61
|
+
try:
|
|
62
|
+
yield locale.setlocale(locale.LC_ALL, locale_value)
|
|
63
|
+
finally:
|
|
64
|
+
locale.setlocale(locale.LC_ALL, saved_locale_value)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
# find true application directory for frozen/bundled execution
|
|
69
|
+
# https://pyinstaller.readthedocs.io/en/stable/runtime-information.html#
|
|
70
|
+
# https://stackoverflow.com/questions/404744/determining-application-path-in-a-python-exe-generated-by-pyinstaller/48817163#48817163
|
|
71
|
+
def get_real_apppath() -> tuple[str, str]:
|
|
72
|
+
"""
|
|
73
|
+
get_real_apppath - find true application directory for frozen/bundled execution
|
|
74
|
+
|
|
75
|
+
Returns:
|
|
76
|
+
str: application path
|
|
77
|
+
"""
|
|
78
|
+
|
|
79
|
+
if getattr(sys, 'frozen', False):
|
|
80
|
+
application_path = os.path.dirname(sys.executable)
|
|
81
|
+
running_mode = 'Frozen/executable'
|
|
82
|
+
else:
|
|
83
|
+
try:
|
|
84
|
+
app_full_path = os.path.realpath(__file__)
|
|
85
|
+
application_path = os.path.dirname(app_full_path)
|
|
86
|
+
running_mode = "Non-interactive (e.g. 'python myapp.py')"
|
|
87
|
+
except NameError:
|
|
88
|
+
application_path = os.getcwd()
|
|
89
|
+
running_mode = 'Interactive'
|
|
90
|
+
|
|
91
|
+
return application_path, running_mode
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
# read config file with standardized boolean states into ConfigParser object
|
|
96
|
+
def readconfigfile(
|
|
97
|
+
configfile: str,
|
|
98
|
+
optionxform: Optional[Callable] = None,
|
|
99
|
+
encoding: str = "utf-8"
|
|
100
|
+
) -> configparser.ConfigParser:
|
|
101
|
+
"""
|
|
102
|
+
readconfigfile - read config file with standardized boolean states into ConfigParser object
|
|
103
|
+
|
|
104
|
+
Args:
|
|
105
|
+
configfile (str): config file
|
|
106
|
+
optionxform (callable, optional): callable to pass on to ConfigParser.optionxform. Defaults to None.
|
|
107
|
+
encoding (str, optional): file encoding. Defaults to "utf-8".
|
|
108
|
+
|
|
109
|
+
Raises:
|
|
110
|
+
Exception: file 'configfile' does not exist.
|
|
111
|
+
|
|
112
|
+
Returns:
|
|
113
|
+
configparser.ConfigParser: config parser object
|
|
114
|
+
"""
|
|
115
|
+
|
|
116
|
+
# no path provided as part of name of configfile, only filename -> use execution directory as default
|
|
117
|
+
if configfile == os.path.basename(configfile):
|
|
118
|
+
configfile = os.path.join(os.path.dirname(os.path.abspath(sys.argv[0])), configfile)
|
|
119
|
+
|
|
120
|
+
if not os.path.isfile(configfile):
|
|
121
|
+
err_msg = f"Error reading ini file '{configfile}'. File does not exist"
|
|
122
|
+
raise Exception(err_msg)
|
|
123
|
+
|
|
124
|
+
config = configparser.ConfigParser(interpolation=configparser.ExtendedInterpolation())
|
|
125
|
+
if optionxform is not None:
|
|
126
|
+
config.optionxform = optionxform # type: ignore
|
|
127
|
+
config.BOOLEAN_STATES = { # type: ignore
|
|
128
|
+
"1": True, "True": True, "true": True, "Yes": True, "yes": True,
|
|
129
|
+
"0": False, "False": False, "false": False, "No": False, "no": False
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
config.read(configfile, encoding=encoding)
|
|
133
|
+
|
|
134
|
+
return config
|
|
135
|
+
|
|
136
|
+
def read_configfile(
|
|
137
|
+
configfile: str,
|
|
138
|
+
optionxform: Optional[Callable] = None,
|
|
139
|
+
encoding: str = "utf-8"
|
|
140
|
+
) -> configparser.ConfigParser:
|
|
141
|
+
"""
|
|
142
|
+
read_configfile - read config file with standardized boolean states into ConfigParser object
|
|
143
|
+
|
|
144
|
+
Args:
|
|
145
|
+
configfile (str): config file
|
|
146
|
+
optionxform (callable, optional): callable to pass on to ConfigParser.optionxform. Defaults to None.
|
|
147
|
+
encoding (str, optional): file encoding. Defaults to "utf-8".
|
|
148
|
+
|
|
149
|
+
Raises:
|
|
150
|
+
Exception: file 'configfile' does not exist.
|
|
151
|
+
|
|
152
|
+
Returns:
|
|
153
|
+
configparser.ConfigParser: config parser object
|
|
154
|
+
"""
|
|
155
|
+
return readconfigfile(configfile, optionxform, encoding)
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
# logging
|
|
159
|
+
|
|
160
|
+
loggers: dict[str, logging.Logger] = {}
|
|
161
|
+
|
|
162
|
+
# set up logger including logic to avoid double assignment
|
|
163
|
+
# https://stackoverflow.com/questions/7173033/duplicate-log-output-when-using-python-logging-module
|
|
164
|
+
def initLogger(
|
|
165
|
+
loggername: str,
|
|
166
|
+
formatstr: str = "%(asctime)s\t%(levelname)s\t%(message)s",
|
|
167
|
+
datefmtstr: str = "%d.%m.%Y %H:%M:%S",
|
|
168
|
+
filename: str = ""
|
|
169
|
+
) -> logging.Logger:
|
|
170
|
+
"""
|
|
171
|
+
initLogger - initialize standard logger object
|
|
172
|
+
|
|
173
|
+
Args:
|
|
174
|
+
loggername (str): name of logger
|
|
175
|
+
formatstr (str, optional): format string for log entries. Defaults to "%(asctime)s\t%(levelname)s\t%(message)s".
|
|
176
|
+
datefmtstr (str, optional): date format for log entries. Defaults to "%d.%m.%Y %H:%M:%S".
|
|
177
|
+
filename (str, optional): name of log file. Defaults to "".
|
|
178
|
+
|
|
179
|
+
Returns:
|
|
180
|
+
logging.Logger: logger object
|
|
181
|
+
"""
|
|
182
|
+
|
|
183
|
+
global loggers
|
|
184
|
+
|
|
185
|
+
if loggers.get(loggername):
|
|
186
|
+
logger = loggers.get(loggername)
|
|
187
|
+
else:
|
|
188
|
+
logger = logging.getLogger(loggername)
|
|
189
|
+
logformatter = logging.Formatter(formatstr, datefmt=datefmtstr)
|
|
190
|
+
if filename == "":
|
|
191
|
+
loghandler = logging.FileHandler(os.path.join(tempfile.gettempdir(), loggername + "_Py.txt"))
|
|
192
|
+
else:
|
|
193
|
+
loghandler = logging.FileHandler(filename)
|
|
194
|
+
loghandler.setFormatter(logformatter)
|
|
195
|
+
loghandler.setLevel(logging.INFO)
|
|
196
|
+
logger.addHandler(loghandler)
|
|
197
|
+
logger.setLevel(logging.INFO)
|
|
198
|
+
loggers[loggername] = logger
|
|
199
|
+
|
|
200
|
+
return logger # type: ignore
|
|
201
|
+
|
|
202
|
+
def init_logger(
|
|
203
|
+
loggername: str,
|
|
204
|
+
formatstr: str = "%(asctime)s\t%(levelname)s\t%(message)s",
|
|
205
|
+
datefmtstr: str = "%d.%m.%Y %H:%M:%S",
|
|
206
|
+
filename: str = ""
|
|
207
|
+
) -> logging.Logger:
|
|
208
|
+
"""
|
|
209
|
+
init_logger - initialize standard logger object
|
|
210
|
+
|
|
211
|
+
Args:
|
|
212
|
+
loggername (str): name of logger
|
|
213
|
+
formatstr (str, optional): format string for log entries. Defaults to "%(asctime)s\t%(levelname)s\t%(message)s".
|
|
214
|
+
datefmtstr (str, optional): date format for log entries. Defaults to "%d.%m.%Y %H:%M:%S".
|
|
215
|
+
filename (str, optional): name of log file. Defaults to "".
|
|
216
|
+
|
|
217
|
+
Returns:
|
|
218
|
+
logging.Logger: logger object
|
|
219
|
+
"""
|
|
220
|
+
return initLogger(loggername, formatstr, datefmtstr, filename)
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
# set loglevel from config file
|
|
224
|
+
def setLogLevel(logger: logging.Logger, config: configparser.ConfigParser, section: str, optionLogLevel: str) -> None:
|
|
225
|
+
"""
|
|
226
|
+
setLogLevel - set log level from configparser object
|
|
227
|
+
|
|
228
|
+
Args:
|
|
229
|
+
logger (logging.Logger): name of logger
|
|
230
|
+
config (configparser): configparser object
|
|
231
|
+
section (str): section in 'config'
|
|
232
|
+
optionLogLevel (str): option in 'config'
|
|
233
|
+
"""
|
|
234
|
+
|
|
235
|
+
if (logger is not None) and (config is not None):
|
|
236
|
+
loglevelnum = getattr(logging, config[section][optionLogLevel].upper(), None)
|
|
237
|
+
if isinstance(loglevelnum, int):
|
|
238
|
+
logger.setLevel(loglevelnum)
|
|
239
|
+
else:
|
|
240
|
+
logger.setLevel(logging.INFO)
|
|
241
|
+
|
|
242
|
+
def set_loglevel(logger: logging.Logger, config: configparser.ConfigParser, section: str, optionLogLevel: str) -> None:
|
|
243
|
+
"""
|
|
244
|
+
set_logLevel - set log level from cCallableonfigparser object
|
|
245
|
+
|
|
246
|
+
Args:
|
|
247
|
+
logger (logging.Logger): name of logger
|
|
248
|
+
config (configparser): configparser object
|
|
249
|
+
section (str): section in 'config'
|
|
250
|
+
optionLogLevel (str): option in 'config'
|
|
251
|
+
"""
|
|
252
|
+
setLogLevel(logger, config, section, optionLogLevel)
|
|
253
|
+
|
|
254
|
+
def set_loglevel_from_config(logger: logging.Logger, config: configparser.ConfigParser, section: str, optionLogLevel: str) -> None:
|
|
255
|
+
"""
|
|
256
|
+
set_loglevel_from_config - set log level from configparser object
|
|
257
|
+
|
|
258
|
+
Args:
|
|
259
|
+
logger (logging.Logger): name of logger
|
|
260
|
+
config (configparser): configparser object
|
|
261
|
+
section (str): section in 'config'
|
|
262
|
+
optionLogLevel (str): option in 'config'
|
|
263
|
+
"""
|
|
264
|
+
setLogLevel(logger, config, section, optionLogLevel)
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
# convert to bool - useful for evaluation of CLI parameters
|
|
269
|
+
def to_bool(value: Union[str, int, float, bool], truevalues: list[str] = ["true", "yes", "x", "1", "-1"]) -> bool:
|
|
270
|
+
"""
|
|
271
|
+
to_bool - convert basic scalar types to bool
|
|
272
|
+
|
|
273
|
+
Args:
|
|
274
|
+
value (Union[str, int, float, bool]): value to be checked
|
|
275
|
+
truevalues (list[str], optional): truthy str values. Defaults to ["true", "yes", "x", "1", "-1"].
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
Returns:
|
|
279
|
+
bool: truthiness of value
|
|
280
|
+
"""
|
|
281
|
+
|
|
282
|
+
if type(value) is bool:
|
|
283
|
+
return value
|
|
284
|
+
elif type(value) in {int, float}:
|
|
285
|
+
return value != 0
|
|
286
|
+
else:
|
|
287
|
+
return value.lower() in truevalues # type: ignore
|
|
288
|
+
|
|
289
|
+
def to_boolean(value: Union[str, int, float, bool], truevalues: list[str] = ["true", "yes", "x", "1", "-1"]) -> bool:
|
|
290
|
+
"""
|
|
291
|
+
to_boolean - convert basic scalar types to bool
|
|
292
|
+
|
|
293
|
+
Args:
|
|
294
|
+
value (Union[str, int, float, bool]): value to be checked
|
|
295
|
+
truevalues (list[str], optional): truthy str values. Defaults to ["true", "yes", "x", "1", "-1"].
|
|
296
|
+
|
|
297
|
+
Returns:
|
|
298
|
+
bool: truthiness of value
|
|
299
|
+
"""
|
|
300
|
+
|
|
301
|
+
return to_bool(value, truevalues)
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
# create localized parserinfo object for dateutil.parser
|
|
305
|
+
# inspired by https://stackoverflow.com/questions/19927654/using-dateutil-parser-to-parse-a-date-in-another-language/62581811#62581811
|
|
306
|
+
class parserinfo_localized(dateutil.parser.parserinfo):
|
|
307
|
+
"""
|
|
308
|
+
parserinfo_localized - create localized date parser object
|
|
309
|
+
"""
|
|
310
|
+
|
|
311
|
+
def __init__(self, locale: str, *args, **kwargs):
|
|
312
|
+
""" initialize parserinfo localized """
|
|
313
|
+
|
|
314
|
+
with setlocale(locale):
|
|
315
|
+
self.WEEKDAYS = zip(calendar.day_abbr, calendar.day_name) # type: ignore[assignment]
|
|
316
|
+
self.MONTHS = list(zip(calendar.month_abbr, calendar.month_name))[1:] # type: ignore[assignment]
|
|
317
|
+
super().__init__(*args, **kwargs)
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
# check date value
|
|
321
|
+
def isdate(checkvalue: Any, checkformat="%d.%m.%Y") -> bool:
|
|
322
|
+
"""
|
|
323
|
+
isdate - check if checkvalue is a date value
|
|
324
|
+
|
|
325
|
+
Args:
|
|
326
|
+
checkvalue (Any): value to be checked
|
|
327
|
+
checkformat (str, optional): dateformat for check of checkvalue of type str. Defaults to "%d.%m.%Y".
|
|
328
|
+
|
|
329
|
+
Returns:
|
|
330
|
+
bool: checkvalue is date or not
|
|
331
|
+
"""
|
|
332
|
+
|
|
333
|
+
if checkvalue is None or checkvalue == "":
|
|
334
|
+
return False
|
|
335
|
+
elif type(checkvalue).__name__ == "datetime" or type(checkvalue).__name__ == "date":
|
|
336
|
+
return True
|
|
337
|
+
elif isinstance(checkvalue, str):
|
|
338
|
+
try:
|
|
339
|
+
check = bool(datetime.datetime.strptime(checkvalue, checkformat))
|
|
340
|
+
except ValueError:
|
|
341
|
+
check = False
|
|
342
|
+
return check
|
|
343
|
+
else:
|
|
344
|
+
return False
|
|
345
|
+
|
|
346
|
+
def is_date(checkvalue: Any, checkformat="%d.%m.%Y") -> bool:
|
|
347
|
+
"""
|
|
348
|
+
is_date - check if checkvalue is a date value
|
|
349
|
+
|
|
350
|
+
Args:
|
|
351
|
+
checkvalue (Any): value to be checked
|
|
352
|
+
checkformat (str, optional): dateformat for check of checkvalue of type str. Defaults to "%d.%m.%Y".
|
|
353
|
+
|
|
354
|
+
Returns:
|
|
355
|
+
bool: checkvalue is date or not
|
|
356
|
+
"""
|
|
357
|
+
return isdate(checkvalue, checkformat)
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
# copy fields from dict to target structure, can be used to copy same named fields to a data class from
|
|
362
|
+
# - TypedArgParser via <TypedArgParser object>.as_dict()
|
|
363
|
+
# - one dataclass to another via <dataclass>.asdict()
|
|
364
|
+
def copydictfields(source: dict, target: Any) -> None:
|
|
365
|
+
"""
|
|
366
|
+
copydictfields - copy fields from dict to target structure
|
|
367
|
+
|
|
368
|
+
can be used to copy same named fields to a data class from TypedArgParser via <TypedArgParser object>.as_dict() or
|
|
369
|
+
one dataclass to another via <dataclass>.asdict()
|
|
370
|
+
|
|
371
|
+
Args:
|
|
372
|
+
source (dict): source dictionary
|
|
373
|
+
target (Any): target dictionary
|
|
374
|
+
"""
|
|
375
|
+
|
|
376
|
+
for key, value in source.items():
|
|
377
|
+
if hasattr(target, key):
|
|
378
|
+
target.key = value
|
|
379
|
+
elif isinstance(target, dict):
|
|
380
|
+
if key in target:
|
|
381
|
+
target[key] = value
|
|
382
|
+
|
|
383
|
+
def copy_dictfields(source: dict, target: Any) -> None:
|
|
384
|
+
"""
|
|
385
|
+
copy_dict_fields - copy fields from dict to target structure
|
|
386
|
+
|
|
387
|
+
can be used to copy same named fields to a data class from TypedArgParser via <TypedArgParser object>.as_dict() or
|
|
388
|
+
one dataclass to another via <dataclass>.asdict()
|
|
389
|
+
|
|
390
|
+
Args:
|
|
391
|
+
source (dict): source dictionary
|
|
392
|
+
target (Any): target dictionary
|
|
393
|
+
"""
|
|
394
|
+
copy_dictfields(source, target)
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
|
|
398
|
+
# decorator for ignoring exceptions
|
|
399
|
+
# https://stackoverflow.com/questions/5929107/decorators-with-parameters
|
|
400
|
+
# https://lemonfold.io/posts/2022/dbc/typed_decorator/
|
|
401
|
+
|
|
402
|
+
|
|
403
|
+
# parameterized decorator
|
|
404
|
+
# - definition of ignored exceptions in decorator parameter using closure
|
|
405
|
+
# - no change of signature of decorated function
|
|
406
|
+
def ignore_exceptions_parameterized(ignored_exceptions: tuple[BaseException]):
|
|
407
|
+
"""
|
|
408
|
+
ignore_exceptions_parameterized - parameterized decorator for ignoring exceptions using closure
|
|
409
|
+
|
|
410
|
+
Args:
|
|
411
|
+
ignored_exceptions (tuple[BaseException]): exceptions to be ignored
|
|
412
|
+
|
|
413
|
+
Returns:
|
|
414
|
+
Callable: wrapped function
|
|
415
|
+
"""
|
|
416
|
+
def ignore_exceptions_helper(func):
|
|
417
|
+
|
|
418
|
+
@wraps(func)
|
|
419
|
+
def wrapper(*args, **kwargs):
|
|
420
|
+
result = None
|
|
421
|
+
if ignored_exceptions:
|
|
422
|
+
try:
|
|
423
|
+
result = func(*args, **kwargs)
|
|
424
|
+
except ignored_exceptions:
|
|
425
|
+
pass
|
|
426
|
+
else:
|
|
427
|
+
result = func(*args, **kwargs)
|
|
428
|
+
return result
|
|
429
|
+
|
|
430
|
+
return wrapper
|
|
431
|
+
|
|
432
|
+
return ignore_exceptions_helper
|
|
433
|
+
|
|
434
|
+
# non-parameterized decorator
|
|
435
|
+
# - definition of ignored exceptions via parameter of decorated function
|
|
436
|
+
# - change of signature of decorated function, dependency between decorator and decorated function
|
|
437
|
+
def ignore_exceptions(func):
|
|
438
|
+
"""
|
|
439
|
+
ignore_exceptions - decorator for ignoring exceptions using parameter in decorated function
|
|
440
|
+
|
|
441
|
+
Args:
|
|
442
|
+
func (Callable): function to be decorated
|
|
443
|
+
|
|
444
|
+
Returns:
|
|
445
|
+
Callable: wrapped function
|
|
446
|
+
"""
|
|
447
|
+
|
|
448
|
+
@wraps(func)
|
|
449
|
+
def wrapper(*args, **kwargs):
|
|
450
|
+
result = None
|
|
451
|
+
ignored_exceptions = kwargs.get('ignored_exceptions')
|
|
452
|
+
if ignored_exceptions:
|
|
453
|
+
try:
|
|
454
|
+
result = func(*args, **kwargs)
|
|
455
|
+
except ignored_exceptions:
|
|
456
|
+
pass
|
|
457
|
+
else:
|
|
458
|
+
result = func(*args, **kwargs)
|
|
459
|
+
return result
|
|
460
|
+
|
|
461
|
+
return wrapper
|
utils_mystuff/version.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"""Compute the version number and store it in the `__version__` variable.
|
|
2
|
+
|
|
3
|
+
Based on <https://github.com/maresb/hatch-vcs-footgun-example>.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
# ruff and mypy per file settings
|
|
8
|
+
# others
|
|
9
|
+
# ruff: noqa: PLC0415
|
|
10
|
+
|
|
11
|
+
# fmt: off
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def _get_hatch_version():
|
|
15
|
+
"""Compute the most up-to-date version number in a development environment.
|
|
16
|
+
|
|
17
|
+
Returns `None` if Hatchling is not installed, e.g. in a production environment.
|
|
18
|
+
|
|
19
|
+
For more details, see <https://github.com/maresb/hatch-vcs-footgun-example/>.
|
|
20
|
+
"""
|
|
21
|
+
import os
|
|
22
|
+
|
|
23
|
+
try:
|
|
24
|
+
from hatchling.metadata.core import ProjectMetadata
|
|
25
|
+
from hatchling.plugin.manager import PluginManager
|
|
26
|
+
from hatchling.utils.fs import locate_file
|
|
27
|
+
except ImportError:
|
|
28
|
+
# Hatchling is not installed, so probably we are not in a development environment.
|
|
29
|
+
return None
|
|
30
|
+
|
|
31
|
+
pyproject_toml = locate_file(__file__, "pyproject.toml")
|
|
32
|
+
if pyproject_toml is None:
|
|
33
|
+
err_msg = "pyproject.toml not found although hatchling is installed"
|
|
34
|
+
raise RuntimeError(err_msg)
|
|
35
|
+
root = os.path.dirname(pyproject_toml)
|
|
36
|
+
metadata = ProjectMetadata(root=root, plugin_manager=PluginManager())
|
|
37
|
+
# Version can be either statically set in pyproject.toml or computed dynamically:
|
|
38
|
+
return metadata.core.version or metadata.hatch.version.cached
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _get_importlib_metadata_version():
|
|
42
|
+
"""Compute the version number using importlib.metadata.
|
|
43
|
+
|
|
44
|
+
This is the official Pythonic way to get the version number of an installed
|
|
45
|
+
package. However, it is only updated when a package is installed. Thus, if a
|
|
46
|
+
package is installed in editable mode, and a different version is checked out,
|
|
47
|
+
then the version number will not be updated.
|
|
48
|
+
"""
|
|
49
|
+
from importlib.metadata import version
|
|
50
|
+
|
|
51
|
+
__version__ = version(__package__)
|
|
52
|
+
return __version__
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
__version__ = _get_hatch_version() or _get_importlib_metadata_version()
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: utils-mystuff
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Package with various utilities i.e. VB regex translation, CLI logging, file handling, basic GUI wrapper ...
|
|
5
|
+
Project-URL: Documentation, https://dornech.github.io/utils-mystuff
|
|
6
|
+
Project-URL: Source, https://github.com/dornech/utils-mystuff
|
|
7
|
+
Project-URL: Tracker, https://github.com/dornech/utils-mystuff/issues
|
|
8
|
+
Project-URL: Sponsor, https://github.com/sponsors/dornech
|
|
9
|
+
Author-email: dornech <dornech@gmx.de>
|
|
10
|
+
License: GPL-3.0-only
|
|
11
|
+
License-File: AUTHORS.md
|
|
12
|
+
License-File: LICENSE.txt
|
|
13
|
+
Keywords: CLI logging,GUI wrapper,RegEx conversion,command line interface,file handling,logging,regular expression
|
|
14
|
+
Classifier: Programming Language :: Python
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
21
|
+
Requires-Python: >=3.9
|
|
22
|
+
Requires-Dist: easygui
|
|
23
|
+
Requires-Dist: freesimplegui
|
|
24
|
+
Requires-Dist: pymsgbox
|
|
25
|
+
Requires-Dist: python-dateutil
|
|
26
|
+
Requires-Dist: pytz
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
|
|
29
|
+
# Personal utilities package for Python
|
|
30
|
+
|
|
31
|
+
Package with various utilities i.e. VB regex translation, CLI logging, file handling, basic GUI wrapper ...
|
|
32
|
+
|
|
33
|
+
## Features
|
|
34
|
+
|
|
35
|
+
Set of submodules contains:
|
|
36
|
+
|
|
37
|
+
- submodule for converting Microsoft VB /COM type regular expression to Python regular expression
|
|
38
|
+
- submodule with utilities to log CLI calls of Python scripts
|
|
39
|
+
- submodule with utilities for file handling
|
|
40
|
+
- submodule with wrapper for basic GUI functions for various GUI frameworks
|
|
41
|
+
- submodule with various utilities - read config file with standard parser, set up standard logger object ...
|
|
42
|
+
|
|
43
|
+
Note: as I am coming from camel case notation I was struggling a little bit with the Python naming conventions.
|
|
44
|
+
However, for publishing I tried to increase compliance with Python naming conventions and added snake case
|
|
45
|
+
method stubs (at least for most important subroutines) as a compromise.
|
|
46
|
+
|
|
47
|
+
## Development
|
|
48
|
+
|
|
49
|
+
To set up [hatch] and [pre-commit] for the first time:
|
|
50
|
+
|
|
51
|
+
1. install [hatch] globally, e.g. with [pipx], i.e. `pipx install hatch`,
|
|
52
|
+
2. make sure `pre-commit` is installed globally, e.g. with `pipx install pre-commit`.
|
|
53
|
+
|
|
54
|
+
A special feature that makes hatch very different from other familiar tools is that you almost never
|
|
55
|
+
activate, or enter, an environment. Instead, you use `hatch run env_name:command` and the `default` environment
|
|
56
|
+
is assumed for a command if there is no colon found. Thus you must always define your environment in a declarative
|
|
57
|
+
way and hatch makes sure that the environment reflects your declaration by updating it whenever you issue
|
|
58
|
+
a `hatch run ...`. This helps with reproducability and avoids forgetting to specify dependencies since the
|
|
59
|
+
hatch workflow is to specify everything directly in [pyproject.toml](pyproject.toml). Only in rare cases, you
|
|
60
|
+
will use `hatch shell` to enter the `default` environment, which is similar to what you may know from other tools.
|
|
61
|
+
|
|
62
|
+
To get you started, use `hatch run test:cov` or `hatch run test:no-cov` to run the unitest with or without coverage reports,
|
|
63
|
+
respectively. Use `hatch run lint:all` to run all kinds of typing and linting checks. Try to automatically fix linting
|
|
64
|
+
problems with `hatch run lint:fix` and use `hatch run docs:serve` to build and serve your documentation.
|
|
65
|
+
You can also easily define your own environments and commands. Check out the environment setup of hatch
|
|
66
|
+
in [pyproject.toml](pyproject.toml) for more commands as well as the package, build and tool configuration.
|
|
67
|
+
|
|
68
|
+
To support versioning and changelog generation please refer to the toolchain selected during package
|
|
69
|
+
generation (see also `pyproject.toml`). If not deselected, the toolchain includes a [pre-commit] hook
|
|
70
|
+
for linting commit messages to ensure commit messages are compliant with the conventional commit format and
|
|
71
|
+
support an automated changelog generation.
|
|
72
|
+
|
|
73
|
+
## Credits
|
|
74
|
+
|
|
75
|
+
This package was created with [The Hatchlor Enhanced] project template. This template is based on [The Hatchlor]
|
|
76
|
+
but was substantially improved.
|
|
77
|
+
|
|
78
|
+
[The Hatchlor Enhanced]: https://github.com/dornech/the-hatchlor-enhanced
|
|
79
|
+
[The Hatchlor]: https://github.com/florianwilhelm/the-hatchlor
|
|
80
|
+
[pipx]: https://pypa.github.io/pipx/
|
|
81
|
+
[hatch]: https://hatch.pypa.io/
|
|
82
|
+
[pre-commit]: https://pre-commit.com/
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
utils_mystuff/__init__.py,sha256=k6WT6QQXR6QMYoKLUmBUx8Wi4z-75DQPxgNMZXZDOzk,1435
|
|
2
|
+
utils_mystuff/convert_regex.py,sha256=B49cxrZNZsKeSAuk2Xo6rDuOz1fatAb5eFossD-TXGM,9013
|
|
3
|
+
utils_mystuff/logger_CLI.py,sha256=LGpUwImluJTMN4ujI7Q8oSxtKMEg73uWFfEeNv_LVN0,6260
|
|
4
|
+
utils_mystuff/utils_GUI.py,sha256=fFU-TR1j5Gfo-xQkVWvWYicgEVMMYJ6xvy65r6k-Cug,14894
|
|
5
|
+
utils_mystuff/utils_filehandling.py,sha256=fvDDtFwr0ualusxESLUD5f5MF0cuhlsUkjY-DgBlTCg,6245
|
|
6
|
+
utils_mystuff/utils_various.py,sha256=4K4ZyaA_HUuw-eGnda3SpHMRooN37OEik3Kmq_3_6-0,14603
|
|
7
|
+
utils_mystuff/version.py,sha256=lALyRABJtfZHDW1KiyUImeIS5FyoyNJCjqlDmKGpMCw,1893
|
|
8
|
+
utils_mystuff-1.0.0.dist-info/METADATA,sha256=MCqwNmzeTIoPsvQZHEtpXw1HkNQNtqhG0FG8hW0y-u4,4415
|
|
9
|
+
utils_mystuff-1.0.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
10
|
+
utils_mystuff-1.0.0.dist-info/licenses/AUTHORS.md,sha256=hjIl3u05KlQzMtYDikuvIzEeFR2s3QcpW6xvF1DYq9o,56
|
|
11
|
+
utils_mystuff-1.0.0.dist-info/licenses/LICENSE.txt,sha256=UcU_ILnkzeYjEuYhmczvll-v5r-IRqQU_i7S-sptGtw,1616
|
|
12
|
+
utils_mystuff-1.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
GNU GENERAL PUBLIC LICENSE
|
|
2
|
+
Version 3, 29 June 2007
|
|
3
|
+
|
|
4
|
+
Package with various utilities i.e. VB regex translation, CLI logging, file handling, basic GUI wrapper ...
|
|
5
|
+
Copyright (C) 2024 dornech
|
|
6
|
+
|
|
7
|
+
This program is free software: you can redistribute it and/or modify
|
|
8
|
+
it under the terms of the GNU General Public License as published by
|
|
9
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
10
|
+
(at your option) any later version.
|
|
11
|
+
|
|
12
|
+
This program is distributed in the hope that it will be useful,
|
|
13
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15
|
+
GNU General Public License for more details.
|
|
16
|
+
|
|
17
|
+
You should have received a copy of the GNU General Public License
|
|
18
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
19
|
+
|
|
20
|
+
Also add information on how to contact you by electronic and paper mail.
|
|
21
|
+
|
|
22
|
+
You should also get your employer (if you work as a programmer) or school,
|
|
23
|
+
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
|
24
|
+
For more information on this, and how to apply and follow the GNU GPL, see
|
|
25
|
+
<http://www.gnu.org/licenses/>.
|
|
26
|
+
|
|
27
|
+
The GNU General Public License does not permit incorporating your program
|
|
28
|
+
into proprietary programs. If your program is a subroutine library, you
|
|
29
|
+
may consider it more useful to permit linking proprietary applications with
|
|
30
|
+
the library. If this is what you want to do, use the GNU Lesser General
|
|
31
|
+
Public License instead of this License. But first, please read
|
|
32
|
+
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|