pylemetry 1.1.2__tar.gz → 1.1.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.
- {pylemetry-1.1.2 → pylemetry-1.1.4}/PKG-INFO +7 -2
- {pylemetry-1.1.2 → pylemetry-1.1.4}/README.md +5 -1
- {pylemetry-1.1.2 → pylemetry-1.1.4}/pyproject.toml +5 -3
- {pylemetry-1.1.2 → pylemetry-1.1.4}/src/pylemetry/meters/counter.py +1 -1
- {pylemetry-1.1.2 → pylemetry-1.1.4}/src/pylemetry/meters/gauge.py +1 -1
- {pylemetry-1.1.2 → pylemetry-1.1.4}/src/pylemetry/meters/meter.py +1 -1
- {pylemetry-1.1.2 → pylemetry-1.1.4}/src/pylemetry/meters/timer.py +3 -3
- {pylemetry-1.1.2 → pylemetry-1.1.4}/src/pylemetry/reporting/logging.py +4 -2
- {pylemetry-1.1.2 → pylemetry-1.1.4}/src/pylemetry/reporting/reporter.py +6 -1
- {pylemetry-1.1.2 → pylemetry-1.1.4}/test/test_pylemetry/reporting/test_reporter.py +19 -0
- {pylemetry-1.1.2 → pylemetry-1.1.4}/uv.lock +5 -1
- {pylemetry-1.1.2 → pylemetry-1.1.4}/.github/actions/configure-uv/action.yaml +0 -0
- {pylemetry-1.1.2 → pylemetry-1.1.4}/.github/workflows/ci.yaml +0 -0
- {pylemetry-1.1.2 → pylemetry-1.1.4}/.github/workflows/release.yaml +0 -0
- {pylemetry-1.1.2 → pylemetry-1.1.4}/.gitignore +0 -0
- {pylemetry-1.1.2 → pylemetry-1.1.4}/LICENSE +0 -0
- {pylemetry-1.1.2 → pylemetry-1.1.4}/src/__init__.py +0 -0
- {pylemetry-1.1.2 → pylemetry-1.1.4}/src/pylemetry/__init__.py +0 -0
- {pylemetry-1.1.2 → pylemetry-1.1.4}/src/pylemetry/decorators/__init__.py +0 -0
- {pylemetry-1.1.2 → pylemetry-1.1.4}/src/pylemetry/decorators/count.py +0 -0
- {pylemetry-1.1.2 → pylemetry-1.1.4}/src/pylemetry/decorators/time.py +0 -0
- {pylemetry-1.1.2 → pylemetry-1.1.4}/src/pylemetry/meters/__init__.py +0 -0
- {pylemetry-1.1.2 → pylemetry-1.1.4}/src/pylemetry/py.typed +0 -0
- {pylemetry-1.1.2 → pylemetry-1.1.4}/src/pylemetry/registry.py +0 -0
- {pylemetry-1.1.2 → pylemetry-1.1.4}/src/pylemetry/reporting/__init__.py +0 -0
- {pylemetry-1.1.2 → pylemetry-1.1.4}/src/pylemetry/reporting/reporting_type.py +0 -0
- {pylemetry-1.1.2 → pylemetry-1.1.4}/test/conftest.py +0 -0
- {pylemetry-1.1.2 → pylemetry-1.1.4}/test/test_pylemetry/decorators/test_count.py +0 -0
- {pylemetry-1.1.2 → pylemetry-1.1.4}/test/test_pylemetry/decorators/test_time.py +0 -0
- {pylemetry-1.1.2 → pylemetry-1.1.4}/test/test_pylemetry/meters/test_counter.py +0 -0
- {pylemetry-1.1.2 → pylemetry-1.1.4}/test/test_pylemetry/meters/test_gauge.py +0 -0
- {pylemetry-1.1.2 → pylemetry-1.1.4}/test/test_pylemetry/meters/test_timer.py +0 -0
- {pylemetry-1.1.2 → pylemetry-1.1.4}/test/test_pylemetry/reporting/test_logging.py +0 -0
- {pylemetry-1.1.2 → pylemetry-1.1.4}/test/test_pylemetry/test_registry.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pylemetry
|
|
3
|
-
Version: 1.1.
|
|
3
|
+
Version: 1.1.4
|
|
4
4
|
Summary: A Python metrics library
|
|
5
5
|
Project-URL: Homepage, https://pypi.org/project/pylemetry/
|
|
6
6
|
Project-URL: Repository, https://github.com/amurphy4/pylemetry
|
|
@@ -18,6 +18,7 @@ Classifier: Programming Language :: Python :: 3.12
|
|
|
18
18
|
Classifier: Programming Language :: Python :: 3.13
|
|
19
19
|
Classifier: Programming Language :: Python :: 3.14
|
|
20
20
|
Requires-Python: >=3.10
|
|
21
|
+
Requires-Dist: typing-extensions>=4.15.0
|
|
21
22
|
Description-Content-Type: text/markdown
|
|
22
23
|
|
|
23
24
|
# Pylemetry
|
|
@@ -265,4 +266,8 @@ logger = logging.getLogger()
|
|
|
265
266
|
with LoggingReporter(10, logger, logging.INFO, ReportingType.CUMULATIVE) as reporter:
|
|
266
267
|
reporter.configure_message_format("{name} - {value}", MeterType.COUNTER)
|
|
267
268
|
...
|
|
268
|
-
```
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
When using a reporter as a context manager there is an additional optional parameter you can set,
|
|
272
|
+
`clear_registry_on_exit` which is set to `False` by default. When set to `True`, this will
|
|
273
|
+
clear the registry (via `registry.clear()`) when the context manager exits
|
|
@@ -243,4 +243,8 @@ logger = logging.getLogger()
|
|
|
243
243
|
with LoggingReporter(10, logger, logging.INFO, ReportingType.CUMULATIVE) as reporter:
|
|
244
244
|
reporter.configure_message_format("{name} - {value}", MeterType.COUNTER)
|
|
245
245
|
...
|
|
246
|
-
```
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
When using a reporter as a context manager there is an additional optional parameter you can set,
|
|
249
|
+
`clear_registry_on_exit` which is set to `False` by default. When set to `True`, this will
|
|
250
|
+
clear the registry (via `registry.clear()`) when the context manager exits
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "pylemetry"
|
|
3
|
-
version = "1.1.
|
|
3
|
+
version = "1.1.4"
|
|
4
4
|
description = "A Python metrics library"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
requires-python = ">=3.10"
|
|
@@ -25,7 +25,9 @@ classifiers = [
|
|
|
25
25
|
"Programming Language :: Python :: 3.14",
|
|
26
26
|
]
|
|
27
27
|
|
|
28
|
-
dependencies = [
|
|
28
|
+
dependencies = [
|
|
29
|
+
"typing-extensions>=4.15.0",
|
|
30
|
+
]
|
|
29
31
|
|
|
30
32
|
[project.urls]
|
|
31
33
|
Homepage = "https://pypi.org/project/pylemetry/"
|
|
@@ -58,7 +60,7 @@ explicit_package_bases = true
|
|
|
58
60
|
line-length = 120
|
|
59
61
|
|
|
60
62
|
[tool.ruff.lint]
|
|
61
|
-
|
|
63
|
+
select = ["E", "F", "B"]
|
|
62
64
|
|
|
63
65
|
[tool.pytest.ini_options]
|
|
64
66
|
addopts = "--cov=pylemetry --cov-report=html"
|
|
@@ -8,10 +8,10 @@ from pylemetry.meters.meter import Meter, MeterType
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
class Timer(Meter):
|
|
11
|
-
def __init__(self):
|
|
11
|
+
def __init__(self) -> None:
|
|
12
12
|
super().__init__(MeterType.TIMER)
|
|
13
13
|
|
|
14
|
-
self.ticks = []
|
|
14
|
+
self.ticks: list[float] = []
|
|
15
15
|
|
|
16
16
|
def tick(self, tick: float) -> None:
|
|
17
17
|
"""
|
|
@@ -49,7 +49,7 @@ class Timer(Meter):
|
|
|
49
49
|
|
|
50
50
|
ticks = self.get_ticks_since_last_interval() if since_last_interval else self.ticks
|
|
51
51
|
|
|
52
|
-
return sum(ticks)
|
|
52
|
+
return sum(ticks) # type: ignore
|
|
53
53
|
|
|
54
54
|
def get_count(self, since_last_interval: bool = False) -> int:
|
|
55
55
|
"""
|
|
@@ -23,8 +23,10 @@ class Loggable(Protocol[P, R]):
|
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
class LoggingReporter(Reporter):
|
|
26
|
-
def __init__(
|
|
27
|
-
|
|
26
|
+
def __init__(
|
|
27
|
+
self, interval: float, logger: Loggable, level: int, _type: ReportingType, clear_registry_on_exit: bool = False
|
|
28
|
+
) -> None:
|
|
29
|
+
super().__init__(interval, clear_registry_on_exit)
|
|
28
30
|
|
|
29
31
|
self.logger = logger
|
|
30
32
|
self.level = level
|
|
@@ -4,14 +4,16 @@ from types import TracebackType
|
|
|
4
4
|
|
|
5
5
|
import threading
|
|
6
6
|
|
|
7
|
+
from pylemetry import registry
|
|
7
8
|
from pylemetry.meters import Counter, Gauge, Timer, Meter
|
|
8
9
|
|
|
9
10
|
|
|
10
11
|
class Reporter:
|
|
11
|
-
def __init__(self, interval: float):
|
|
12
|
+
def __init__(self, interval: float, clear_registry_on_exit: bool = False) -> None:
|
|
12
13
|
self.interval = interval
|
|
13
14
|
self.__timer_thread: Optional[threading.Timer] = None
|
|
14
15
|
self.running = False
|
|
16
|
+
self.clear_registry_on_exit = clear_registry_on_exit
|
|
15
17
|
|
|
16
18
|
def __enter__(self) -> Self:
|
|
17
19
|
self.start()
|
|
@@ -23,6 +25,9 @@ class Reporter:
|
|
|
23
25
|
):
|
|
24
26
|
self.stop()
|
|
25
27
|
|
|
28
|
+
if self.clear_registry_on_exit:
|
|
29
|
+
registry.clear()
|
|
30
|
+
|
|
26
31
|
def flush(self) -> None:
|
|
27
32
|
"""
|
|
28
33
|
Flush all meter values in the registry. If the reporter is configured using `ReporterType.INTERVAL`, this will
|
|
@@ -51,6 +51,25 @@ def test_reporter_context_manager(caplog) -> None:
|
|
|
51
51
|
assert caplog.records[0].msg == "test_counter - 1.0"
|
|
52
52
|
|
|
53
53
|
|
|
54
|
+
def test_reporter_context_manager_clear_registry_on_exit(caplog) -> None:
|
|
55
|
+
logger = logging.getLogger(__name__)
|
|
56
|
+
|
|
57
|
+
counter = Counter()
|
|
58
|
+
counter += 1
|
|
59
|
+
|
|
60
|
+
registry.add_counter("test_counter", counter)
|
|
61
|
+
|
|
62
|
+
with LoggingReporter(0.1, logger, logging.INFO, ReportingType.CUMULATIVE):
|
|
63
|
+
counter += 1
|
|
64
|
+
|
|
65
|
+
assert registry.get_counter("test_counter") == counter
|
|
66
|
+
|
|
67
|
+
with LoggingReporter(0.1, logger, logging.INFO, ReportingType.CUMULATIVE, clear_registry_on_exit=True):
|
|
68
|
+
counter += 1
|
|
69
|
+
|
|
70
|
+
assert registry.get_counter("test_counter") is None
|
|
71
|
+
|
|
72
|
+
|
|
54
73
|
def test_message_format_counter() -> None:
|
|
55
74
|
message_format = (
|
|
56
75
|
"{{'name': '{name}', 'type': '{type}', 'value': {value}, 'min': {min}, 'max': {max}, 'average': {avg}}}"
|
|
@@ -257,8 +257,11 @@ wheels = [
|
|
|
257
257
|
|
|
258
258
|
[[package]]
|
|
259
259
|
name = "pylemetry"
|
|
260
|
-
version = "1.1.
|
|
260
|
+
version = "1.1.4"
|
|
261
261
|
source = { editable = "." }
|
|
262
|
+
dependencies = [
|
|
263
|
+
{ name = "typing-extensions" },
|
|
264
|
+
]
|
|
262
265
|
|
|
263
266
|
[package.dev-dependencies]
|
|
264
267
|
dev = [
|
|
@@ -272,6 +275,7 @@ dev = [
|
|
|
272
275
|
]
|
|
273
276
|
|
|
274
277
|
[package.metadata]
|
|
278
|
+
requires-dist = [{ name = "typing-extensions", specifier = ">=4.15.0" }]
|
|
275
279
|
|
|
276
280
|
[package.metadata.requires-dev]
|
|
277
281
|
dev = [
|
|
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
|
|
File without changes
|
|
File without changes
|