timer-for-python 0.9.5__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 ADDED
File without changes
@@ -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(function: Callable[..., Any], args: tuple[Any, ...], kwargs: dict[str, Any]) -> str:
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(f"{Color.YELLOW}Timer: Something went wrong {action}{'' if helper.thread.is_none(thread) else f' for thread {thread}'}.{Color.OFF}")
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, float)) or decimals is None:
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(f"{Color.YELLOW}Timer: Decimals set to {MAXIMUM} as the Timer doesn't support more than {MAXIMUM} decimals (i.e. nanoseconds).{Color.OFF}")
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(f"{Color.YELLOW}Timer: Decimals {decimals} set to {decimals_rounded} as a floating number is invalid input.{Color.OFF}")
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"when trying to verify the Timer's decimals input \"{decimals}\"")
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(f"{intro} {fractions.count_minutes_to_seconds():.{decimals}f} seconds ({time.minutes}m {fractions.seconds_rounded()}s){thread_info}")
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}")
@@ -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"when trying to remove entry from the Timer's thread list for entry index \"{entry_index}\"")
34
+ f'when trying to remove entry from the Timer\'s thread list for entry index "{entry_index}"'
35
+ )
@@ -19,4 +19,5 @@ def calculate_time_fractions(elapsed_time_ns: int) -> ElapsedTimeFractions:
19
19
  seconds=int(seconds),
20
20
  minutes=int(minutes),
21
21
  hours=int(hours),
22
- days=int(days))
22
+ days=int(days),
23
+ )
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__ = ["_threads", "_decimals",
13
- "_context_manager_threads", "_context_manager_latest_thread", "_context_manager_latest_decimals",
14
- "__dict__"]
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 = decimals if decimals == constant.decimals.DEFAULT else helper.decimals.validate_and_normalise(
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__(self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None) -> None:
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__(self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None) -> None:
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, 5)
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.5
4
- Summary: Timer for Python
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
3
+ Version: 0.9.7
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
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
- License-File: LICENSE.md
29
- Requires-Dist: colorist==1.8.3
30
- Provides-Extra: testing
31
- Requires-Dist: coverage==7.10.6; extra == "testing"
32
- Requires-Dist: flake8==7.3.0; extra == "testing"
33
- Requires-Dist: mypy==1.18.2; extra == "testing"
34
- Requires-Dist: pytest==8.4.2; extra == "testing"
35
- Requires-Dist: pytest-cov==7.0.0; extra == "testing"
36
- Requires-Dist: tox==4.29.0; extra == "testing"
37
- Dynamic: download-url
38
- Dynamic: license-file
39
-
40
- [![Latest version](https://img.shields.io/static/v1?label=version&message=0.9.5&color=yellowgreen)](https://github.com/jakob-bagterp/timer-for-python/releases/latest)
26
+
27
+ [![Latest version](https://img.shields.io/static/v1?label=version&message=0.9.7&color=yellowgreen)](https://github.com/jakob-bagterp/timer-for-python/releases/latest)
41
28
  [![Python 3.10 | 3.11 | 3.12 | 3.13 | 3.14+](https://img.shields.io/static/v1?label=python&message=3.10%20|%203.11%20|%203.12%20|%203.13%20|%203.14%2B&color=blueviolet)](https://www.python.org)
42
29
  [![MIT license](https://img.shields.io/static/v1?label=license&message=MIT&color=blue)](https://github.com/jakob-bagterp/timer-for-python/blob/master/LICENSE.md)
43
30
  [![Codecov](https://codecov.io/gh/jakob-bagterp/timer-for-python/branch/master/graph/badge.svg?token=P4IT8WQO0R)](https://codecov.io/gh/jakob-bagterp/timer-for-python)
@@ -141,7 +128,7 @@ with Timer(thread="A")
141
128
  ```
142
129
 
143
130
  ## Become a Sponsor 🏅
144
- If you find this project helpful, please consider supporting its development. Your donations will help keep it alive and growing. Every contribution, no matter the size, makes a difference.
131
+ If you find this project helpful, please consider supporting its development. Your donations will help keep it alive and growing. Every contribution makes a difference, whether you buy a coffee or support with a monthly donation. Find your tier here:
145
132
 
146
133
  [Donate on GitHub Sponsors](https://github.com/sponsors/jakob-bagterp)
147
134
 
@@ -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=PK1wGCVS63at5uPJt8QNpKNnQYMLRSMYnvubSH63rKE,80
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=M5EI68cxE8atPgPoEdjXWDKuzJ25cLZ0vDjrft1JOzk,3553
10
- timer/error/__init__.py,sha256=I0WE1idFHucWU66AsPTg5hqDCuzd1l1Bo5V4cLFCivE,1183
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=5S4Ab1P3yABUjhW0BLgjJMSH9jizbSNXgsvHoWWnZbE,1569
13
- timer/helper/output.py,sha256=KeI1L3I3cRjlTQKRFKMsG-j8_OGSEJEH0Ipc2KbQC8Q,1714
14
- timer/helper/time_fractions.py,sha256=5mjbiy-LmChZDRF_gg-jxJAZOLdJxIv8oOfLBgviVB0,1083
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=19A85nXIB_gyt-wsNHNoIsfxRwbWMuH9DrgGf8daYCg,1477
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=NWUPg0InWuOruwXNx1P6wgGzj6s9_PqKCDhhp8qXqM4,7144
22
- timer/model/timer_base.py,sha256=RV0KelcP_nvMhVbBR3kC3q1dnvckAHUp4BxgJGrDiJo,1001
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.5.dist-info/licenses/LICENSE.md,sha256=bV6mZhoYf6kHYGgsG3ArjpF_tjOweaI7QZKRvmzkUMI,1085
25
- timer_for_python-0.9.5.dist-info/METADATA,sha256=cgKiIms4g2KC5Qvxtno-JOU1rLCmUR4KN4jmYXe4Qs4,7214
26
- timer_for_python-0.9.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
27
- timer_for_python-0.9.5.dist-info/top_level.txt,sha256=mbqaJ4u4Wh38RQxq5PFpTOu6h1EcSHjwI2bqdDYCRAI,6
28
- timer_for_python-0.9.5.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,5 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (80.9.0)
2
+ Generator: hatchling 1.28.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
-
@@ -1 +0,0 @@
1
- timer