executiontime 0.4.0__tar.gz → 0.4.1__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.
- {executiontime-0.4.0 → executiontime-0.4.1}/PKG-INFO +10 -1
- {executiontime-0.4.0 → executiontime-0.4.1}/README.md +9 -0
- {executiontime-0.4.0 → executiontime-0.4.1}/executiontime/__init__.py +10 -2
- {executiontime-0.4.0 → executiontime-0.4.1}/pyproject.toml +1 -1
- {executiontime-0.4.0 → executiontime-0.4.1}/LICENSE +0 -0
- {executiontime-0.4.0 → executiontime-0.4.1}/executiontime/py.typed +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: executiontime
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.1
|
|
4
4
|
Summary: A simple function decorator to display its execution time on the console or in the logs.
|
|
5
5
|
License: MIT
|
|
6
6
|
Keywords: testing,logging,time,performance,execution
|
|
@@ -40,6 +40,7 @@ pip install executiontime
|
|
|
40
40
|
## Usage
|
|
41
41
|
|
|
42
42
|
You simply need to decorate the function and specify a message template.
|
|
43
|
+
If you do not provide a message, one will be created for you based on the names of the decorated function and its module.
|
|
43
44
|
|
|
44
45
|
```python
|
|
45
46
|
from executiontime import printexecutiontime
|
|
@@ -81,3 +82,11 @@ if __name__ == '__main__':
|
|
|
81
82
|
my_function()
|
|
82
83
|
```
|
|
83
84
|
|
|
85
|
+
## Changelog
|
|
86
|
+
|
|
87
|
+
- v0.4.1
|
|
88
|
+
- The message is now optional and a default one is provided, based on the names of the decorated function and its module.
|
|
89
|
+
- v0.4.0
|
|
90
|
+
- Refresh the dependencies
|
|
91
|
+
- Replace deprecated datetime.utcnow()
|
|
92
|
+
|
|
@@ -15,6 +15,7 @@ pip install executiontime
|
|
|
15
15
|
## Usage
|
|
16
16
|
|
|
17
17
|
You simply need to decorate the function and specify a message template.
|
|
18
|
+
If you do not provide a message, one will be created for you based on the names of the decorated function and its module.
|
|
18
19
|
|
|
19
20
|
```python
|
|
20
21
|
from executiontime import printexecutiontime
|
|
@@ -55,3 +56,11 @@ def my_function():
|
|
|
55
56
|
if __name__ == '__main__':
|
|
56
57
|
my_function()
|
|
57
58
|
```
|
|
59
|
+
|
|
60
|
+
## Changelog
|
|
61
|
+
|
|
62
|
+
- v0.4.1
|
|
63
|
+
- The message is now optional and a default one is provided, based on the names of the decorated function and its module.
|
|
64
|
+
- v0.4.0
|
|
65
|
+
- Refresh the dependencies
|
|
66
|
+
- Replace deprecated datetime.utcnow()
|
|
@@ -29,10 +29,15 @@ P = ParamSpec("P")
|
|
|
29
29
|
T = TypeVar("T")
|
|
30
30
|
|
|
31
31
|
|
|
32
|
-
def printexecutiontime(
|
|
32
|
+
def printexecutiontime(
|
|
33
|
+
message: Optional[str] = None, output: Callable[..., None] = print, color: Optional[str] = None
|
|
34
|
+
) -> Callable[[Callable[P, T]], Callable[P, T]]:
|
|
33
35
|
"""
|
|
34
36
|
This function returns a decorator. This allows to have a decorator that accepts parameters.
|
|
35
37
|
message: A string with a '{0}' placeholder for the time that will be sent to the console.
|
|
38
|
+
If none is provided, we will use a default message with the module's and functions's names.
|
|
39
|
+
output: A function to send the message. By default we use 'print' that sends the message to the console.
|
|
40
|
+
color: One of the constant string provided in this module to color the message.
|
|
36
41
|
"""
|
|
37
42
|
|
|
38
43
|
def decorator(function: Callable[P, T]) -> Callable[P, T]:
|
|
@@ -48,7 +53,10 @@ def printexecutiontime(message: str, output: Callable[..., None] = print, color:
|
|
|
48
53
|
start = datetime.now(tz=UTC)
|
|
49
54
|
value = function(*args, **kwargs)
|
|
50
55
|
elapsed = datetime.now(tz=UTC) - start
|
|
51
|
-
|
|
56
|
+
if message is None:
|
|
57
|
+
msg = f"{function.__module__}.{function.__name__} executed in {elapsed}"
|
|
58
|
+
else:
|
|
59
|
+
msg = message.format(elapsed)
|
|
52
60
|
if color:
|
|
53
61
|
msg = color + msg + Fore.RESET
|
|
54
62
|
output(msg)
|
|
File without changes
|
|
File without changes
|