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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: lkj
3
- Version: 0.1.37
3
+ Version: 0.1.39
4
4
  Summary: A dump of homeless useful utils
5
5
  Home-page: https://github.com/thorwhalen/lkj
6
6
  Author: Thor Whalen
@@ -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)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: lkj
3
- Version: 0.1.37
3
+ Version: 0.1.39
4
4
  Summary: A dump of homeless useful utils
5
5
  Home-page: https://github.com/thorwhalen/lkj
6
6
  Author: Thor Whalen
@@ -1,6 +1,6 @@
1
1
  [metadata]
2
2
  name = lkj
3
- version = 0.1.37
3
+ version = 0.1.39
4
4
  url = https://github.com/thorwhalen/lkj
5
5
  platforms = any
6
6
  description_file = README.md
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