timer-for-python 0.9.2__tar.gz → 0.9.4__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.
Files changed (36) hide show
  1. {timer_for_python-0.9.2/src/timer_for_python.egg-info → timer_for_python-0.9.4}/PKG-INFO +14 -12
  2. {timer_for_python-0.9.2 → timer_for_python-0.9.4}/README.md +2 -2
  3. {timer_for_python-0.9.2 → timer_for_python-0.9.4}/pyproject.toml +1 -1
  4. {timer_for_python-0.9.2 → timer_for_python-0.9.4}/setup.cfg +9 -9
  5. {timer_for_python-0.9.2 → timer_for_python-0.9.4}/src/timer/decorator/function.py +28 -2
  6. {timer_for_python-0.9.2 → timer_for_python-0.9.4}/src/timer/model/thread_item.py +1 -1
  7. {timer_for_python-0.9.2 → timer_for_python-0.9.4}/src/timer/model/timer.py +4 -4
  8. {timer_for_python-0.9.2 → timer_for_python-0.9.4}/src/timer/version.py +1 -1
  9. {timer_for_python-0.9.2 → timer_for_python-0.9.4/src/timer_for_python.egg-info}/PKG-INFO +14 -12
  10. timer_for_python-0.9.4/src/timer_for_python.egg-info/requires.txt +10 -0
  11. timer_for_python-0.9.2/src/timer_for_python.egg-info/requires.txt +0 -10
  12. {timer_for_python-0.9.2 → timer_for_python-0.9.4}/LICENSE.md +0 -0
  13. {timer_for_python-0.9.2 → timer_for_python-0.9.4}/MANIFEST.in +0 -0
  14. {timer_for_python-0.9.2 → timer_for_python-0.9.4}/src/timer/__init__.py +0 -0
  15. {timer_for_python-0.9.2 → timer_for_python-0.9.4}/src/timer/constant/__init__.py +0 -0
  16. {timer_for_python-0.9.2 → timer_for_python-0.9.4}/src/timer/constant/decimals.py +0 -0
  17. {timer_for_python-0.9.2 → timer_for_python-0.9.4}/src/timer/constant/various.py +0 -0
  18. {timer_for_python-0.9.2 → timer_for_python-0.9.4}/src/timer/controller/__init__.py +0 -0
  19. {timer_for_python-0.9.2 → timer_for_python-0.9.4}/src/timer/decorator/__init__.py +0 -0
  20. {timer_for_python-0.9.2 → timer_for_python-0.9.4}/src/timer/error/__init__.py +0 -0
  21. {timer_for_python-0.9.2 → timer_for_python-0.9.4}/src/timer/helper/__init__.py +0 -0
  22. {timer_for_python-0.9.2 → timer_for_python-0.9.4}/src/timer/helper/decimals.py +0 -0
  23. {timer_for_python-0.9.2 → timer_for_python-0.9.4}/src/timer/helper/output.py +0 -0
  24. {timer_for_python-0.9.2 → timer_for_python-0.9.4}/src/timer/helper/thread/__init__.py +0 -0
  25. {timer_for_python-0.9.2 → timer_for_python-0.9.4}/src/timer/helper/thread/list.py +0 -0
  26. {timer_for_python-0.9.2 → timer_for_python-0.9.4}/src/timer/helper/time_fractions.py +0 -0
  27. {timer_for_python-0.9.2 → timer_for_python-0.9.4}/src/timer/model/__init__.py +0 -0
  28. {timer_for_python-0.9.2 → timer_for_python-0.9.4}/src/timer/model/abc/mkdocstrings.py +0 -0
  29. {timer_for_python-0.9.2 → timer_for_python-0.9.4}/src/timer/model/elapsed_time_fractions.py +0 -0
  30. {timer_for_python-0.9.2 → timer_for_python-0.9.4}/src/timer/model/time_fractions.py +0 -0
  31. {timer_for_python-0.9.2 → timer_for_python-0.9.4}/src/timer/model/timer_base.py +0 -0
  32. {timer_for_python-0.9.2 → timer_for_python-0.9.4}/src/timer/py.typed +0 -0
  33. {timer_for_python-0.9.2 → timer_for_python-0.9.4}/src/timer_for_python.egg-info/SOURCES.txt +0 -0
  34. {timer_for_python-0.9.2 → timer_for_python-0.9.4}/src/timer_for_python.egg-info/dependency_links.txt +0 -0
  35. {timer_for_python-0.9.2 → timer_for_python-0.9.4}/src/timer_for_python.egg-info/not-zip-safe +0 -0
  36. {timer_for_python-0.9.2 → timer_for_python-0.9.4}/src/timer_for_python.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: timer-for-python
3
- Version: 0.9.2
3
+ Version: 0.9.4
4
4
  Summary: Timer for Python
5
5
  Home-page: https://jakob-bagterp.github.io/timer-for-python/
6
6
  Download-URL: https://pypi.org/project/timer-for-python/
@@ -27,15 +27,17 @@ Description-Content-Type: text/markdown
27
27
  License-File: LICENSE.md
28
28
  Requires-Dist: colorist==1.8.3
29
29
  Provides-Extra: testing
30
- Requires-Dist: coverage==7.6.8; extra == "testing"
31
- Requires-Dist: flake8==7.1.1; extra == "testing"
32
- Requires-Dist: mypy==1.13.0; extra == "testing"
33
- Requires-Dist: numpy==2.1.3; extra == "testing"
34
- Requires-Dist: pytest==8.3.4; extra == "testing"
35
- Requires-Dist: pytest-cov==6.0.0; extra == "testing"
36
- Requires-Dist: tox==4.23.2; extra == "testing"
37
-
38
- [![Latest version](https://img.shields.io/static/v1?label=version&message=0.9.2&color=yellowgreen)](https://github.com/jakob-bagterp/timer-for-python/releases/latest)
30
+ Requires-Dist: coverage==7.8.0; extra == "testing"
31
+ Requires-Dist: flake8==7.2.0; extra == "testing"
32
+ Requires-Dist: mypy==1.15.0; extra == "testing"
33
+ Requires-Dist: numpy==2.2.4; extra == "testing"
34
+ Requires-Dist: pytest==8.3.5; extra == "testing"
35
+ Requires-Dist: pytest-cov==6.1.1; extra == "testing"
36
+ Requires-Dist: tox==4.25.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.4&color=yellowgreen)](https://github.com/jakob-bagterp/timer-for-python/releases/latest)
39
41
  [![Python 3.10 | 3.11 | 3.12 | 3.13+](https://img.shields.io/static/v1?label=python&message=3.10%20|%203.11%20|%203.12%20|%203.13%2B&color=blueviolet)](https://www.python.org)
40
42
  [![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)
41
43
  [![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)
@@ -64,7 +66,7 @@ timer.stop() # Output example: 12.34 seconds
64
66
  ```
65
67
 
66
68
  #### Context Manager
67
- Alternatively, use the with statement. This will automatically start and stop the Timer – and so no need to declare `timer.start()` and `timer.stop()`. Same result as before, but less code:
69
+ Alternatively, use the with statement. This will automatically start and stop the clock – and so no need to declare `timer.start()` and `timer.stop()`. Same result as before, but less code:
68
70
 
69
71
  ```python
70
72
  with Timer():
@@ -1,4 +1,4 @@
1
- [![Latest version](https://img.shields.io/static/v1?label=version&message=0.9.2&color=yellowgreen)](https://github.com/jakob-bagterp/timer-for-python/releases/latest)
1
+ [![Latest version](https://img.shields.io/static/v1?label=version&message=0.9.4&color=yellowgreen)](https://github.com/jakob-bagterp/timer-for-python/releases/latest)
2
2
  [![Python 3.10 | 3.11 | 3.12 | 3.13+](https://img.shields.io/static/v1?label=python&message=3.10%20|%203.11%20|%203.12%20|%203.13%2B&color=blueviolet)](https://www.python.org)
3
3
  [![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)
4
4
  [![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)
@@ -27,7 +27,7 @@ timer.stop() # Output example: 12.34 seconds
27
27
  ```
28
28
 
29
29
  #### Context Manager
30
- Alternatively, use the with statement. This will automatically start and stop the Timer – and so no need to declare `timer.start()` and `timer.stop()`. Same result as before, but less code:
30
+ Alternatively, use the with statement. This will automatically start and stop the clock – and so no need to declare `timer.start()` and `timer.stop()`. Same result as before, but less code:
31
31
 
32
32
  ```python
33
33
  with Timer():
@@ -1,6 +1,6 @@
1
1
  [build-system]
2
2
  requires = [
3
- "setuptools==75.6.0",
3
+ "setuptools==80.4.0",
4
4
  "wheel"
5
5
  ]
6
6
  build-backend = "setuptools.build_meta"
@@ -1,6 +1,6 @@
1
1
  [metadata]
2
2
  name = timer-for-python
3
- version = 0.9.2
3
+ version = 0.9.4
4
4
  author = Jakob Bagterp
5
5
  author_email = jakob_bagterp@hotmail.com
6
6
  maintainer = Jakob Bagterp
@@ -44,19 +44,19 @@ include_package_data = True
44
44
 
45
45
  [options.extras_require]
46
46
  testing =
47
- coverage==7.6.8
48
- flake8==7.1.1
49
- mypy==1.13.0
50
- numpy==2.1.3
51
- pytest==8.3.4
52
- pytest-cov==6.0.0
53
- tox==4.23.2
47
+ coverage==7.8.0
48
+ flake8==7.2.0
49
+ mypy==1.15.0
50
+ numpy==2.2.4
51
+ pytest==8.3.5
52
+ pytest-cov==6.1.1
53
+ tox==4.25.0
54
54
 
55
55
  [options.packages.find]
56
56
  where = src
57
57
 
58
58
  [options.package_data]
59
- colorist = py.typed
59
+ timer = py.typed
60
60
 
61
61
  [mypy]
62
62
  mypy_path = $MYPY_CONFIG_FILE_DIR/src
@@ -9,10 +9,20 @@ 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:
13
+ thread_name = function.__name__
14
+ if args or kwargs:
15
+ arg_names = function.__code__.co_varnames[:function.__code__.co_argcount]
16
+ mapped_args = [f"{name}={value!r}" for name, value in zip(arg_names, args)]
17
+ mapped_kwargs = [f"{key}={value!r}" for key, value in kwargs.items()]
18
+ all_mapped_args = ", ".join(mapped_args + mapped_kwargs)
19
+ thread_name += f"({all_mapped_args})"
20
+ return thread_name
21
+
12
22
  def decorator(function: Callable[..., Any]) -> Callable[..., Any]:
13
23
  @functools.wraps(function)
14
24
  def wrapper(*args: Any, **kwargs: Any) -> Any:
15
- thread_name = thread if thread else function.__name__
25
+ thread_name = thread if thread else get_function_with_arguments_as_thread_name(function, args, kwargs)
16
26
  with Timer(thread=thread_name, decimals=decimals):
17
27
  return function(*args, **kwargs)
18
28
  return wrapper
@@ -59,6 +69,22 @@ class MkDocstringsWrapper(MkDocstringsWrapper_ABC):
59
69
  How it appears in the terminal:
60
70
 
61
71
  <pre><code>% Elapsed time: 0.12345 seconds for thread <span class="fg-green">CUSTOM</span></code></pre>
72
+
73
+ The `@function_timer` automatically names the function and its arguments as thread name. For example:
74
+
75
+ ```python linenums="1" hl_lines="3-4"
76
+ from timer import function_timer
77
+
78
+ @function_timer()
79
+ def sum_numbers(a, b):
80
+ return a + b
81
+
82
+ sum_numbers(1, 2)
83
+ ```
84
+
85
+ How it appears in the terminal:
86
+
87
+ <pre><code>% Elapsed time: 0.12 seconds for thread <span class="fg-green">SUM_NUMBERS(A=1, B=2)</span></code></pre>
62
88
  """
63
89
 
64
- return function_timer(thread=thread, decimals=decimals)
90
+ return function_timer(thread=thread, decimals=decimals) # pragma: no cover
@@ -1,7 +1,7 @@
1
1
  from dataclasses import dataclass
2
2
 
3
3
 
4
- @dataclass(frozen=True, slots=True)
4
+ @dataclass(slots=True)
5
5
  class ThreadItem:
6
6
  """Class to define a thread's name, start time, and decimals."""
7
7
 
@@ -150,8 +150,8 @@ class Timer(TimerBase):
150
150
  try:
151
151
  start_time = time.perf_counter_ns() # For precision, this is the first operation of the function.
152
152
  controller.start(self, thread, start_time, decimals)
153
- except Exception:
154
- error.message_for_action("when trying to start the Timer", thread)
153
+ except Exception: # pragma: no cover
154
+ error.message_for_action("when trying to start the Timer", thread) # pragma: no cover
155
155
 
156
156
  def stop(self, thread: str | None = None) -> None:
157
157
  """Stops the Timer. Should always be called after `timer.start()`.
@@ -200,5 +200,5 @@ class Timer(TimerBase):
200
200
  try:
201
201
  stop_time = time.perf_counter_ns() # For precision, this is the first operation of the function.
202
202
  controller.stop(self, thread, stop_time)
203
- except Exception:
204
- error.message_for_action("when trying to stop the Timer", thread)
203
+ except Exception: # pragma: no cover
204
+ error.message_for_action("when trying to stop the Timer", thread) # pragma: no cover
@@ -1,2 +1,2 @@
1
- __version_info__ = (0, 9, 2)
1
+ __version_info__ = (0, 9, 4)
2
2
  __version__ = ".".join(map(str, __version_info__))
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: timer-for-python
3
- Version: 0.9.2
3
+ Version: 0.9.4
4
4
  Summary: Timer for Python
5
5
  Home-page: https://jakob-bagterp.github.io/timer-for-python/
6
6
  Download-URL: https://pypi.org/project/timer-for-python/
@@ -27,15 +27,17 @@ Description-Content-Type: text/markdown
27
27
  License-File: LICENSE.md
28
28
  Requires-Dist: colorist==1.8.3
29
29
  Provides-Extra: testing
30
- Requires-Dist: coverage==7.6.8; extra == "testing"
31
- Requires-Dist: flake8==7.1.1; extra == "testing"
32
- Requires-Dist: mypy==1.13.0; extra == "testing"
33
- Requires-Dist: numpy==2.1.3; extra == "testing"
34
- Requires-Dist: pytest==8.3.4; extra == "testing"
35
- Requires-Dist: pytest-cov==6.0.0; extra == "testing"
36
- Requires-Dist: tox==4.23.2; extra == "testing"
37
-
38
- [![Latest version](https://img.shields.io/static/v1?label=version&message=0.9.2&color=yellowgreen)](https://github.com/jakob-bagterp/timer-for-python/releases/latest)
30
+ Requires-Dist: coverage==7.8.0; extra == "testing"
31
+ Requires-Dist: flake8==7.2.0; extra == "testing"
32
+ Requires-Dist: mypy==1.15.0; extra == "testing"
33
+ Requires-Dist: numpy==2.2.4; extra == "testing"
34
+ Requires-Dist: pytest==8.3.5; extra == "testing"
35
+ Requires-Dist: pytest-cov==6.1.1; extra == "testing"
36
+ Requires-Dist: tox==4.25.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.4&color=yellowgreen)](https://github.com/jakob-bagterp/timer-for-python/releases/latest)
39
41
  [![Python 3.10 | 3.11 | 3.12 | 3.13+](https://img.shields.io/static/v1?label=python&message=3.10%20|%203.11%20|%203.12%20|%203.13%2B&color=blueviolet)](https://www.python.org)
40
42
  [![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)
41
43
  [![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)
@@ -64,7 +66,7 @@ timer.stop() # Output example: 12.34 seconds
64
66
  ```
65
67
 
66
68
  #### Context Manager
67
- Alternatively, use the with statement. This will automatically start and stop the Timer – and so no need to declare `timer.start()` and `timer.stop()`. Same result as before, but less code:
69
+ Alternatively, use the with statement. This will automatically start and stop the clock – and so no need to declare `timer.start()` and `timer.stop()`. Same result as before, but less code:
68
70
 
69
71
  ```python
70
72
  with Timer():
@@ -0,0 +1,10 @@
1
+ colorist==1.8.3
2
+
3
+ [testing]
4
+ coverage==7.8.0
5
+ flake8==7.2.0
6
+ mypy==1.15.0
7
+ numpy==2.2.4
8
+ pytest==8.3.5
9
+ pytest-cov==6.1.1
10
+ tox==4.25.0
@@ -1,10 +0,0 @@
1
- colorist==1.8.3
2
-
3
- [testing]
4
- coverage==7.6.8
5
- flake8==7.1.1
6
- mypy==1.13.0
7
- numpy==2.1.3
8
- pytest==8.3.4
9
- pytest-cov==6.0.0
10
- tox==4.23.2