xtr-stopwatch 7.0.0__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.
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 xterr
4
+ Copyright (c) 2004-present Fabien Potencier
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
@@ -0,0 +1,181 @@
1
+ Metadata-Version: 2.4
2
+ Name: xtr-stopwatch
3
+ Version: 7.0.0
4
+ Summary: Times what code does, in named events grouped by category and nested in sections, kept apart for every concurrent unit of work.
5
+ Keywords: stopwatch,timing,profiling,performance,timeline
6
+ Author: Xterr
7
+ Author-email: Xterr <me@xterr.dev>
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Programming Language :: Python :: 3.14
13
+ Classifier: Topic :: Software Development :: Debuggers
14
+ Classifier: Typing :: Typed
15
+ Requires-Dist: xtr-clock>=7.0,<8
16
+ Requires-Python: >=3.14.4
17
+ Description-Content-Type: text/markdown
18
+
19
+ <div align="center">
20
+
21
+ # xtr-stopwatch
22
+
23
+ **Where the time went: named events, grouped by category, nested in sections — one set per unit of work.**
24
+
25
+ <img alt="python 3.14+" src="https://img.shields.io/badge/python-%E2%89%A5%203.14-3776AB?logo=python&logoColor=white">
26
+ <img alt="typed" src="https://img.shields.io/badge/typed-ty%20%2B%20basedpyright-1f6feb">
27
+ <img alt="license MIT" src="https://img.shields.io/badge/license-MIT-blue">
28
+
29
+ </div>
30
+
31
+ ---
32
+
33
+ ## Why?
34
+
35
+ "This request took 400 ms" is a start; "the listeners took 30, the queries 300, and the template
36
+ the rest" is an answer. Getting there takes every piece of work timed under a name, a kind, and
37
+ one shared starting point, so the pieces can be laid side by side on a timeline.
38
+
39
+ - ⏱️ **Events by name.** Start and stop `"load"`; run it three times and it is one event with
40
+ three periods.
41
+ - 🏷️ **Categories.** Each event says what kind of work it is — `"orm"`, `"event_listener"`,
42
+ `"template"` — so a timeline can colour and filter by kind.
43
+ - 🪆 **Sections.** Open one per request: every event in it is measured from the section's own
44
+ origin, and the section is stored under an id once it closes.
45
+ - 🔀 **Concurrent units of work stay apart.** What is timed belongs to the calling context, so
46
+ two requests served at once each see only their own events.
47
+ - 🕰️ **A clock you can freeze.** Readings come from an
48
+ [xtr-clock](../xtr-clock) clock — monotonic by default, a `MockClock` in a test.
49
+
50
+ ## Install
51
+
52
+ ```sh
53
+ uv add xtr-stopwatch
54
+ ```
55
+
56
+ Requires Python 3.14.4+.
57
+
58
+ ## Quick start
59
+
60
+ ```python
61
+ from xtr_stopwatch import Stopwatch
62
+
63
+ stopwatch = Stopwatch()
64
+
65
+ stopwatch.open_section()
66
+ event = stopwatch.start("load-books", "orm")
67
+ ... # the work
68
+ event.stop()
69
+ stopwatch.stop_section("request-42")
70
+
71
+ for name, event in stopwatch.get_section_events("request-42").items():
72
+ print(name, event.category, f"{event.get_duration():.1f} ms")
73
+ ```
74
+
75
+ ## Events
76
+
77
+ `start(name, category=None)` opens a period of the event `name` in the current section and
78
+ returns the event; `stop(name)` closes the period opened last. Starting a running event again
79
+ opens a second, nested period. `lap(name)` closes one period and opens the next at the same
80
+ instant.
81
+
82
+ Keep the event `start` returns and stop *it* when the code that started it is the code that
83
+ ends it: the object stays the same even if the context is [reset](#units-of-work) in between,
84
+ so its period still closes.
85
+
86
+ | `StopwatchEvent` | Answers |
87
+ |---|---|
88
+ | `name`, `category`, `origin` | what it is called, what kind of work it is (`"default"` when none was given), the instant its readings count from — milliseconds since the epoch |
89
+ | `get_periods()` | every closed period: `start`, `end`, `duration`, in milliseconds from `origin` |
90
+ | `get_start_time()`, `get_end_time()` | when it first began, when its last closed period ended |
91
+ | `get_duration()` | the time spent in every period, open ones counted up to now |
92
+ | `is_started()`, `ensure_stopped()` | whether a period is open; close every open one |
93
+ | `to_dict()` | all of the above as plain data, for JSON |
94
+
95
+ ## Sections
96
+
97
+ `open_section()` opens a section inside the current one; `stop_section(section_id)` closes the
98
+ current section and stores it under `section_id`, after which
99
+ `get_section_events(section_id)` returns its events by name. The events of a section all count
100
+ from the instant it opened, which is what puts them on one axis.
101
+
102
+ Opening a section starts `SECTION_EVENT` (`"__section__"`) in it and `SECTION_CHILD_EVENT`
103
+ (`"__section__.child"`, category `"section"`) in its parent, and closing it stops both — the
104
+ section's own duration is one of its events, and the parent records where the child sat in its
105
+ own time. `open_section(section_id)` reopens a stopped child of the current section, adding a
106
+ period to it.
107
+
108
+ Outside any section, events go to the root section, stored as `ROOT` (`"__root__"`), whose
109
+ events each count from the instant they first started.
110
+
111
+ `has_open_section()` tells whether the calling context has a section open, without starting
112
+ anything. Code that times what it does on a stopwatch it shares — every listener a dispatcher
113
+ runs — asks it first, so a context no unit of work times in, a worker's own loop, never
114
+ accumulates events.
115
+
116
+ ## Units of work
117
+
118
+ Everything a stopwatch times belongs to the calling context — the same `contextvars` mechanism
119
+ that keeps a server's concurrent requests apart — so
120
+ one stopwatch shared by a whole application gives every request only its own sections. Code
121
+ run in a copy of that context, such as a synchronous function a worker thread runs, times into
122
+ the same sections.
123
+
124
+ `reset()` starts the calling context afresh, with nothing timed. A unit of work calls it as it
125
+ begins; other contexts are untouched.
126
+
127
+ ## Testing
128
+
129
+ Freeze time with [xtr-clock](../xtr-clock)'s `MockClock` and move it with `sleep`:
130
+
131
+ ```python
132
+ from xtr_clock import MockClock
133
+ from xtr_stopwatch import Stopwatch
134
+
135
+ clock = MockClock("2026-01-01 00:00:00")
136
+ stopwatch = Stopwatch(clock)
137
+
138
+ stopwatch.start("load")
139
+ clock.sleep(0.004)
140
+ assert stopwatch.stop("load").get_duration() == 4.0
141
+ ```
142
+
143
+ ## Errors
144
+
145
+ Everything this library raises derives from `StopwatchError`.
146
+
147
+ | Error | Raised when |
148
+ |---|---|
149
+ | `EventNotStartedError` | an event is stopped or lapped while it is not running |
150
+ | `UnknownEventError` | `get_event` names an event the current section never started; also a `LookupError` |
151
+ | `NoStartedSectionError` | `stop_section` is called with only the root open |
152
+ | `UnknownSectionError` | `open_section(section_id)` names no child of the current section; also a `LookupError` |
153
+
154
+ ## Layout
155
+
156
+ ```
157
+ xtr_stopwatch/
158
+ ├── stopwatch.py Stopwatch, the sections of the calling context
159
+ ├── section.py Section, the events sharing one origin
160
+ ├── stopwatch_event.py StopwatchEvent, one named thing and its periods
161
+ ├── stopwatch_period.py StopwatchPeriod, one start and its stop
162
+ └── exception/ StopwatchError, the root of everything this library raises
163
+ ```
164
+
165
+ ## Development
166
+
167
+ Developed in the [python-xtr](https://github.com/xterr/python-xtr) monorepo, under
168
+ `packages/xtr-stopwatch`; run the commands below from there.
169
+
170
+ ```sh
171
+ uv sync
172
+ uv run ruff check
173
+ uv run ruff format --check
174
+ uv run basedpyright
175
+ uv run ty check
176
+ uv run pytest
177
+ ```
178
+
179
+ ## License
180
+
181
+ MIT — see [LICENSE](LICENSE).
@@ -0,0 +1,163 @@
1
+ <div align="center">
2
+
3
+ # xtr-stopwatch
4
+
5
+ **Where the time went: named events, grouped by category, nested in sections — one set per unit of work.**
6
+
7
+ <img alt="python 3.14+" src="https://img.shields.io/badge/python-%E2%89%A5%203.14-3776AB?logo=python&logoColor=white">
8
+ <img alt="typed" src="https://img.shields.io/badge/typed-ty%20%2B%20basedpyright-1f6feb">
9
+ <img alt="license MIT" src="https://img.shields.io/badge/license-MIT-blue">
10
+
11
+ </div>
12
+
13
+ ---
14
+
15
+ ## Why?
16
+
17
+ "This request took 400 ms" is a start; "the listeners took 30, the queries 300, and the template
18
+ the rest" is an answer. Getting there takes every piece of work timed under a name, a kind, and
19
+ one shared starting point, so the pieces can be laid side by side on a timeline.
20
+
21
+ - ⏱️ **Events by name.** Start and stop `"load"`; run it three times and it is one event with
22
+ three periods.
23
+ - 🏷️ **Categories.** Each event says what kind of work it is — `"orm"`, `"event_listener"`,
24
+ `"template"` — so a timeline can colour and filter by kind.
25
+ - 🪆 **Sections.** Open one per request: every event in it is measured from the section's own
26
+ origin, and the section is stored under an id once it closes.
27
+ - 🔀 **Concurrent units of work stay apart.** What is timed belongs to the calling context, so
28
+ two requests served at once each see only their own events.
29
+ - 🕰️ **A clock you can freeze.** Readings come from an
30
+ [xtr-clock](../xtr-clock) clock — monotonic by default, a `MockClock` in a test.
31
+
32
+ ## Install
33
+
34
+ ```sh
35
+ uv add xtr-stopwatch
36
+ ```
37
+
38
+ Requires Python 3.14.4+.
39
+
40
+ ## Quick start
41
+
42
+ ```python
43
+ from xtr_stopwatch import Stopwatch
44
+
45
+ stopwatch = Stopwatch()
46
+
47
+ stopwatch.open_section()
48
+ event = stopwatch.start("load-books", "orm")
49
+ ... # the work
50
+ event.stop()
51
+ stopwatch.stop_section("request-42")
52
+
53
+ for name, event in stopwatch.get_section_events("request-42").items():
54
+ print(name, event.category, f"{event.get_duration():.1f} ms")
55
+ ```
56
+
57
+ ## Events
58
+
59
+ `start(name, category=None)` opens a period of the event `name` in the current section and
60
+ returns the event; `stop(name)` closes the period opened last. Starting a running event again
61
+ opens a second, nested period. `lap(name)` closes one period and opens the next at the same
62
+ instant.
63
+
64
+ Keep the event `start` returns and stop *it* when the code that started it is the code that
65
+ ends it: the object stays the same even if the context is [reset](#units-of-work) in between,
66
+ so its period still closes.
67
+
68
+ | `StopwatchEvent` | Answers |
69
+ |---|---|
70
+ | `name`, `category`, `origin` | what it is called, what kind of work it is (`"default"` when none was given), the instant its readings count from — milliseconds since the epoch |
71
+ | `get_periods()` | every closed period: `start`, `end`, `duration`, in milliseconds from `origin` |
72
+ | `get_start_time()`, `get_end_time()` | when it first began, when its last closed period ended |
73
+ | `get_duration()` | the time spent in every period, open ones counted up to now |
74
+ | `is_started()`, `ensure_stopped()` | whether a period is open; close every open one |
75
+ | `to_dict()` | all of the above as plain data, for JSON |
76
+
77
+ ## Sections
78
+
79
+ `open_section()` opens a section inside the current one; `stop_section(section_id)` closes the
80
+ current section and stores it under `section_id`, after which
81
+ `get_section_events(section_id)` returns its events by name. The events of a section all count
82
+ from the instant it opened, which is what puts them on one axis.
83
+
84
+ Opening a section starts `SECTION_EVENT` (`"__section__"`) in it and `SECTION_CHILD_EVENT`
85
+ (`"__section__.child"`, category `"section"`) in its parent, and closing it stops both — the
86
+ section's own duration is one of its events, and the parent records where the child sat in its
87
+ own time. `open_section(section_id)` reopens a stopped child of the current section, adding a
88
+ period to it.
89
+
90
+ Outside any section, events go to the root section, stored as `ROOT` (`"__root__"`), whose
91
+ events each count from the instant they first started.
92
+
93
+ `has_open_section()` tells whether the calling context has a section open, without starting
94
+ anything. Code that times what it does on a stopwatch it shares — every listener a dispatcher
95
+ runs — asks it first, so a context no unit of work times in, a worker's own loop, never
96
+ accumulates events.
97
+
98
+ ## Units of work
99
+
100
+ Everything a stopwatch times belongs to the calling context — the same `contextvars` mechanism
101
+ that keeps a server's concurrent requests apart — so
102
+ one stopwatch shared by a whole application gives every request only its own sections. Code
103
+ run in a copy of that context, such as a synchronous function a worker thread runs, times into
104
+ the same sections.
105
+
106
+ `reset()` starts the calling context afresh, with nothing timed. A unit of work calls it as it
107
+ begins; other contexts are untouched.
108
+
109
+ ## Testing
110
+
111
+ Freeze time with [xtr-clock](../xtr-clock)'s `MockClock` and move it with `sleep`:
112
+
113
+ ```python
114
+ from xtr_clock import MockClock
115
+ from xtr_stopwatch import Stopwatch
116
+
117
+ clock = MockClock("2026-01-01 00:00:00")
118
+ stopwatch = Stopwatch(clock)
119
+
120
+ stopwatch.start("load")
121
+ clock.sleep(0.004)
122
+ assert stopwatch.stop("load").get_duration() == 4.0
123
+ ```
124
+
125
+ ## Errors
126
+
127
+ Everything this library raises derives from `StopwatchError`.
128
+
129
+ | Error | Raised when |
130
+ |---|---|
131
+ | `EventNotStartedError` | an event is stopped or lapped while it is not running |
132
+ | `UnknownEventError` | `get_event` names an event the current section never started; also a `LookupError` |
133
+ | `NoStartedSectionError` | `stop_section` is called with only the root open |
134
+ | `UnknownSectionError` | `open_section(section_id)` names no child of the current section; also a `LookupError` |
135
+
136
+ ## Layout
137
+
138
+ ```
139
+ xtr_stopwatch/
140
+ ├── stopwatch.py Stopwatch, the sections of the calling context
141
+ ├── section.py Section, the events sharing one origin
142
+ ├── stopwatch_event.py StopwatchEvent, one named thing and its periods
143
+ ├── stopwatch_period.py StopwatchPeriod, one start and its stop
144
+ └── exception/ StopwatchError, the root of everything this library raises
145
+ ```
146
+
147
+ ## Development
148
+
149
+ Developed in the [python-xtr](https://github.com/xterr/python-xtr) monorepo, under
150
+ `packages/xtr-stopwatch`; run the commands below from there.
151
+
152
+ ```sh
153
+ uv sync
154
+ uv run ruff check
155
+ uv run ruff format --check
156
+ uv run basedpyright
157
+ uv run ty check
158
+ uv run pytest
159
+ ```
160
+
161
+ ## License
162
+
163
+ MIT — see [LICENSE](LICENSE).
@@ -0,0 +1,138 @@
1
+ [project]
2
+ name = "xtr-stopwatch"
3
+ version = "7.0.0"
4
+ description = "Times what code does, in named events grouped by category and nested in sections, kept apart for every concurrent unit of work."
5
+ readme = "README.md"
6
+ requires-python = ">=3.14.4"
7
+ license = "MIT"
8
+ license-files = ["LICENSE"]
9
+ keywords = [
10
+ "stopwatch",
11
+ "timing",
12
+ "profiling",
13
+ "performance",
14
+ "timeline",
15
+ ]
16
+ classifiers = [
17
+ "Development Status :: 3 - Alpha",
18
+ "Intended Audience :: Developers",
19
+ "Programming Language :: Python :: 3.14",
20
+ "Topic :: Software Development :: Debuggers",
21
+ "Typing :: Typed",
22
+ ]
23
+ dependencies = ["xtr-clock>=7.0,<8"]
24
+
25
+ [[project.authors]]
26
+ name = "Xterr"
27
+ email = "me@xterr.dev"
28
+
29
+ [dependency-groups]
30
+ dev = [
31
+ "anyio>=4.10",
32
+ "basedpyright>=1.31.7",
33
+ "ruff>=0.14.7",
34
+ "pytest>=8.4",
35
+ "pytest-cov>=7.1",
36
+ "ty>=0.0.83",
37
+ ]
38
+
39
+ [build-system]
40
+ requires = ["uv_build>=0.9.18,<0.10.0"]
41
+ build-backend = "uv_build"
42
+
43
+ [tool.basedpyright]
44
+ typeCheckingMode = "all"
45
+ pythonVersion = "3.14"
46
+ pythonPlatform = "All"
47
+ include = [
48
+ "src",
49
+ "tests",
50
+ ]
51
+ exclude = [
52
+ "**/__pycache__",
53
+ "**/.venv",
54
+ "**/build",
55
+ "**/dist",
56
+ ".tmp",
57
+ ]
58
+ reportUnusedCallResult = "warning"
59
+ reportUnnecessaryTypeIgnoreComment = "error"
60
+ reportUnusedVariable = "error"
61
+ reportMissingParameterType = "error"
62
+ reportPrivateUsage = "error"
63
+ reportImplicitStringConcatenation = "none"
64
+
65
+ [tool.ruff]
66
+ target-version = "py314"
67
+ line-length = 100
68
+ src = [
69
+ "src",
70
+ "tests",
71
+ ]
72
+
73
+ [tool.ruff.lint]
74
+ select = ["ALL"]
75
+ ignore = [
76
+ "COM812",
77
+ "ISC001",
78
+ "D203",
79
+ "D213",
80
+ "CPY001",
81
+ "FBT001",
82
+ "FBT002",
83
+ "TD002",
84
+ "TD003",
85
+ "FIX002",
86
+ "TRY003",
87
+ "EM101",
88
+ "EM102",
89
+ ]
90
+ fixable = ["ALL"]
91
+ unfixable = []
92
+
93
+ [tool.ruff.lint.per-file-ignores]
94
+ "tests/**/*.py" = [
95
+ "S101",
96
+ "ARG",
97
+ "PLR2004",
98
+ "SLF001",
99
+ "D",
100
+ ]
101
+
102
+ [tool.ruff.lint.pydocstyle]
103
+ convention = "google"
104
+
105
+ [tool.ruff.format]
106
+ quote-style = "double"
107
+ indent-style = "space"
108
+ docstring-code-format = true
109
+ docstring-code-line-length = "dynamic"
110
+
111
+ [tool.ty.src]
112
+ include = [
113
+ "src",
114
+ "tests",
115
+ ]
116
+
117
+ [tool.pytest.ini_options]
118
+ minversion = "8.0"
119
+ testpaths = ["tests"]
120
+ addopts = [
121
+ "-ra",
122
+ "--strict-config",
123
+ "--strict-markers",
124
+ ]
125
+ filterwarnings = ["error"]
126
+
127
+ [tool.coverage.run]
128
+ source = ["src"]
129
+ branch = true
130
+
131
+ [tool.coverage.report]
132
+ fail_under = 97
133
+ exclude_lines = [
134
+ "pragma: no cover",
135
+ "if TYPE_CHECKING:",
136
+ "raise NotImplementedError",
137
+ '^\s*\.\.\.$',
138
+ ]
@@ -0,0 +1,136 @@
1
+ [project]
2
+ name = "xtr-stopwatch"
3
+ version = "7.0.0"
4
+ description = "Times what code does, in named events grouped by category and nested in sections, kept apart for every concurrent unit of work."
5
+ readme = "README.md"
6
+ requires-python = ">=3.14.4"
7
+ license = "MIT"
8
+ license-files = ["LICENSE"]
9
+ authors = [
10
+ { name = "Xterr", email = "me@xterr.dev" }
11
+ ]
12
+ keywords = ["stopwatch", "timing", "profiling", "performance", "timeline"]
13
+ classifiers = [
14
+ "Development Status :: 3 - Alpha",
15
+ "Intended Audience :: Developers",
16
+ "Programming Language :: Python :: 3.14",
17
+ "Topic :: Software Development :: Debuggers",
18
+ "Typing :: Typed",
19
+ ]
20
+ dependencies = [
21
+ "xtr-clock>=7.0,<8",
22
+ ]
23
+
24
+ [dependency-groups]
25
+ dev = [
26
+ "anyio>=4.10",
27
+ "basedpyright>=1.31.7",
28
+ "ruff>=0.14.7",
29
+ "pytest>=8.4",
30
+ "pytest-cov>=7.1",
31
+ "ty>=0.0.83",
32
+ ]
33
+
34
+ [build-system]
35
+ requires = ["uv_build>=0.9.18,<0.10.0"]
36
+ build-backend = "uv_build"
37
+
38
+ # ─────────────────────────────────────────────────────────────────
39
+ # basedpyright — typeCheckingMode = "all" sets every report flag to error
40
+ # ─────────────────────────────────────────────────────────────────
41
+ [tool.basedpyright]
42
+ typeCheckingMode = "all"
43
+ pythonVersion = "3.14"
44
+ pythonPlatform = "All"
45
+ include = ["src", "tests"]
46
+ exclude = ["**/__pycache__", "**/.venv", "**/build", "**/dist", ".tmp"]
47
+
48
+ reportUnusedCallResult = "warning"
49
+ reportUnnecessaryTypeIgnoreComment = "error"
50
+ reportUnusedVariable = "error"
51
+ reportMissingParameterType = "error"
52
+ reportPrivateUsage = "error"
53
+
54
+ # An error message long enough to be useful has to wrap, and a 100-column
55
+ # limit puts the break inside the string.
56
+ reportImplicitStringConcatenation = "none"
57
+
58
+ # ─────────────────────────────────────────────────────────────────
59
+ # ruff — select = ["ALL"], minimal justified ignores
60
+ # ─────────────────────────────────────────────────────────────────
61
+ [tool.ruff]
62
+ target-version = "py314"
63
+ line-length = 100
64
+ src = ["src", "tests"]
65
+
66
+ [tool.ruff.lint]
67
+ select = ["ALL"]
68
+ ignore = [
69
+ # Formatter conflicts (ruff documents these)
70
+ "COM812",
71
+ "ISC001",
72
+ # Mutually-exclusive docstring conventions; keep the modern one
73
+ "D203",
74
+ "D213",
75
+ # Project-specific noise
76
+ "CPY001",
77
+ "FBT001",
78
+ "FBT002",
79
+ "TD002",
80
+ "TD003",
81
+ "FIX002",
82
+ # Exceptions compose their own messages from typed fields; the string at a
83
+ # raise site is a `reason` data field. See xtr_stopwatch/exception/.
84
+ "TRY003",
85
+ "EM101",
86
+ "EM102",
87
+ ]
88
+ fixable = ["ALL"]
89
+ unfixable = []
90
+
91
+ [tool.ruff.lint.per-file-ignores]
92
+ "tests/**/*.py" = [
93
+ "S101", # assert is the point of pytest
94
+ "ARG", # fixtures look unused
95
+ "PLR2004", # magic numbers in test data
96
+ "SLF001", # tests reach into privates
97
+ "D", # test names are the docs
98
+ ]
99
+
100
+ [tool.ruff.lint.pydocstyle]
101
+ convention = "google"
102
+
103
+ [tool.ruff.format]
104
+ quote-style = "double"
105
+ indent-style = "space"
106
+ docstring-code-format = true
107
+ docstring-code-line-length = "dynamic"
108
+
109
+ # ─────────────────────────────────────────────────────────────────
110
+ # ty — a second opinion on the source
111
+ # ─────────────────────────────────────────────────────────────────
112
+ [tool.ty.src]
113
+ include = ["src", "tests"]
114
+
115
+ # ─────────────────────────────────────────────────────────────────
116
+ # pytest
117
+ # ─────────────────────────────────────────────────────────────────
118
+ [tool.pytest.ini_options]
119
+ minversion = "8.0"
120
+ testpaths = ["tests"]
121
+ addopts = ["-ra", "--strict-config", "--strict-markers"]
122
+ filterwarnings = ["error"]
123
+
124
+ [tool.coverage.run]
125
+ source = ["src"]
126
+ branch = true
127
+
128
+ [tool.coverage.report]
129
+ # CI runs the tests with --cov; a change taking coverage below this fails there.
130
+ fail_under = 97
131
+ exclude_lines = [
132
+ "pragma: no cover",
133
+ "if TYPE_CHECKING:",
134
+ "raise NotImplementedError",
135
+ "^\\s*\\.\\.\\.$",
136
+ ]
@@ -0,0 +1,51 @@
1
+ """Times what code does: named events, grouped by category, nested in sections.
2
+
3
+ A profile wants to know where a request spent its time — which listener,
4
+ which query, which template — and on one axis, so the pieces can be drawn
5
+ as a timeline. :class:`~xtr_stopwatch.stopwatch.Stopwatch` records exactly
6
+ that: each event is a name, a category and the periods it ran for, and every
7
+ event of a section is measured from the section's own origin.
8
+
9
+ What is timed belongs to the calling context, so concurrent requests served
10
+ by one process each see only their own events.
11
+ """
12
+
13
+ from __future__ import annotations
14
+
15
+ from importlib.metadata import PackageNotFoundError, version
16
+
17
+ from .exception import (
18
+ EventNotStartedError,
19
+ NoStartedSectionError,
20
+ StopwatchError,
21
+ UnknownEventError,
22
+ UnknownSectionError,
23
+ )
24
+ from .section import Section
25
+ from .stopwatch import ROOT, SECTION_CATEGORY, SECTION_CHILD_EVENT, SECTION_EVENT, Stopwatch
26
+ from .stopwatch_event import StopwatchEvent
27
+ from .stopwatch_period import StopwatchPeriod
28
+
29
+ try:
30
+ __version__ = version("xtr-stopwatch")
31
+ except PackageNotFoundError: # pragma: no cover
32
+ # Running from a source tree or a vendored copy, with no installed
33
+ # metadata to read. Having no version is better than refusing to import.
34
+ __version__ = "0+unknown"
35
+
36
+ __all__ = [
37
+ "ROOT",
38
+ "SECTION_CATEGORY",
39
+ "SECTION_CHILD_EVENT",
40
+ "SECTION_EVENT",
41
+ "EventNotStartedError",
42
+ "NoStartedSectionError",
43
+ "Section",
44
+ "Stopwatch",
45
+ "StopwatchError",
46
+ "StopwatchEvent",
47
+ "StopwatchPeriod",
48
+ "UnknownEventError",
49
+ "UnknownSectionError",
50
+ "__version__",
51
+ ]