lkj 0.1.36__tar.gz → 0.1.38__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.36
3
+ Version: 0.1.38
4
4
  Summary: A dump of homeless useful utils
5
5
  Home-page: https://github.com/thorwhalen/lkj
6
6
  Author: Thor Whalen
@@ -25,9 +25,38 @@ That is, modules are all self contained (so can easily be copy-paste-vendored
25
25
  Further, many functions will contain their own imports: Those functions can even be
26
26
  copy-paste-vendored by just copying the function body.
27
27
 
28
-
29
28
  # Examples of utils
30
29
 
30
+ ## Find and replace
31
+
32
+ `FindReplaceTool` is a general-purpose find-and-replace tool that can treat the input text as a continuous sequence of characters,
33
+ even if operations such as viewing context are performed line by line.
34
+
35
+ The basic usage is
36
+
37
+ ```python
38
+ FindReplaceTool("apple banana apple").find_and_print_matches(r'apple')
39
+ ```
40
+
41
+ Match 0 (around line 1):
42
+ apple banana apple
43
+ ^^^^^
44
+ ----------------------------------------
45
+ Match 1 (around line 1):
46
+ apple banana apple
47
+ ^^^^^
48
+ ----------------------------------------
49
+
50
+ ```python
51
+ FindReplaceTool("apple banana apple").find_and_replace(r'apple', "orange")
52
+ ```
53
+
54
+ 'orange banana orange'
55
+
56
+ [See more examples in documentation](https://i2mint.github.io/lkj/module_docs/lkj/strings.html#lkj.strings.FindReplaceTool)
57
+
58
+ [See here a example of how I used this to edit my CI yamls](https://github.com/i2mint/lkj/discussions/4#discussioncomment-12104547)
59
+
31
60
  ## loggers
32
61
 
33
62
  ### clog
@@ -14,9 +14,38 @@ That is, modules are all self contained (so can easily be copy-paste-vendored
14
14
  Further, many functions will contain their own imports: Those functions can even be
15
15
  copy-paste-vendored by just copying the function body.
16
16
 
17
-
18
17
  # Examples of utils
19
18
 
19
+ ## Find and replace
20
+
21
+ `FindReplaceTool` is a general-purpose find-and-replace tool that can treat the input text as a continuous sequence of characters,
22
+ even if operations such as viewing context are performed line by line.
23
+
24
+ The basic usage is
25
+
26
+ ```python
27
+ FindReplaceTool("apple banana apple").find_and_print_matches(r'apple')
28
+ ```
29
+
30
+ Match 0 (around line 1):
31
+ apple banana apple
32
+ ^^^^^
33
+ ----------------------------------------
34
+ Match 1 (around line 1):
35
+ apple banana apple
36
+ ^^^^^
37
+ ----------------------------------------
38
+
39
+ ```python
40
+ FindReplaceTool("apple banana apple").find_and_replace(r'apple', "orange")
41
+ ```
42
+
43
+ 'orange banana orange'
44
+
45
+ [See more examples in documentation](https://i2mint.github.io/lkj/module_docs/lkj/strings.html#lkj.strings.FindReplaceTool)
46
+
47
+ [See here a example of how I used this to edit my CI yamls](https://github.com/i2mint/lkj/discussions/4#discussioncomment-12104547)
48
+
20
49
  ## loggers
21
50
 
22
51
  ### clog
@@ -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.36
3
+ Version: 0.1.38
4
4
  Summary: A dump of homeless useful utils
5
5
  Home-page: https://github.com/thorwhalen/lkj
6
6
  Author: Thor Whalen
@@ -25,9 +25,38 @@ That is, modules are all self contained (so can easily be copy-paste-vendored
25
25
  Further, many functions will contain their own imports: Those functions can even be
26
26
  copy-paste-vendored by just copying the function body.
27
27
 
28
-
29
28
  # Examples of utils
30
29
 
30
+ ## Find and replace
31
+
32
+ `FindReplaceTool` is a general-purpose find-and-replace tool that can treat the input text as a continuous sequence of characters,
33
+ even if operations such as viewing context are performed line by line.
34
+
35
+ The basic usage is
36
+
37
+ ```python
38
+ FindReplaceTool("apple banana apple").find_and_print_matches(r'apple')
39
+ ```
40
+
41
+ Match 0 (around line 1):
42
+ apple banana apple
43
+ ^^^^^
44
+ ----------------------------------------
45
+ Match 1 (around line 1):
46
+ apple banana apple
47
+ ^^^^^
48
+ ----------------------------------------
49
+
50
+ ```python
51
+ FindReplaceTool("apple banana apple").find_and_replace(r'apple', "orange")
52
+ ```
53
+
54
+ 'orange banana orange'
55
+
56
+ [See more examples in documentation](https://i2mint.github.io/lkj/module_docs/lkj/strings.html#lkj.strings.FindReplaceTool)
57
+
58
+ [See here a example of how I used this to edit my CI yamls](https://github.com/i2mint/lkj/discussions/4#discussioncomment-12104547)
59
+
31
60
  ## loggers
32
61
 
33
62
  ### clog
@@ -1,6 +1,6 @@
1
1
  [metadata]
2
2
  name = lkj
3
- version = 0.1.36
3
+ version = 0.1.38
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