timer-for-python 0.9.6__py3-none-any.whl → 0.9.7__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.
- timer/conftest.py +0 -0
- timer/decorator/function.py +6 -2
- timer/error/__init__.py +3 -1
- timer/helper/decimals.py +8 -4
- timer/helper/output.py +3 -1
- timer/helper/thread/list.py +2 -1
- timer/helper/time_fractions.py +2 -1
- timer/model/timer.py +14 -6
- timer/model/timer_base.py +3 -1
- timer/version.py +1 -1
- {timer_for_python-0.9.6.dist-info → timer_for_python-0.9.7.dist-info}/METADATA +10 -33
- {timer_for_python-0.9.6.dist-info → timer_for_python-0.9.7.dist-info}/RECORD +14 -14
- {timer_for_python-0.9.6.dist-info → timer_for_python-0.9.7.dist-info}/WHEEL +1 -2
- timer_for_python-0.9.6.dist-info/top_level.txt +0 -1
- {timer_for_python-0.9.6.dist-info → timer_for_python-0.9.7.dist-info}/licenses/LICENSE.md +0 -0
timer/conftest.py
ADDED
|
File without changes
|
timer/decorator/function.py
CHANGED
|
@@ -9,10 +9,12 @@ from ..model.timer import Timer
|
|
|
9
9
|
def function_timer(thread: str | None = None, decimals: int = 2) -> Callable[..., Any]:
|
|
10
10
|
"""Function decorator to measure the performance of a function."""
|
|
11
11
|
|
|
12
|
-
def get_function_with_arguments_as_thread_name(
|
|
12
|
+
def get_function_with_arguments_as_thread_name(
|
|
13
|
+
function: Callable[..., Any], args: tuple[Any, ...], kwargs: dict[str, Any]
|
|
14
|
+
) -> str:
|
|
13
15
|
thread_name = function.__name__
|
|
14
16
|
if args or kwargs:
|
|
15
|
-
arg_names = function.__code__.co_varnames[:function.__code__.co_argcount]
|
|
17
|
+
arg_names = function.__code__.co_varnames[: function.__code__.co_argcount]
|
|
16
18
|
mapped_args = [f"{name}={value!r}" for name, value in zip(arg_names, args)]
|
|
17
19
|
mapped_kwargs = [f"{key}={value!r}" for key, value in kwargs.items()]
|
|
18
20
|
all_mapped_args = ", ".join(mapped_args + mapped_kwargs)
|
|
@@ -25,7 +27,9 @@ def function_timer(thread: str | None = None, decimals: int = 2) -> Callable[...
|
|
|
25
27
|
thread_name = thread if thread else get_function_with_arguments_as_thread_name(function, args, kwargs)
|
|
26
28
|
with Timer(thread=thread_name, decimals=decimals):
|
|
27
29
|
return function(*args, **kwargs)
|
|
30
|
+
|
|
28
31
|
return wrapper
|
|
32
|
+
|
|
29
33
|
return decorator
|
|
30
34
|
|
|
31
35
|
|
timer/error/__init__.py
CHANGED
|
@@ -24,4 +24,6 @@ def stop_controller(timer: TimerBase, thread: str | None) -> None:
|
|
|
24
24
|
|
|
25
25
|
|
|
26
26
|
def message_for_action(action: str, thread: str | None = None) -> None:
|
|
27
|
-
print(
|
|
27
|
+
print(
|
|
28
|
+
f"{Color.YELLOW}Timer: Something went wrong {action}{'' if helper.thread.is_none(thread) else f' for thread {thread}'}.{Color.OFF}"
|
|
29
|
+
)
|
timer/helper/decimals.py
CHANGED
|
@@ -13,21 +13,25 @@ def mediate(timer: TimerBase, decimals: int | None) -> int:
|
|
|
13
13
|
|
|
14
14
|
def validate_and_normalise(decimals: int | float | None) -> int:
|
|
15
15
|
try:
|
|
16
|
-
if not isinstance(decimals, (int
|
|
16
|
+
if not isinstance(decimals, (int | float)) or decimals is None:
|
|
17
17
|
print(f"{Color.YELLOW}Timer: Decimals set to default {DEFAULT} due to invalid input.{Color.OFF}")
|
|
18
18
|
return DEFAULT
|
|
19
19
|
elif decimals > MAXIMUM:
|
|
20
|
-
print(
|
|
20
|
+
print(
|
|
21
|
+
f"{Color.YELLOW}Timer: Decimals set to {MAXIMUM} as the Timer doesn't support more than {MAXIMUM} decimals (i.e. nanoseconds).{Color.OFF}"
|
|
22
|
+
)
|
|
21
23
|
return MAXIMUM
|
|
22
24
|
elif MINIMUM <= decimals <= MAXIMUM:
|
|
23
25
|
if decimals % 1 == 0:
|
|
24
26
|
return int(decimals)
|
|
25
27
|
decimals_rounded = int(round(decimals))
|
|
26
|
-
print(
|
|
28
|
+
print(
|
|
29
|
+
f"{Color.YELLOW}Timer: Decimals {decimals} set to {decimals_rounded} as a floating number is invalid input.{Color.OFF}"
|
|
30
|
+
)
|
|
27
31
|
return decimals_rounded
|
|
28
32
|
else:
|
|
29
33
|
print(f"{Color.YELLOW}Timer: Decimals set to default {DEFAULT} due to invalid input.{Color.OFF}")
|
|
30
34
|
return DEFAULT
|
|
31
35
|
except Exception:
|
|
32
|
-
error.message_for_action(f
|
|
36
|
+
error.message_for_action(f'when trying to verify the Timer\'s decimals input "{decimals}"')
|
|
33
37
|
return DEFAULT
|
timer/helper/output.py
CHANGED
|
@@ -17,7 +17,9 @@ def message(thread: str, fractions: TimeFractions, decimals: int) -> None:
|
|
|
17
17
|
print(f"{intro} {time.hours}h {time.minutes}m {fractions.seconds_rounded()}s{thread_info}")
|
|
18
18
|
elif time.minutes > 0:
|
|
19
19
|
# Format: 62.34 seconds (1m 2s)
|
|
20
|
-
print(
|
|
20
|
+
print(
|
|
21
|
+
f"{intro} {fractions.count_minutes_to_seconds():.{decimals}f} seconds ({time.minutes}m {fractions.seconds_rounded()}s){thread_info}"
|
|
22
|
+
)
|
|
21
23
|
elif time.seconds > 0:
|
|
22
24
|
# Format: 0.123456789 seconds
|
|
23
25
|
print(f"{intro} {fractions.count_seconds_to_float():.{decimals}f} seconds{thread_info}")
|
timer/helper/thread/list.py
CHANGED
|
@@ -31,4 +31,5 @@ def remove(timer: TimerBase, entry_index: int) -> None:
|
|
|
31
31
|
timer._threads.pop(entry_index)
|
|
32
32
|
except Exception:
|
|
33
33
|
error.message_for_action(
|
|
34
|
-
f
|
|
34
|
+
f'when trying to remove entry from the Timer\'s thread list for entry index "{entry_index}"'
|
|
35
|
+
)
|
timer/helper/time_fractions.py
CHANGED
timer/model/timer.py
CHANGED
|
@@ -9,9 +9,14 @@ from .timer_base import TimerBase
|
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
class Timer(TimerBase):
|
|
12
|
-
__slots__ = [
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
__slots__ = [
|
|
13
|
+
"_threads",
|
|
14
|
+
"_decimals",
|
|
15
|
+
"_context_manager_threads",
|
|
16
|
+
"_context_manager_latest_thread",
|
|
17
|
+
"_context_manager_latest_decimals",
|
|
18
|
+
"__dict__",
|
|
19
|
+
]
|
|
15
20
|
|
|
16
21
|
_instance = None
|
|
17
22
|
_lock_init = False
|
|
@@ -88,8 +93,9 @@ class Timer(TimerBase):
|
|
|
88
93
|
self._threads: list[ThreadItem] = []
|
|
89
94
|
self._context_manager_threads: list[str] = []
|
|
90
95
|
self._lock_init = True
|
|
91
|
-
self._decimals: int =
|
|
92
|
-
decimals)
|
|
96
|
+
self._decimals: int = (
|
|
97
|
+
decimals if decimals == constant.decimals.DEFAULT else helper.decimals.validate_and_normalise(decimals)
|
|
98
|
+
)
|
|
93
99
|
self._context_manager_latest_thread: str = helper.thread.normalise_to_string_and_uppercase(thread)
|
|
94
100
|
self._context_manager_latest_decimals: int = self._decimals
|
|
95
101
|
|
|
@@ -98,7 +104,9 @@ class Timer(TimerBase):
|
|
|
98
104
|
self.start(self._context_manager_latest_thread, self._context_manager_latest_decimals)
|
|
99
105
|
return self
|
|
100
106
|
|
|
101
|
-
def __exit__(
|
|
107
|
+
def __exit__(
|
|
108
|
+
self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None
|
|
109
|
+
) -> None:
|
|
102
110
|
last_context_manager_thread = self._context_manager_threads.pop()
|
|
103
111
|
self.stop(last_context_manager_thread)
|
|
104
112
|
|
timer/model/timer_base.py
CHANGED
|
@@ -16,7 +16,9 @@ class TimerBase(ABC):
|
|
|
16
16
|
def __enter__(self) -> "TimerBase":
|
|
17
17
|
raise NotImplementedError # pragma: no cover
|
|
18
18
|
|
|
19
|
-
def __exit__(
|
|
19
|
+
def __exit__(
|
|
20
|
+
self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None
|
|
21
|
+
) -> None:
|
|
20
22
|
raise NotImplementedError # pragma: no cover
|
|
21
23
|
|
|
22
24
|
@abstractmethod
|
timer/version.py
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
__version_info__ = (0, 9,
|
|
1
|
+
__version_info__ = (0, 9, 7)
|
|
2
2
|
__version__ = ".".join(map(str, __version_info__))
|
|
@@ -1,43 +1,30 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: timer-for-python
|
|
3
|
-
Version: 0.9.
|
|
3
|
+
Version: 0.9.7
|
|
4
4
|
Summary: Lightweight package that makes it easy to measure how much time it takes to run Python programs and gauge performance of multiple, smaller bits of code
|
|
5
|
-
Home-page: https://jakob-bagterp.github.io/timer-for-python/
|
|
6
|
-
Download-URL: https://pypi.org/project/timer-for-python/
|
|
7
|
-
Author: Jakob Bagterp
|
|
8
|
-
Author-email: jakob_bagterp@hotmail.com
|
|
9
|
-
Maintainer: Jakob Bagterp
|
|
10
|
-
Maintainer-email: jakob_bagterp@hotmail.com
|
|
11
|
-
License: MIT License
|
|
12
5
|
Project-URL: Bug Tracker, https://github.com/jakob-bagterp/timer-for-python/issues
|
|
13
6
|
Project-URL: Documentation, https://jakob-bagterp.github.io/timer-for-python/
|
|
14
7
|
Project-URL: API Reference, https://jakob-bagterp.github.io/timer-for-python/reference/
|
|
15
8
|
Project-URL: Source Code, https://github.com/jakob-bagterp/timer-for-python
|
|
16
9
|
Project-URL: Release Notes, https://github.com/jakob-bagterp/timer-for-python/releases
|
|
10
|
+
Author-email: Jakob Bagterp <jakob_bagterp@hotmail.com>
|
|
11
|
+
Maintainer-email: Jakob Bagterp <jakob_bagterp@hotmail.com>
|
|
12
|
+
License: MIT License
|
|
13
|
+
License-File: LICENSE.md
|
|
17
14
|
Keywords: python,timer
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
18
17
|
Classifier: Programming Language :: Python :: 3
|
|
19
18
|
Classifier: Programming Language :: Python :: 3.10
|
|
20
19
|
Classifier: Programming Language :: Python :: 3.11
|
|
21
20
|
Classifier: Programming Language :: Python :: 3.12
|
|
22
21
|
Classifier: Programming Language :: Python :: 3.13
|
|
23
22
|
Classifier: Programming Language :: Python :: 3.14
|
|
24
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
25
|
-
Classifier: Operating System :: OS Independent
|
|
26
23
|
Requires-Python: >=3.10
|
|
24
|
+
Requires-Dist: colorist==1.8.9
|
|
27
25
|
Description-Content-Type: text/markdown
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
Provides-Extra: testing
|
|
31
|
-
Requires-Dist: coverage==7.11.0; extra == "testing"
|
|
32
|
-
Requires-Dist: flake8==7.3.0; extra == "testing"
|
|
33
|
-
Requires-Dist: mypy==1.19.0; extra == "testing"
|
|
34
|
-
Requires-Dist: pytest==9.0.1; extra == "testing"
|
|
35
|
-
Requires-Dist: pytest-cov==7.0.0; extra == "testing"
|
|
36
|
-
Requires-Dist: tox==4.32.0; extra == "testing"
|
|
37
|
-
Dynamic: download-url
|
|
38
|
-
Dynamic: license-file
|
|
39
|
-
|
|
40
|
-
[](https://github.com/jakob-bagterp/timer-for-python/releases/latest)
|
|
26
|
+
|
|
27
|
+
[](https://github.com/jakob-bagterp/timer-for-python/releases/latest)
|
|
41
28
|
[](https://www.python.org)
|
|
42
29
|
[](https://github.com/jakob-bagterp/timer-for-python/blob/master/LICENSE.md)
|
|
43
30
|
[](https://codecov.io/gh/jakob-bagterp/timer-for-python)
|
|
@@ -152,13 +139,3 @@ If you have suggestions or changes to the module, feel free to add to the code a
|
|
|
152
139
|
|
|
153
140
|
## Report Bugs
|
|
154
141
|
If you encounter any issues, you can [report them as bugs or raise issues](https://github.com/jakob-bagterp/timer-for-python/issues).
|
|
155
|
-
|
|
156
|
-
# MIT License
|
|
157
|
-
|
|
158
|
-
Copyright (c) 2020 – present, Jakob Bagterp
|
|
159
|
-
|
|
160
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
161
|
-
|
|
162
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
163
|
-
|
|
164
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
timer/__init__.py,sha256=X7Z5wKwhKDIzSnmtYR5Img5iGp13-vfgMWSWGFfHGq4,158
|
|
2
|
+
timer/conftest.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
3
|
timer/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
-
timer/version.py,sha256=
|
|
4
|
+
timer/version.py,sha256=WwRqnFgnq__PbO35sCvLvs1RophYxK14NfumJXilAlE,80
|
|
4
5
|
timer/constant/__init__.py,sha256=0e0W-lRc5xtJ9LSsEyq4o6zKckaRweAvrntmFE1gisE,67
|
|
5
6
|
timer/constant/decimals.py,sha256=9SKe-IbFIbXY-Mps6bSYBqaWuxLiRlsa3rNmT_oDbiM,53
|
|
6
7
|
timer/constant/various.py,sha256=v_UX49eVff3JnXs_VgS0luKkCc3iIH_EUalPxNt8-YQ,117
|
|
7
8
|
timer/controller/__init__.py,sha256=lN-rF2nX4pCZ-Z8l7kJTlk4mmsInfLZ52NY4S6Wf6A0,1662
|
|
8
9
|
timer/decorator/__init__.py,sha256=juqd9PbXs4yg45zMJ7BHAOPQjb7sgEbWE9InBtGZhfo,24
|
|
9
|
-
timer/decorator/function.py,sha256=
|
|
10
|
-
timer/error/__init__.py,sha256=
|
|
10
|
+
timer/decorator/function.py,sha256=LBbtkIA9p1T-HgIh6OMgtJTyOmo6aM5TuIwK0E7ieQk,3570
|
|
11
|
+
timer/error/__init__.py,sha256=pjjCgDtv2TJ8-eBnq98buWPIDt-Znfj1Gbk9CXzJhQE,1197
|
|
11
12
|
timer/helper/__init__.py,sha256=kYe7PVpjG7UeamvAvohgiIleefsGslx1tJvuNO5_oSQ,117
|
|
12
|
-
timer/helper/decimals.py,sha256=
|
|
13
|
-
timer/helper/output.py,sha256=
|
|
14
|
-
timer/helper/time_fractions.py,sha256=
|
|
13
|
+
timer/helper/decimals.py,sha256=3WXpSLkf8ySbOMgE98ieTvs1ILaSA1ymennlQdMxaNM,1629
|
|
14
|
+
timer/helper/output.py,sha256=doWzg3W4fKA5udxrKl1RJkMrqqDyzh3FR9kL-4i13VE,1744
|
|
15
|
+
timer/helper/time_fractions.py,sha256=sDz-ZOnMC6shJKiMCBc_oYk3kMjyNklYmoU4kbQMh-8,1089
|
|
15
16
|
timer/helper/thread/__init__.py,sha256=sIXJTI05fLVUT71DbiBf0axFpxOn0L9sRe23KUOC8Gw,471
|
|
16
|
-
timer/helper/thread/list.py,sha256=
|
|
17
|
+
timer/helper/thread/list.py,sha256=6rT-0zRG9xuwbQsLpFdTeoa-O1NqWiCbznzsC31e2SA,1485
|
|
17
18
|
timer/model/__init__.py,sha256=m-K3jgLBqKUwBNJByKeLiGQCzCVZC07N12_SmkbGxyg,145
|
|
18
19
|
timer/model/elapsed_time_fractions.py,sha256=UXfABMQ14kgsEHjQmef2PKMgtdqKF9zPyrmA9_TQHrg,282
|
|
19
20
|
timer/model/thread_item.py,sha256=7i7oH2eghF5K_k4Oed-i6to85VoPlJw3_g0U5ilB_VY,199
|
|
20
21
|
timer/model/time_fractions.py,sha256=yweResJFS7NutBoLWZYKC1f7GIemwWVIiEc04xsxOno,1298
|
|
21
|
-
timer/model/timer.py,sha256=
|
|
22
|
-
timer/model/timer_base.py,sha256=
|
|
22
|
+
timer/model/timer.py,sha256=cQblVIvhIU-Fhh3L4EvYVZNFkNWj8ABv1A1detaQMGo,7190
|
|
23
|
+
timer/model/timer_base.py,sha256=TZ_ROsJWM0hLioXnYTFv_WMqN31c1i2yng2IU8vteWc,1015
|
|
23
24
|
timer/model/abc/mkdocstrings.py,sha256=3JrQVkW0D4YW7hOVOr9Jd35gH7-Z5o8y0bNjQz1EAzw,350
|
|
24
|
-
timer_for_python-0.9.
|
|
25
|
-
timer_for_python-0.9.
|
|
26
|
-
timer_for_python-0.9.
|
|
27
|
-
timer_for_python-0.9.
|
|
28
|
-
timer_for_python-0.9.6.dist-info/RECORD,,
|
|
25
|
+
timer_for_python-0.9.7.dist-info/METADATA,sha256=4ZLhVadmmIJ-MKqAmi7Qp7xJpw2BYxn4wF2BDNyAeeQ,5824
|
|
26
|
+
timer_for_python-0.9.7.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
27
|
+
timer_for_python-0.9.7.dist-info/licenses/LICENSE.md,sha256=bV6mZhoYf6kHYGgsG3ArjpF_tjOweaI7QZKRvmzkUMI,1085
|
|
28
|
+
timer_for_python-0.9.7.dist-info/RECORD,,
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
timer
|
|
File without changes
|