timer-for-python 0.9.6__tar.gz → 0.9.7__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 (38) hide show
  1. timer_for_python-0.9.7/.gitignore +179 -0
  2. {timer_for_python-0.9.6/src/timer_for_python.egg-info → timer_for_python-0.9.7}/PKG-INFO +10 -33
  3. {timer_for_python-0.9.6 → timer_for_python-0.9.7}/README.md +1 -1
  4. timer_for_python-0.9.7/pyproject.toml +96 -0
  5. {timer_for_python-0.9.6 → timer_for_python-0.9.7}/src/timer/decorator/function.py +6 -2
  6. {timer_for_python-0.9.6 → timer_for_python-0.9.7}/src/timer/error/__init__.py +3 -1
  7. {timer_for_python-0.9.6 → timer_for_python-0.9.7}/src/timer/helper/decimals.py +8 -4
  8. {timer_for_python-0.9.6 → timer_for_python-0.9.7}/src/timer/helper/output.py +3 -1
  9. {timer_for_python-0.9.6 → timer_for_python-0.9.7}/src/timer/helper/thread/list.py +2 -1
  10. {timer_for_python-0.9.6 → timer_for_python-0.9.7}/src/timer/helper/time_fractions.py +2 -1
  11. {timer_for_python-0.9.6 → timer_for_python-0.9.7}/src/timer/model/timer.py +14 -6
  12. {timer_for_python-0.9.6 → timer_for_python-0.9.7}/src/timer/model/timer_base.py +3 -1
  13. timer_for_python-0.9.7/src/timer/py.typed +0 -0
  14. {timer_for_python-0.9.6 → timer_for_python-0.9.7}/src/timer/version.py +1 -1
  15. timer_for_python-0.9.6/MANIFEST.in +0 -11
  16. timer_for_python-0.9.6/PKG-INFO +0 -164
  17. timer_for_python-0.9.6/pyproject.toml +0 -6
  18. timer_for_python-0.9.6/setup.cfg +0 -83
  19. timer_for_python-0.9.6/src/timer_for_python.egg-info/SOURCES.txt +0 -34
  20. timer_for_python-0.9.6/src/timer_for_python.egg-info/dependency_links.txt +0 -1
  21. timer_for_python-0.9.6/src/timer_for_python.egg-info/not-zip-safe +0 -1
  22. timer_for_python-0.9.6/src/timer_for_python.egg-info/requires.txt +0 -9
  23. timer_for_python-0.9.6/src/timer_for_python.egg-info/top_level.txt +0 -1
  24. {timer_for_python-0.9.6 → timer_for_python-0.9.7}/LICENSE.md +0 -0
  25. {timer_for_python-0.9.6 → timer_for_python-0.9.7}/src/timer/__init__.py +0 -0
  26. /timer_for_python-0.9.6/src/timer/py.typed → /timer_for_python-0.9.7/src/timer/conftest.py +0 -0
  27. {timer_for_python-0.9.6 → timer_for_python-0.9.7}/src/timer/constant/__init__.py +0 -0
  28. {timer_for_python-0.9.6 → timer_for_python-0.9.7}/src/timer/constant/decimals.py +0 -0
  29. {timer_for_python-0.9.6 → timer_for_python-0.9.7}/src/timer/constant/various.py +0 -0
  30. {timer_for_python-0.9.6 → timer_for_python-0.9.7}/src/timer/controller/__init__.py +0 -0
  31. {timer_for_python-0.9.6 → timer_for_python-0.9.7}/src/timer/decorator/__init__.py +0 -0
  32. {timer_for_python-0.9.6 → timer_for_python-0.9.7}/src/timer/helper/__init__.py +0 -0
  33. {timer_for_python-0.9.6 → timer_for_python-0.9.7}/src/timer/helper/thread/__init__.py +0 -0
  34. {timer_for_python-0.9.6 → timer_for_python-0.9.7}/src/timer/model/__init__.py +0 -0
  35. {timer_for_python-0.9.6 → timer_for_python-0.9.7}/src/timer/model/abc/mkdocstrings.py +0 -0
  36. {timer_for_python-0.9.6 → timer_for_python-0.9.7}/src/timer/model/elapsed_time_fractions.py +0 -0
  37. {timer_for_python-0.9.6 → timer_for_python-0.9.7}/src/timer/model/thread_item.py +0 -0
  38. {timer_for_python-0.9.6 → timer_for_python-0.9.7}/src/timer/model/time_fractions.py +0 -0
@@ -0,0 +1,179 @@
1
+ # Visual Studio Code
2
+ *.code-workspace
3
+ .vscode/
4
+
5
+ # Jupyter
6
+ *.ipynb
7
+
8
+ # Created by https://www.toptal.com/developers/gitignore/api/macos,python
9
+ # Edit at https://www.toptal.com/developers/gitignore?templates=macos,python
10
+
11
+ ### macOS ###
12
+ # General
13
+ .DS_Store
14
+ .AppleDouble
15
+ .LSOverride
16
+
17
+ # Icon must end with two \r
18
+ Icon
19
+
20
+ # Thumbnails
21
+ ._*
22
+
23
+ # Files that might appear in the root of a volume
24
+ .DocumentRevisions-V100
25
+ .fseventsd
26
+ .Spotlight-V100
27
+ .TemporaryItems
28
+ .Trashes
29
+ .VolumeIcon.icns
30
+ .com.apple.timemachine.donotpresent
31
+
32
+ # Directories potentially created on remote AFP share
33
+ .AppleDB
34
+ .AppleDesktop
35
+ Network Trash Folder
36
+ Temporary Items
37
+ .apdisk
38
+
39
+ ### Python ###
40
+ # Byte-compiled / optimized / DLL files
41
+ __pycache__/
42
+ *.py[cod]
43
+ *$py.class
44
+
45
+ # C extensions
46
+ *.so
47
+
48
+ # Distribution / packaging
49
+ .Python
50
+ build/
51
+ develop-eggs/
52
+ dist/
53
+ downloads/
54
+ eggs/
55
+ .eggs/
56
+ lib/
57
+ lib64/
58
+ parts/
59
+ sdist/
60
+ var/
61
+ wheels/
62
+ share/python-wheels/
63
+ *.egg-info/
64
+ .installed.cfg
65
+ *.egg
66
+ MANIFEST
67
+
68
+ # PyInstaller
69
+ # Usually these files are written by a python script from a template
70
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
71
+ *.manifest
72
+ *.spec
73
+
74
+ # Installer logs
75
+ pip-log.txt
76
+ pip-delete-this-directory.txt
77
+
78
+ # Unit test / coverage reports
79
+ htmlcov/
80
+ .tox/
81
+ .nox/
82
+ .coverage
83
+ .coverage.*
84
+ .cache
85
+ nosetests.xml
86
+ coverage.xml
87
+ *.cover
88
+ *.py,cover
89
+ .hypothesis/
90
+ .pytest_cache/
91
+ cover/
92
+
93
+ # Translations
94
+ *.mo
95
+ *.pot
96
+
97
+ # Django stuff:
98
+ *.log
99
+ local_settings.py
100
+ db.sqlite3
101
+ db.sqlite3-journal
102
+
103
+ # Flask stuff:
104
+ instance/
105
+ .webassets-cache
106
+
107
+ # Scrapy stuff:
108
+ .scrapy
109
+
110
+ # Sphinx documentation
111
+ docs/_build/
112
+
113
+ # PyBuilder
114
+ .pybuilder/
115
+ target/
116
+
117
+ # Jupyter Notebook
118
+ .ipynb_checkpoints
119
+
120
+ # IPython
121
+ profile_default/
122
+ ipython_config.py
123
+
124
+ # pyenv
125
+ # For a library or package, you might want to ignore these files since the code is
126
+ # intended to run in multiple environments; otherwise, check them in:
127
+ # .python-version
128
+
129
+ # pipenv
130
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
131
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
132
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
133
+ # install all needed dependencies.
134
+ #Pipfile.lock
135
+
136
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow
137
+ __pypackages__/
138
+
139
+ # Celery stuff
140
+ celerybeat-schedule
141
+ celerybeat.pid
142
+
143
+ # SageMath parsed files
144
+ *.sage.py
145
+
146
+ # Environments
147
+ .env
148
+ .venv
149
+ env/
150
+ venv/
151
+ ENV/
152
+ env.bak/
153
+ venv.bak/
154
+
155
+ # Spyder project settings
156
+ .spyderproject
157
+ .spyproject
158
+
159
+ # Rope project settings
160
+ .ropeproject
161
+
162
+ # MkDocs documentation
163
+ /site
164
+
165
+ # mypy
166
+ .mypy_cache/
167
+ .dmypy.json
168
+ dmypy.json
169
+
170
+ # Pyre type checker
171
+ .pyre/
172
+
173
+ # pytype static type analyzer
174
+ .pytype/
175
+
176
+ # Cython debug symbols
177
+ cython_debug/
178
+
179
+ # End of https://www.toptal.com/developers/gitignore/api/macos,python
@@ -1,43 +1,30 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: timer-for-python
3
- Version: 0.9.6
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
- License-File: LICENSE.md
29
- Requires-Dist: colorist==1.8.8
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
- [![Latest version](https://img.shields.io/static/v1?label=version&message=0.9.6&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)
@@ -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,4 +1,4 @@
1
- [![Latest version](https://img.shields.io/static/v1?label=version&message=0.9.6&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.7&color=yellowgreen)](https://github.com/jakob-bagterp/timer-for-python/releases/latest)
2
2
  [![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)
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)
@@ -0,0 +1,96 @@
1
+ [project]
2
+ name = "timer-for-python"
3
+ version = "0.9.7"
4
+ description = "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
+ authors = [
6
+ { name = "Jakob Bagterp", email = "jakob_bagterp@hotmail.com" }
7
+ ]
8
+ maintainers = [
9
+ { name = "Jakob Bagterp", email = "jakob_bagterp@hotmail.com" }
10
+ ]
11
+ license = { text = "MIT License" }
12
+ readme = "README.md"
13
+ keywords = ["python", "timer"]
14
+ requires-python = ">=3.10"
15
+ classifiers = [
16
+ "Programming Language :: Python :: 3",
17
+ "Programming Language :: Python :: 3.10",
18
+ "Programming Language :: Python :: 3.11",
19
+ "Programming Language :: Python :: 3.12",
20
+ "Programming Language :: Python :: 3.13",
21
+ "Programming Language :: Python :: 3.14",
22
+ "License :: OSI Approved :: MIT License",
23
+ "Operating System :: OS Independent",
24
+ ]
25
+
26
+ dependencies = [
27
+ "colorist==1.8.9",
28
+ ]
29
+
30
+ [project.urls]
31
+ "Bug Tracker" = "https://github.com/jakob-bagterp/timer-for-python/issues"
32
+ "Documentation" = "https://jakob-bagterp.github.io/timer-for-python/"
33
+ "API Reference" = "https://jakob-bagterp.github.io/timer-for-python/reference/"
34
+ "Source Code" = "https://github.com/jakob-bagterp/timer-for-python"
35
+ "Release Notes" = "https://github.com/jakob-bagterp/timer-for-python/releases"
36
+
37
+ [dependency-groups]
38
+ dev = [
39
+ "coverage==7.13.2",
40
+ "mypy==1.19.1",
41
+ "pre-commit==4.5.1",
42
+ "pytest==9.0.2",
43
+ "pytest-cov==6.2.1",
44
+ "pytest-xdist==3.8.0",
45
+ "ruff==0.15.0",
46
+ "tox==4.34.1",
47
+ ]
48
+ docs = [
49
+ "mkdocs==1.6.1",
50
+ "mkdocs-git-revision-date-localized-plugin==1.5.1",
51
+ "mkdocs-material==9.7.1",
52
+ "mkdocs-material-extensions==1.3.1",
53
+ "mkdocs-minify-plugin==0.8.0",
54
+ "mkdocs-redirects==1.2.2",
55
+ "mkdocstrings==1.0.2",
56
+ "mkdocstrings-python==2.0.1",
57
+ ]
58
+
59
+ [build-system]
60
+ requires = ["hatchling"]
61
+ build-backend = "hatchling.build"
62
+
63
+ [tool.hatch.build.targets.wheel]
64
+ packages = ["src/timer"]
65
+
66
+ [tool.hatch.build.targets.sdist]
67
+ include = ["/src"]
68
+
69
+ [tool.hatch.build.targets.wheel.sources]
70
+ "src/timer" = "timer"
71
+
72
+ [tool.uv]
73
+ package = true
74
+
75
+ [tool.mypy]
76
+ files = ["src"]
77
+ disallow_any_unimported = true
78
+ no_implicit_reexport = true
79
+ show_error_codes = true
80
+ strict = true
81
+ warn_unreachable = true
82
+
83
+ [tool.ruff]
84
+ line-length = 120
85
+
86
+ [tool.ruff.lint]
87
+ select = ["E", "F", "W", "I", "UP"]
88
+ ignore = ["E501", "COM812"]
89
+
90
+ [tool.ruff.lint.isort]
91
+ split-on-trailing-comma = false
92
+
93
+ [tool.ruff.format]
94
+ quote-style = "double"
95
+ indent-style = "space"
96
+ skip-magic-trailing-comma = true
@@ -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
 
@@ -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
+ )
@@ -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
@@ -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
+ )
@@ -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
 
@@ -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
File without changes
@@ -1,2 +1,2 @@
1
- __version_info__ = (0, 9, 6)
1
+ __version_info__ = (0, 9, 7)
2
2
  __version__ = ".".join(map(str, __version_info__))
@@ -1,11 +0,0 @@
1
- include README.md
2
- include LICENSE.md
3
- include pyproject.toml
4
- include setup.cfg
5
-
6
- graft src
7
-
8
- global-exclude __pycache__
9
- global-exclude *.py[co]
10
- global-exclude .DS_Store
11
- global-exclude conftest.py
@@ -1,164 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: timer-for-python
3
- Version: 0.9.6
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
- Project-URL: Bug Tracker, https://github.com/jakob-bagterp/timer-for-python/issues
13
- Project-URL: Documentation, https://jakob-bagterp.github.io/timer-for-python/
14
- Project-URL: API Reference, https://jakob-bagterp.github.io/timer-for-python/reference/
15
- Project-URL: Source Code, https://github.com/jakob-bagterp/timer-for-python
16
- Project-URL: Release Notes, https://github.com/jakob-bagterp/timer-for-python/releases
17
- Keywords: python,timer
18
- Classifier: Programming Language :: Python :: 3
19
- Classifier: Programming Language :: Python :: 3.10
20
- Classifier: Programming Language :: Python :: 3.11
21
- Classifier: Programming Language :: Python :: 3.12
22
- Classifier: Programming Language :: Python :: 3.13
23
- Classifier: Programming Language :: Python :: 3.14
24
- Classifier: License :: OSI Approved :: MIT License
25
- Classifier: Operating System :: OS Independent
26
- Requires-Python: >=3.10
27
- Description-Content-Type: text/markdown
28
- License-File: LICENSE.md
29
- Requires-Dist: colorist==1.8.8
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
- [![Latest version](https://img.shields.io/static/v1?label=version&message=0.9.6&color=yellowgreen)](https://github.com/jakob-bagterp/timer-for-python/releases/latest)
41
- [![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
- [![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
- [![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)
44
- [![CodeQL](https://github.com/jakob-bagterp/timer-for-python/actions/workflows/github-code-scanning/codeql/badge.svg)](https://github.com/jakob-bagterp/timer-for-python/actions/workflows/github-code-scanning/codeql)
45
- [![Test](https://github.com/jakob-bagterp/timer-for-python/actions/workflows/test.yml/badge.svg)](https://github.com/jakob-bagterp/timer-for-python/actions/workflows/test.yml)
46
- [![Downloads](https://static.pepy.tech/badge/timer-for-python)](https://pepy.tech/project/timer-for-python)
47
-
48
- # ⏳ Timer for Python ⌛️
49
- Lightweight Python 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.
50
-
51
- Ready to try? Learn [how to install](https://jakob-bagterp.github.io/timer-for-python/getting-started/installation/) and find tutorials in the [user guide](https://jakob-bagterp.github.io/timer-for-python/user-guide/).
52
-
53
- ## Getting Started
54
- ### Basics
55
- Simply add the Timer to your imports, and then wrap the Timer function around your code to measure the performance of the executed block of code:
56
-
57
- ```python
58
- from timer import Timer
59
-
60
- timer = Timer()
61
- timer.start()
62
-
63
- # Insert your code here
64
-
65
- timer.stop() # Output example: 12.34 seconds
66
- ```
67
-
68
- #### Context Manager
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:
70
-
71
- ```python
72
- with Timer():
73
- # Insert your code here
74
-
75
- # Output example: 12.34 seconds
76
- ```
77
-
78
- #### Decorator
79
- Or use the `function_timer` as a function decorator:
80
-
81
- ```python
82
- from timer import function_timer
83
-
84
- @function_timer()
85
- def test_function():
86
- # Insert your code here
87
-
88
- test_function()
89
-
90
- # Output example: 12.34 seconds for thread TEST_FUNCTION
91
- ```
92
-
93
- ### Core Features
94
- #### Decimals
95
- Instead of the default value of `2` for `decimals``, you can set the output precision up to `9` in the `decimals` parameter:
96
-
97
- ```python
98
- timer = Timer()
99
- timer.start(decimals=5)
100
-
101
- # Insert your code here
102
-
103
- timer.stop() # Output example: 0.12345 seconds
104
- ```
105
-
106
- #### Multiple Threads
107
- Imagine that you want to troubleshoot which parts of your code are performing better or worse. Or do you want to split-test the performance of different methods? Timer for Python is a quick, easy way to get the job done.
108
-
109
- To measure the performance of multiple blocks of code, use the `thread` parameter to name different threads:
110
-
111
- ```python
112
- timer = Timer()
113
- timer.start(thread="A")
114
-
115
- # Insert your code here
116
-
117
- timer.start(thread="B", decimals=5)
118
-
119
- # Insert more code here
120
-
121
- timer.stop(thread="B") # Output example: 0.12345 seconds for thread B
122
-
123
- # Insert even more code here
124
-
125
- timer.stop(thread="A") # Output example: 6.78 seconds for thread A
126
- ```
127
-
128
- Or use the `with` statement to get the same result with less code:
129
- ```python
130
- with Timer(thread="A")
131
- # Insert your code here
132
-
133
- with Timer(thread="B", decimals=5):
134
- # Insert more code here
135
-
136
- # Output example: 0.12345 seconds for thread B
137
-
138
- # Insert even more code here
139
-
140
- # Output example: 6.78 seconds for thread A
141
- ```
142
-
143
- ## 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 makes a difference, whether you buy a coffee or support with a monthly donation. Find your tier here:
145
-
146
- [Donate on GitHub Sponsors](https://github.com/sponsors/jakob-bagterp)
147
-
148
- Thank you for your support! 🙌
149
-
150
- ## Contribute
151
- If you have suggestions or changes to the module, feel free to add to the code and create a [pull request](https://github.com/jakob-bagterp/timer-for-python/pulls).
152
-
153
- ## Report Bugs
154
- 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,6 +0,0 @@
1
- [build-system]
2
- requires = [
3
- "setuptools==80.9.0",
4
- "wheel"
5
- ]
6
- build-backend = "setuptools.build_meta"
@@ -1,83 +0,0 @@
1
- [metadata]
2
- name = timer-for-python
3
- version = 0.9.6
4
- author = Jakob Bagterp
5
- author_email = jakob_bagterp@hotmail.com
6
- maintainer = Jakob Bagterp
7
- maintainer_email = jakob_bagterp@hotmail.com
8
- description = 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
9
- long_description = file: README.md, LICENSE.md
10
- long_description_content_type = text/markdown
11
- keywords =
12
- python
13
- timer
14
- url = https://jakob-bagterp.github.io/timer-for-python/
15
- download_url = https://pypi.org/project/timer-for-python/
16
- project_urls =
17
- Bug Tracker = https://github.com/jakob-bagterp/timer-for-python/issues
18
- Documentation = https://jakob-bagterp.github.io/timer-for-python/
19
- API Reference = https://jakob-bagterp.github.io/timer-for-python/reference/
20
- Source Code = https://github.com/jakob-bagterp/timer-for-python
21
- Release Notes = https://github.com/jakob-bagterp/timer-for-python/releases
22
- classifiers =
23
- Programming Language :: Python :: 3
24
- Programming Language :: Python :: 3.10
25
- Programming Language :: Python :: 3.11
26
- Programming Language :: Python :: 3.12
27
- Programming Language :: Python :: 3.13
28
- Programming Language :: Python :: 3.14
29
- License :: OSI Approved :: MIT License
30
- Operating System :: OS Independent
31
- license = MIT License
32
- license_files = LICENSE.md
33
-
34
- [options]
35
- package_dir =
36
- = src
37
- packages = find:
38
- python_requires = >=3.10
39
- setup_requires =
40
- colorist==1.8.8
41
- install_requires =
42
- colorist==1.8.8
43
- zip_safe = no
44
- include_package_data = True
45
-
46
- [options.extras_require]
47
- testing =
48
- coverage==7.11.0
49
- flake8==7.3.0
50
- mypy==1.19.0
51
- pytest==9.0.1
52
- pytest-cov==7.0.0
53
- tox==4.32.0
54
-
55
- [options.packages.find]
56
- where = src
57
-
58
- [options.package_data]
59
- timer = py.typed
60
-
61
- [mypy]
62
- mypy_path = $MYPY_CONFIG_FILE_DIR/src
63
- disallow_any_unimported = True
64
- no_implicit_reexport = True
65
- show_error_codes = True
66
- strict = True
67
- warn_unreachable = True
68
-
69
- [pycodestyle]
70
- max_line_length = 120
71
-
72
- [flake8]
73
- ignore =
74
- E501
75
- exclude =
76
- .git
77
- __pycache__
78
- dist
79
-
80
- [egg_info]
81
- tag_build =
82
- tag_date = 0
83
-
@@ -1,34 +0,0 @@
1
- LICENSE.md
2
- MANIFEST.in
3
- README.md
4
- pyproject.toml
5
- setup.cfg
6
- src/timer/__init__.py
7
- src/timer/py.typed
8
- src/timer/version.py
9
- src/timer/constant/__init__.py
10
- src/timer/constant/decimals.py
11
- src/timer/constant/various.py
12
- src/timer/controller/__init__.py
13
- src/timer/decorator/__init__.py
14
- src/timer/decorator/function.py
15
- src/timer/error/__init__.py
16
- src/timer/helper/__init__.py
17
- src/timer/helper/decimals.py
18
- src/timer/helper/output.py
19
- src/timer/helper/time_fractions.py
20
- src/timer/helper/thread/__init__.py
21
- src/timer/helper/thread/list.py
22
- src/timer/model/__init__.py
23
- src/timer/model/elapsed_time_fractions.py
24
- src/timer/model/thread_item.py
25
- src/timer/model/time_fractions.py
26
- src/timer/model/timer.py
27
- src/timer/model/timer_base.py
28
- src/timer/model/abc/mkdocstrings.py
29
- src/timer_for_python.egg-info/PKG-INFO
30
- src/timer_for_python.egg-info/SOURCES.txt
31
- src/timer_for_python.egg-info/dependency_links.txt
32
- src/timer_for_python.egg-info/not-zip-safe
33
- src/timer_for_python.egg-info/requires.txt
34
- src/timer_for_python.egg-info/top_level.txt
@@ -1,9 +0,0 @@
1
- colorist==1.8.8
2
-
3
- [testing]
4
- coverage==7.11.0
5
- flake8==7.3.0
6
- mypy==1.19.0
7
- pytest==9.0.1
8
- pytest-cov==7.0.0
9
- tox==4.32.0