timer-for-python 0.9.0__tar.gz → 0.9.2__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.
- {timer_for_python-0.9.0/src/timer_for_python.egg-info → timer_for_python-0.9.2}/PKG-INFO +2 -2
- {timer_for_python-0.9.0 → timer_for_python-0.9.2}/README.md +1 -1
- {timer_for_python-0.9.0 → timer_for_python-0.9.2}/setup.cfg +1 -1
- {timer_for_python-0.9.0 → timer_for_python-0.9.2}/src/timer/error/__init__.py +2 -2
- {timer_for_python-0.9.0 → timer_for_python-0.9.2}/src/timer/helper/decimals.py +1 -1
- {timer_for_python-0.9.0 → timer_for_python-0.9.2}/src/timer/helper/thread/list.py +3 -3
- {timer_for_python-0.9.0 → timer_for_python-0.9.2}/src/timer/model/timer.py +10 -10
- timer_for_python-0.9.2/src/timer/model/timer_base.py +32 -0
- {timer_for_python-0.9.0 → timer_for_python-0.9.2}/src/timer/version.py +1 -1
- {timer_for_python-0.9.0 → timer_for_python-0.9.2/src/timer_for_python.egg-info}/PKG-INFO +2 -2
- timer_for_python-0.9.0/src/timer/model/timer_base.py +0 -25
- {timer_for_python-0.9.0 → timer_for_python-0.9.2}/LICENSE.md +0 -0
- {timer_for_python-0.9.0 → timer_for_python-0.9.2}/MANIFEST.in +0 -0
- {timer_for_python-0.9.0 → timer_for_python-0.9.2}/pyproject.toml +0 -0
- {timer_for_python-0.9.0 → timer_for_python-0.9.2}/src/timer/__init__.py +0 -0
- {timer_for_python-0.9.0 → timer_for_python-0.9.2}/src/timer/constant/__init__.py +0 -0
- {timer_for_python-0.9.0 → timer_for_python-0.9.2}/src/timer/constant/decimals.py +0 -0
- {timer_for_python-0.9.0 → timer_for_python-0.9.2}/src/timer/constant/various.py +0 -0
- {timer_for_python-0.9.0 → timer_for_python-0.9.2}/src/timer/controller/__init__.py +0 -0
- {timer_for_python-0.9.0 → timer_for_python-0.9.2}/src/timer/decorator/__init__.py +0 -0
- {timer_for_python-0.9.0 → timer_for_python-0.9.2}/src/timer/decorator/function.py +0 -0
- {timer_for_python-0.9.0 → timer_for_python-0.9.2}/src/timer/helper/__init__.py +0 -0
- {timer_for_python-0.9.0 → timer_for_python-0.9.2}/src/timer/helper/output.py +0 -0
- {timer_for_python-0.9.0 → timer_for_python-0.9.2}/src/timer/helper/thread/__init__.py +0 -0
- {timer_for_python-0.9.0 → timer_for_python-0.9.2}/src/timer/helper/time_fractions.py +0 -0
- {timer_for_python-0.9.0 → timer_for_python-0.9.2}/src/timer/model/__init__.py +0 -0
- {timer_for_python-0.9.0 → timer_for_python-0.9.2}/src/timer/model/abc/mkdocstrings.py +0 -0
- {timer_for_python-0.9.0 → timer_for_python-0.9.2}/src/timer/model/elapsed_time_fractions.py +0 -0
- {timer_for_python-0.9.0 → timer_for_python-0.9.2}/src/timer/model/thread_item.py +0 -0
- {timer_for_python-0.9.0 → timer_for_python-0.9.2}/src/timer/model/time_fractions.py +0 -0
- {timer_for_python-0.9.0 → timer_for_python-0.9.2}/src/timer/py.typed +0 -0
- {timer_for_python-0.9.0 → timer_for_python-0.9.2}/src/timer_for_python.egg-info/SOURCES.txt +0 -0
- {timer_for_python-0.9.0 → timer_for_python-0.9.2}/src/timer_for_python.egg-info/dependency_links.txt +0 -0
- {timer_for_python-0.9.0 → timer_for_python-0.9.2}/src/timer_for_python.egg-info/not-zip-safe +0 -0
- {timer_for_python-0.9.0 → timer_for_python-0.9.2}/src/timer_for_python.egg-info/requires.txt +0 -0
- {timer_for_python-0.9.0 → timer_for_python-0.9.2}/src/timer_for_python.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: timer-for-python
|
|
3
|
-
Version: 0.9.
|
|
3
|
+
Version: 0.9.2
|
|
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/
|
|
@@ -35,7 +35,7 @@ Requires-Dist: pytest==8.3.4; extra == "testing"
|
|
|
35
35
|
Requires-Dist: pytest-cov==6.0.0; extra == "testing"
|
|
36
36
|
Requires-Dist: tox==4.23.2; extra == "testing"
|
|
37
37
|
|
|
38
|
-
[](https://github.com/jakob-bagterp/timer-for-python/releases/latest)
|
|
39
39
|
[](https://www.python.org)
|
|
40
40
|
[](https://github.com/jakob-bagterp/timer-for-python/blob/master/LICENSE.md)
|
|
41
41
|
[](https://codecov.io/gh/jakob-bagterp/timer-for-python)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
[](https://github.com/jakob-bagterp/timer-for-python/releases/latest)
|
|
2
2
|
[](https://www.python.org)
|
|
3
3
|
[](https://github.com/jakob-bagterp/timer-for-python/blob/master/LICENSE.md)
|
|
4
4
|
[](https://codecov.io/gh/jakob-bagterp/timer-for-python)
|
|
@@ -18,8 +18,8 @@ def stop_controller(timer: TimerBase, thread: str | None) -> None:
|
|
|
18
18
|
print(f"{Color.YELLOW}Timer is not running. Use .start() to start it.{Color.OFF}")
|
|
19
19
|
else:
|
|
20
20
|
print(f"{Color.YELLOW}Timer for thread {thread} is not running. Use .start({thread=}) to start it.{Color.OFF}")
|
|
21
|
-
if len(timer.
|
|
22
|
-
open_threads = [thread_item.name for thread_item in timer.
|
|
21
|
+
if len(timer._threads) > 0:
|
|
22
|
+
open_threads = [thread_item.name for thread_item in timer._threads]
|
|
23
23
|
print(f"Or maybe you aren't stopping the right thread? Currently open threads: {', '.join(open_threads)}")
|
|
24
24
|
|
|
25
25
|
|
|
@@ -8,7 +8,7 @@ from ..model.timer_base import TimerBase
|
|
|
8
8
|
def mediate(timer: TimerBase, decimals: int | None) -> int:
|
|
9
9
|
"""If the start function doesn't have decimals defined, then use the decimals value defined when the Timer() was initiated."""
|
|
10
10
|
|
|
11
|
-
return timer.
|
|
11
|
+
return timer._decimals if decimals is None else validate_and_normalise(decimals)
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
def validate_and_normalise(decimals: int | float | None) -> int:
|
|
@@ -6,7 +6,7 @@ from ...model.timer_base import TimerBase
|
|
|
6
6
|
def try_get_thread_item_and_index(timer: TimerBase, thread: str) -> tuple[ThreadItem, int] | tuple[None, None]:
|
|
7
7
|
try:
|
|
8
8
|
index_counter = 0
|
|
9
|
-
for thread_item in timer.
|
|
9
|
+
for thread_item in timer._threads:
|
|
10
10
|
# Check if thread already exists in list. Note that this expects a normalised thread (i.e. string and not None) and already in uppercase so it evaluates as intended.
|
|
11
11
|
if thread_item.name == thread:
|
|
12
12
|
# Make sure only the first match is returned, yet the main function is not designed to allow input of duplicates.
|
|
@@ -21,14 +21,14 @@ def try_get_thread_item_and_index(timer: TimerBase, thread: str) -> tuple[Thread
|
|
|
21
21
|
|
|
22
22
|
def add(timer: TimerBase, thread: str, start_time: int, decimals: int) -> None:
|
|
23
23
|
try:
|
|
24
|
-
timer.
|
|
24
|
+
timer._threads.append(ThreadItem(name=thread, start_time=start_time, decimals=decimals))
|
|
25
25
|
except Exception:
|
|
26
26
|
error.message_for_action("when trying to add entry to the Timer's thread list", thread)
|
|
27
27
|
|
|
28
28
|
|
|
29
29
|
def remove(timer: TimerBase, entry_index: int) -> None:
|
|
30
30
|
try:
|
|
31
|
-
timer.
|
|
31
|
+
timer._threads.pop(entry_index)
|
|
32
32
|
except Exception:
|
|
33
33
|
error.message_for_action(
|
|
34
34
|
f"when trying to remove entry from the Timer's thread list for entry index \"{entry_index}\"")
|
|
@@ -9,8 +9,8 @@ from .timer_base import TimerBase
|
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
class Timer(TimerBase):
|
|
12
|
-
__slots__ = ["
|
|
13
|
-
"
|
|
12
|
+
__slots__ = ["_threads", "_decimals",
|
|
13
|
+
"_context_manager_threads", "_context_manager_latest_thread", "_context_manager_latest_decimals",
|
|
14
14
|
"__dict__"]
|
|
15
15
|
|
|
16
16
|
_instance = None
|
|
@@ -85,21 +85,21 @@ class Timer(TimerBase):
|
|
|
85
85
|
"""
|
|
86
86
|
|
|
87
87
|
if not self._lock_init: # Ensure that initialisation of the lists only runs the first time.
|
|
88
|
-
self.
|
|
89
|
-
self.
|
|
88
|
+
self._threads: list[ThreadItem] = []
|
|
89
|
+
self._context_manager_threads: list[str] = []
|
|
90
90
|
self._lock_init = True
|
|
91
|
-
self.
|
|
91
|
+
self._decimals: int = decimals if decimals == constant.decimals.DEFAULT else helper.decimals.validate_and_normalise(
|
|
92
92
|
decimals)
|
|
93
|
-
self.
|
|
94
|
-
self.
|
|
93
|
+
self._context_manager_latest_thread: str = helper.thread.normalise_to_string_and_uppercase(thread)
|
|
94
|
+
self._context_manager_latest_decimals: int = self._decimals
|
|
95
95
|
|
|
96
96
|
def __enter__(self) -> Timer:
|
|
97
|
-
self.
|
|
98
|
-
self.start(self.
|
|
97
|
+
self._context_manager_threads.append(self._context_manager_latest_thread)
|
|
98
|
+
self.start(self._context_manager_latest_thread, self._context_manager_latest_decimals)
|
|
99
99
|
return self
|
|
100
100
|
|
|
101
101
|
def __exit__(self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None) -> None:
|
|
102
|
-
last_context_manager_thread = self.
|
|
102
|
+
last_context_manager_thread = self._context_manager_threads.pop()
|
|
103
103
|
self.stop(last_context_manager_thread)
|
|
104
104
|
|
|
105
105
|
def start(self, thread: str | None = None, decimals: int | None = None) -> None:
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
from abc import ABC, abstractmethod
|
|
2
|
+
from types import TracebackType
|
|
3
|
+
|
|
4
|
+
from .thread_item import ThreadItem
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class TimerBase(ABC):
|
|
8
|
+
"""Abstract base class of Timer object."""
|
|
9
|
+
|
|
10
|
+
__slots__ = ["_decimals", "_threads"]
|
|
11
|
+
|
|
12
|
+
def __init__(self) -> None:
|
|
13
|
+
self._decimals: int # pragma: no cover
|
|
14
|
+
self._threads: list[ThreadItem] # pragma: no cover
|
|
15
|
+
|
|
16
|
+
def __enter__(self) -> "TimerBase":
|
|
17
|
+
raise NotImplementedError # pragma: no cover
|
|
18
|
+
|
|
19
|
+
def __exit__(self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None) -> None:
|
|
20
|
+
raise NotImplementedError # pragma: no cover
|
|
21
|
+
|
|
22
|
+
@abstractmethod
|
|
23
|
+
def start(self, thread: str | None = None, decimals: int | None = None) -> None:
|
|
24
|
+
"""Starts the Timer."""
|
|
25
|
+
|
|
26
|
+
raise NotImplementedError # pragma: no cover
|
|
27
|
+
|
|
28
|
+
@abstractmethod
|
|
29
|
+
def stop(self, thread: str | None = None) -> None:
|
|
30
|
+
"""Stops the Timer."""
|
|
31
|
+
|
|
32
|
+
raise NotImplementedError # pragma: no cover
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
__version_info__ = (0, 9,
|
|
1
|
+
__version_info__ = (0, 9, 2)
|
|
2
2
|
__version__ = ".".join(map(str, __version_info__))
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: timer-for-python
|
|
3
|
-
Version: 0.9.
|
|
3
|
+
Version: 0.9.2
|
|
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/
|
|
@@ -35,7 +35,7 @@ Requires-Dist: pytest==8.3.4; extra == "testing"
|
|
|
35
35
|
Requires-Dist: pytest-cov==6.0.0; extra == "testing"
|
|
36
36
|
Requires-Dist: tox==4.23.2; extra == "testing"
|
|
37
37
|
|
|
38
|
-
[](https://github.com/jakob-bagterp/timer-for-python/releases/latest)
|
|
39
39
|
[](https://www.python.org)
|
|
40
40
|
[](https://github.com/jakob-bagterp/timer-for-python/blob/master/LICENSE.md)
|
|
41
41
|
[](https://codecov.io/gh/jakob-bagterp/timer-for-python)
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
from abc import ABC, abstractmethod
|
|
2
|
-
|
|
3
|
-
from .thread_item import ThreadItem
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class TimerBase(ABC):
|
|
7
|
-
"""Abstract base class of Timer object."""
|
|
8
|
-
|
|
9
|
-
__slots__ = ["decimals", "threads"]
|
|
10
|
-
|
|
11
|
-
def __init__(self) -> None:
|
|
12
|
-
self.decimals: int
|
|
13
|
-
self.threads: list[ThreadItem]
|
|
14
|
-
|
|
15
|
-
@abstractmethod
|
|
16
|
-
def start(self, thread: str, decimals: int) -> None:
|
|
17
|
-
"""Starts the Timer."""
|
|
18
|
-
|
|
19
|
-
raise NotImplementedError
|
|
20
|
-
|
|
21
|
-
@abstractmethod
|
|
22
|
-
def stop(self, thread: str) -> None:
|
|
23
|
-
"""Stops the Timer."""
|
|
24
|
-
|
|
25
|
-
raise NotImplementedError
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{timer_for_python-0.9.0 → timer_for_python-0.9.2}/src/timer_for_python.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
{timer_for_python-0.9.0 → timer_for_python-0.9.2}/src/timer_for_python.egg-info/not-zip-safe
RENAMED
|
File without changes
|
{timer_for_python-0.9.0 → timer_for_python-0.9.2}/src/timer_for_python.egg-info/requires.txt
RENAMED
|
File without changes
|
{timer_for_python-0.9.0 → timer_for_python-0.9.2}/src/timer_for_python.egg-info/top_level.txt
RENAMED
|
File without changes
|