bluer-options 5.166.1__tar.gz → 5.170.1__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.

Potentially problematic release.


This version of bluer-options might be problematic. Click here for more details.

Files changed (81) hide show
  1. {bluer_options-5.166.1/bluer_options.egg-info → bluer_options-5.170.1}/PKG-INFO +1 -1
  2. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options/__init__.py +1 -1
  3. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options/string/functions.py +1 -1
  4. bluer_options-5.170.1/bluer_options/timing/__init__.py +4 -0
  5. bluer_options-5.170.1/bluer_options/timing/classes.py +117 -0
  6. bluer_options-5.170.1/bluer_options/timing/elapsed_timer.py +42 -0
  7. {bluer_options-5.166.1 → bluer_options-5.170.1/bluer_options.egg-info}/PKG-INFO +1 -1
  8. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options.egg-info/SOURCES.txt +4 -2
  9. {bluer_options-5.166.1 → bluer_options-5.170.1}/setup.py +1 -0
  10. bluer_options-5.166.1/bluer_options/elapsed_timer.py +0 -23
  11. {bluer_options-5.166.1 → bluer_options-5.170.1}/LICENSE +0 -0
  12. {bluer_options-5.166.1 → bluer_options-5.170.1}/MANIFEST.in +0 -0
  13. {bluer_options-5.166.1 → bluer_options-5.170.1}/README.md +0 -0
  14. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options/.bash/alias.sh +0 -0
  15. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options/.bash/assert.sh +0 -0
  16. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options/.bash/bluer_options.sh +0 -0
  17. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options/.bash/bool.sh +0 -0
  18. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options/.bash/browse.sh +0 -0
  19. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options/.bash/code.sh +0 -0
  20. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options/.bash/env/backup.sh +0 -0
  21. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options/.bash/env/dot/cat.sh +0 -0
  22. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options/.bash/env/dot/cp.sh +0 -0
  23. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options/.bash/env/dot/edit.sh +0 -0
  24. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options/.bash/env/dot/load.sh +0 -0
  25. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options/.bash/env/dot/seed.sh +0 -0
  26. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options/.bash/env/dot.sh +0 -0
  27. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options/.bash/env.sh +0 -0
  28. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options/.bash/eval.sh +0 -0
  29. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options/.bash/generic_task.sh +0 -0
  30. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options/.bash/help.sh +0 -0
  31. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options/.bash/install.sh +0 -0
  32. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options/.bash/list.sh +0 -0
  33. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options/.bash/logging.sh +0 -0
  34. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options/.bash/open.sh +0 -0
  35. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options/.bash/options.sh +0 -0
  36. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options/.bash/pause.sh +0 -0
  37. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options/.bash/plugins.sh +0 -0
  38. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options/.bash/pylint.sh +0 -0
  39. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options/.bash/pytest.sh +0 -0
  40. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options/.bash/repeat.sh +0 -0
  41. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options/.bash/seed.sh +0 -0
  42. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options/.bash/sleep.sh +0 -0
  43. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options/.bash/source.sh +0 -0
  44. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options/.bash/string.sh +0 -0
  45. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options/.bash/terminal.sh +0 -0
  46. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options/.bash/test.sh +0 -0
  47. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options/.bash/wait.sh +0 -0
  48. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options/.bash/watch.sh +0 -0
  49. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options/__main__.py +0 -0
  50. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options/assets/example1.sh +0 -0
  51. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options/config.env +0 -0
  52. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options/env/__init__.py +0 -0
  53. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options/env/functions.py +0 -0
  54. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options/help/__init__.py +0 -0
  55. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options/help/__main__.py +0 -0
  56. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options/help/functions.py +0 -0
  57. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options/help/parsing.py +0 -0
  58. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options/host/__init__.py +0 -0
  59. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options/host/__main__.py +0 -0
  60. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options/host/functions.py +0 -0
  61. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options/list/__init__.py +0 -0
  62. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options/list/__main__.py +0 -0
  63. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options/logger/__init__.py +0 -0
  64. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options/logger/config.py +0 -0
  65. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options/options/__init__.py +0 -0
  66. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options/options/__main__.py +0 -0
  67. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options/options/classes.py +0 -0
  68. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options/string/__init__.py +0 -0
  69. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options/string/__main__.py +0 -0
  70. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options/string/constants.py +0 -0
  71. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options/terminal/__init__.py +0 -0
  72. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options/terminal/__main__.py +0 -0
  73. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options/terminal/functions.py +0 -0
  74. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options/timer.py +0 -0
  75. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options/urls.py +0 -0
  76. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options.egg-info/dependency_links.txt +0 -0
  77. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options.egg-info/requires.txt +0 -0
  78. {bluer_options-5.166.1 → bluer_options-5.170.1}/bluer_options.egg-info/top_level.txt +0 -0
  79. {bluer_options-5.166.1 → bluer_options-5.170.1}/pyproject.toml +0 -0
  80. {bluer_options-5.166.1 → bluer_options-5.170.1}/requirements.txt +0 -0
  81. {bluer_options-5.166.1 → bluer_options-5.170.1}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: bluer_options
3
- Version: 5.166.1
3
+ Version: 5.170.1
4
4
  Summary: 🌀 Options for Bash.
5
5
  Home-page: https://github.com/kamangir/bluer-options
6
6
  Author: Arash Abadpour (Kamangir)
@@ -6,7 +6,7 @@ ICON = "🌀"
6
6
 
7
7
  DESCRIPTION = f"{ICON} Options for Bash."
8
8
 
9
- VERSION = "5.166.1"
9
+ VERSION = "5.170.1"
10
10
 
11
11
  REPO_NAME = "bluer-options"
12
12
 
@@ -221,7 +221,7 @@ def pretty_shape_of_matrix(
221
221
 
222
222
 
223
223
  def pretty_duration(
224
- duration: Union[None, int],
224
+ duration: Union[None, float],
225
225
  element_format: str = "{}{}",
226
226
  include_ms: bool = False,
227
227
  largest: bool = False,
@@ -0,0 +1,4 @@
1
+ from bluer_options.timing.elapsed_timer import ElapsedTimer
2
+ from bluer_options.timing.classes import Timing
3
+
4
+ timing = Timing()
@@ -0,0 +1,117 @@
1
+ import time
2
+ from typing import List
3
+ from collections import defaultdict
4
+ from functools import wraps
5
+
6
+ from bluer_options import string
7
+ from bluer_options.logger import logger
8
+ from bluer_options.logger.config import log_list
9
+ from bluer_options.timing.elapsed_timer import ElapsedTimer
10
+
11
+
12
+ class Timing:
13
+ def __init__(self):
14
+ self._active = {}
15
+ self.stats = defaultdict(lambda: {"count": 0, "total": 0.0})
16
+ self.elapsed_timer = ElapsedTimer()
17
+
18
+ def start(self, keyword: str):
19
+ """Start timing a code block identified by 'keyword'."""
20
+ self._active[keyword] = time.perf_counter()
21
+
22
+ def stop(self, keyword: str):
23
+ """Stop timing for 'keyword' and record elapsed time."""
24
+ if keyword not in self._active:
25
+ raise RuntimeError(f"No active timer for {keyword}")
26
+
27
+ elapsed = time.perf_counter() - self._active.pop(keyword)
28
+ self.stats[keyword]["count"] += 1
29
+ self.stats[keyword]["total"] += elapsed
30
+
31
+ return elapsed
32
+
33
+ def as_list(self, **kwgrs) -> List[str]:
34
+ lines = []
35
+ # sort items by total time (descending)
36
+ for k, v in sorted(
37
+ self.stats.items(),
38
+ key=lambda item: item[1]["total"],
39
+ reverse=True,
40
+ ):
41
+ avg = v["total"] / v["count"]
42
+ lines.append(
43
+ "{}: called {:,} time(s), total {}, avg {}".format(
44
+ k,
45
+ v["count"],
46
+ string.pretty_duration(v["total"], **kwgrs),
47
+ string.pretty_duration(avg, **kwgrs),
48
+ )
49
+ )
50
+ return lines
51
+
52
+ def log(
53
+ self,
54
+ include_ms: bool = True,
55
+ largest: bool = True,
56
+ short: bool = True,
57
+ **kwargs,
58
+ ):
59
+ log_list(
60
+ logger,
61
+ "took {} for".format(
62
+ self.elapsed_timer.as_str(
63
+ stop=False,
64
+ include_ms=include_ms,
65
+ largest=largest,
66
+ short=short,
67
+ )
68
+ ),
69
+ self.as_list(
70
+ include_ms=include_ms,
71
+ largest=largest,
72
+ short=short,
73
+ ),
74
+ "function call(s):",
75
+ **kwargs,
76
+ )
77
+
78
+ def reset(self):
79
+ self._active = {}
80
+ self.stats = defaultdict(lambda: {"count": 0, "total": 0.0})
81
+ self.elapsed_timer.reset()
82
+
83
+ def time(self, arg=None):
84
+ """Use as @timing.time, @timing.time(), or @timing.time('custom')"""
85
+
86
+ # Case 1: @timing.time (no parentheses, arg is the function)
87
+ if callable(arg):
88
+ func = arg
89
+ name = func.__name__
90
+
91
+ @wraps(func)
92
+ def inner(*args, **kwargs):
93
+ self.start(name)
94
+ try:
95
+ return func(*args, **kwargs)
96
+ finally:
97
+ self.stop(name)
98
+
99
+ return inner
100
+
101
+ # Case 2: @timing.time() or @timing.time("custom")
102
+ keyword = arg # may be None or str
103
+
104
+ def decorator(func):
105
+ name = keyword or func.__name__
106
+
107
+ @wraps(func)
108
+ def inner(*args, **kwargs):
109
+ self.start(name)
110
+ try:
111
+ return func(*args, **kwargs)
112
+ finally:
113
+ self.stop(name)
114
+
115
+ return inner
116
+
117
+ return decorator
@@ -0,0 +1,42 @@
1
+ import time
2
+ from bluer_options import string
3
+
4
+
5
+ class ElapsedTimer:
6
+ def __init__(self):
7
+ self.start_time = time.time()
8
+ self.elapsed_time_ = None
9
+
10
+ def as_str(
11
+ self,
12
+ stop: bool = True,
13
+ **kwargs,
14
+ ):
15
+ if stop:
16
+ self.stop()
17
+
18
+ elapsed_time = self.elapsed_time
19
+
20
+ return (
21
+ "None"
22
+ if elapsed_time is None
23
+ else string.pretty_duration(elapsed_time, **kwargs)
24
+ )
25
+
26
+ @property
27
+ def elapsed_time(self) -> float:
28
+ if self.start_time is None:
29
+ return self.elapsed_time_
30
+
31
+ return time.time() - self.start_time
32
+
33
+ def reset(self):
34
+ self.start_time = time.time()
35
+ self.elapsed_time_ = None
36
+
37
+ def stop(self):
38
+ if self.start_time is None:
39
+ return
40
+
41
+ self.elapsed_time_ = self.elapsed_time
42
+ self.start_time = None
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: bluer_options
3
- Version: 5.166.1
3
+ Version: 5.170.1
4
4
  Summary: 🌀 Options for Bash.
5
5
  Home-page: https://github.com/kamangir/bluer-options
6
6
  Author: Arash Abadpour (Kamangir)
@@ -7,7 +7,6 @@ setup.py
7
7
  bluer_options/__init__.py
8
8
  bluer_options/__main__.py
9
9
  bluer_options/config.env
10
- bluer_options/elapsed_timer.py
11
10
  bluer_options/timer.py
12
11
  bluer_options/urls.py
13
12
  bluer_options.egg-info/PKG-INFO
@@ -73,4 +72,7 @@ bluer_options/string/constants.py
73
72
  bluer_options/string/functions.py
74
73
  bluer_options/terminal/__init__.py
75
74
  bluer_options/terminal/__main__.py
76
- bluer_options/terminal/functions.py
75
+ bluer_options/terminal/functions.py
76
+ bluer_options/timing/__init__.py
77
+ bluer_options/timing/classes.py
78
+ bluer_options/timing/elapsed_timer.py
@@ -19,6 +19,7 @@ setup(
19
19
  f"{NAME}.options",
20
20
  f"{NAME}.string",
21
21
  f"{NAME}.terminal",
22
+ f"{NAME}.timing",
22
23
  ],
23
24
  include_package_data=True,
24
25
  package_data={
@@ -1,23 +0,0 @@
1
- import time
2
- from bluer_options import string
3
-
4
-
5
- class ElapsedTimer:
6
- def __init__(self):
7
- self.start_time = time.time()
8
- self.elapsed_time = None
9
-
10
- def stop(self):
11
- if self.start_time is None:
12
- return
13
-
14
- self.elapsed_time = time.time() - self.start_time
15
- self.start_time = None
16
-
17
- def elapsed_pretty(self, **kwargs):
18
- self.stop()
19
- return (
20
- "None"
21
- if self.elapsed_time is None
22
- else string.pretty_duration(self.elapsed_time, **kwargs)
23
- )
File without changes