lkj 0.1.37__tar.gz → 0.1.39__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.
- {lkj-0.1.37 → lkj-0.1.39}/PKG-INFO +1 -1
- {lkj-0.1.37 → lkj-0.1.39}/lkj/__init__.py +7 -6
- {lkj-0.1.37 → lkj-0.1.39}/lkj/loggers.py +31 -0
- {lkj-0.1.37 → lkj-0.1.39}/lkj.egg-info/PKG-INFO +1 -1
- {lkj-0.1.37 → lkj-0.1.39}/setup.cfg +1 -1
- {lkj-0.1.37 → lkj-0.1.39}/LICENSE +0 -0
- {lkj-0.1.37 → lkj-0.1.39}/README.md +0 -0
- {lkj-0.1.37 → lkj-0.1.39}/lkj/chunking.py +0 -0
- {lkj-0.1.37 → lkj-0.1.39}/lkj/dicts.py +0 -0
- {lkj-0.1.37 → lkj-0.1.39}/lkj/filesys.py +0 -0
- {lkj-0.1.37 → lkj-0.1.39}/lkj/funcs.py +0 -0
- {lkj-0.1.37 → lkj-0.1.39}/lkj/importing.py +0 -0
- {lkj-0.1.37 → lkj-0.1.39}/lkj/iterables.py +0 -0
- {lkj-0.1.37 → lkj-0.1.39}/lkj/misc.py +0 -0
- {lkj-0.1.37 → lkj-0.1.39}/lkj/strings.py +0 -0
- {lkj-0.1.37 → lkj-0.1.39}/lkj.egg-info/SOURCES.txt +0 -0
- {lkj-0.1.37 → lkj-0.1.39}/lkj.egg-info/dependency_links.txt +0 -0
- {lkj-0.1.37 → lkj-0.1.39}/lkj.egg-info/not-zip-safe +0 -0
- {lkj-0.1.37 → lkj-0.1.39}/lkj.egg-info/top_level.txt +0 -0
- {lkj-0.1.37 → lkj-0.1.39}/setup.py +0 -0
|
@@ -30,13 +30,14 @@ from lkj.strings import (
|
|
|
30
30
|
truncate_string_with_marker, # Deprecated: Backcompatibility alias
|
|
31
31
|
)
|
|
32
32
|
from lkj.loggers import (
|
|
33
|
-
print_with_timestamp,
|
|
34
|
-
print_progress,
|
|
35
|
-
log_calls,
|
|
36
|
-
clog,
|
|
33
|
+
print_with_timestamp, # Prints with a timestamp and optional refresh.
|
|
34
|
+
print_progress, # an alias often used for print_with_timestamp
|
|
35
|
+
log_calls, # Decorator that adds logging before and after the function's call.
|
|
36
|
+
clog, # Conditional logger
|
|
37
37
|
ErrorInfo,
|
|
38
|
-
return_error_info_on_error,
|
|
39
|
-
wrapped_print,
|
|
38
|
+
return_error_info_on_error, # Decorator that returns traceback and local variables on error.
|
|
39
|
+
wrapped_print, # Prints a string or list ensuring the total line width does not exceed `max_width`.
|
|
40
|
+
CallOnError, # Context manager that calls a function on error (subclass of suppress)
|
|
40
41
|
)
|
|
41
42
|
from lkj.importing import import_object, register_namespace_forwarding
|
|
42
43
|
from lkj.chunking import chunk_iterable, chunker
|
|
@@ -414,3 +414,34 @@ def return_error_info_on_error(
|
|
|
414
414
|
return error_info_processor(error_info)
|
|
415
415
|
|
|
416
416
|
return wrapper
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
from contextlib import suppress
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+
class CallOnError(suppress):
|
|
423
|
+
"""
|
|
424
|
+
An extension of the suppress context manager that enables the user to issue a warning
|
|
425
|
+
message when an import error occurs.
|
|
426
|
+
|
|
427
|
+
>>> warn_about_import_errors = CallOnError(ImportError, on_error=lambda err: print(f"Warning: {err}"))
|
|
428
|
+
>>> with warn_about_import_errors:
|
|
429
|
+
... import this_package_surely_does_not_exist
|
|
430
|
+
Warning: No module named 'this_package_surely_does_not_exist'
|
|
431
|
+
>>> with warn_about_import_errors:
|
|
432
|
+
... from os.this_module_does_not_exist import this_function_does_not_exist
|
|
433
|
+
Warning: No module named 'os.this_module_does_not_exist'; 'os' is not a package
|
|
434
|
+
"""
|
|
435
|
+
|
|
436
|
+
def __init__(
|
|
437
|
+
self,
|
|
438
|
+
*exceptions,
|
|
439
|
+
on_error: Callable = print,
|
|
440
|
+
):
|
|
441
|
+
self.on_error = on_error
|
|
442
|
+
super().__init__(*exceptions)
|
|
443
|
+
|
|
444
|
+
def __exit__(self, exctype, excinst, exctb):
|
|
445
|
+
if exctype is not None:
|
|
446
|
+
self.on_error(excinst)
|
|
447
|
+
return super().__exit__(exctype, excinst, exctb)
|
|
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
|