obkit 0.0.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.
- obkit-0.0.1/LICENSE +21 -0
- obkit-0.0.1/PKG-INFO +96 -0
- obkit-0.0.1/README.md +42 -0
- obkit-0.0.1/obkit/__init__.py +0 -0
- obkit-0.0.1/obkit/logger/__init__.py +63 -0
- obkit-0.0.1/obkit/prof/__init__.py +2 -0
- obkit-0.0.1/obkit.egg-info/PKG-INFO +96 -0
- obkit-0.0.1/obkit.egg-info/SOURCES.txt +13 -0
- obkit-0.0.1/obkit.egg-info/dependency_links.txt +1 -0
- obkit-0.0.1/obkit.egg-info/requires.txt +4 -0
- obkit-0.0.1/obkit.egg-info/top_level.txt +1 -0
- obkit-0.0.1/pyproject.toml +45 -0
- obkit-0.0.1/setup.cfg +4 -0
- obkit-0.0.1/tests/test_emit.py +53 -0
- obkit-0.0.1/tests/test_init.py +38 -0
obkit-0.0.1/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Omnibenchmark Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
obkit-0.0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: obkit
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Utility toolkit for omnibenchmark modules and Snakemake workflows
|
|
5
|
+
Author: Omnibenchmark Contributors
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2026 Omnibenchmark Contributors
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Project-URL: Homepage, https://omnibenchmark.org
|
|
29
|
+
Project-URL: Repository, https://github.com/omnibenchmark/obkit
|
|
30
|
+
Project-URL: Issues, https://github.com/omnibenchmark/obkit/issues
|
|
31
|
+
Keywords: omnibenchmark,snakemake,benchmarking,logging,profiling
|
|
32
|
+
Classifier: Development Status :: 3 - Alpha
|
|
33
|
+
Classifier: Intended Audience :: Science/Research
|
|
34
|
+
Classifier: Intended Audience :: Developers
|
|
35
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
36
|
+
Classifier: Operating System :: OS Independent
|
|
37
|
+
Classifier: Programming Language :: Python :: 3
|
|
38
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
39
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
40
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
41
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
42
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
43
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
44
|
+
Classifier: Topic :: Scientific/Engineering
|
|
45
|
+
Classifier: Topic :: System :: Logging
|
|
46
|
+
Classifier: Typing :: Typed
|
|
47
|
+
Requires-Python: >=3.9
|
|
48
|
+
Description-Content-Type: text/markdown
|
|
49
|
+
License-File: LICENSE
|
|
50
|
+
Provides-Extra: dev
|
|
51
|
+
Requires-Dist: pytest>=7; extra == "dev"
|
|
52
|
+
Requires-Dist: ruff>=0.6; extra == "dev"
|
|
53
|
+
Dynamic: license-file
|
|
54
|
+
|
|
55
|
+
# obkit
|
|
56
|
+
|
|
57
|
+
Utility toolkit for [omnibenchmark](https://omnibenchmark.org) modules and
|
|
58
|
+
Snakemake workflows. Pure stdlib, zero runtime dependencies.
|
|
59
|
+
|
|
60
|
+
The R implementation lives in the same repository under `r/obkit`.
|
|
61
|
+
|
|
62
|
+
## Install
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
pip install obkit
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Modules
|
|
69
|
+
|
|
70
|
+
| module | purpose |
|
|
71
|
+
|---------------|---------|
|
|
72
|
+
| `obkit.logger` | Structured JSONL lifecycle event logging — drop phase-boundary anchors into a log file so downstream tooling can attribute profiler samples to named phases of a rule. |
|
|
73
|
+
| `obkit.prof` | Parse and align profiler output (denet, Snakemake bench files) with logger events for per-phase resource attribution. *(in progress)* |
|
|
74
|
+
|
|
75
|
+
## Usage
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
from obkit.logger import init_logger, emit
|
|
79
|
+
|
|
80
|
+
init_logger("/path/to/logdir")
|
|
81
|
+
emit("align", "start")
|
|
82
|
+
# ... do work ...
|
|
83
|
+
emit("align", "end", attrs={"reads": 12345})
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Events are written to `omnibench-events.jsonl` inside the directory passed to
|
|
87
|
+
`init_logger`. See the [wire format spec](https://github.com/omnibenchmark/obkit/blob/main/docs/spec-logger.md)
|
|
88
|
+
for the record schema.
|
|
89
|
+
|
|
90
|
+
## Status
|
|
91
|
+
|
|
92
|
+
v0.1, pre-release. Wire format is stable; API may still shift.
|
|
93
|
+
|
|
94
|
+
## License
|
|
95
|
+
|
|
96
|
+
MIT — see [LICENSE](LICENSE).
|
obkit-0.0.1/README.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# obkit
|
|
2
|
+
|
|
3
|
+
Utility toolkit for [omnibenchmark](https://omnibenchmark.org) modules and
|
|
4
|
+
Snakemake workflows. Pure stdlib, zero runtime dependencies.
|
|
5
|
+
|
|
6
|
+
The R implementation lives in the same repository under `r/obkit`.
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
pip install obkit
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Modules
|
|
15
|
+
|
|
16
|
+
| module | purpose |
|
|
17
|
+
|---------------|---------|
|
|
18
|
+
| `obkit.logger` | Structured JSONL lifecycle event logging — drop phase-boundary anchors into a log file so downstream tooling can attribute profiler samples to named phases of a rule. |
|
|
19
|
+
| `obkit.prof` | Parse and align profiler output (denet, Snakemake bench files) with logger events for per-phase resource attribution. *(in progress)* |
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
from obkit.logger import init_logger, emit
|
|
25
|
+
|
|
26
|
+
init_logger("/path/to/logdir")
|
|
27
|
+
emit("align", "start")
|
|
28
|
+
# ... do work ...
|
|
29
|
+
emit("align", "end", attrs={"reads": 12345})
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Events are written to `omnibench-events.jsonl` inside the directory passed to
|
|
33
|
+
`init_logger`. See the [wire format spec](https://github.com/omnibenchmark/obkit/blob/main/docs/spec-logger.md)
|
|
34
|
+
for the record schema.
|
|
35
|
+
|
|
36
|
+
## Status
|
|
37
|
+
|
|
38
|
+
v0.1, pre-release. Wire format is stable; API may still shift.
|
|
39
|
+
|
|
40
|
+
## License
|
|
41
|
+
|
|
42
|
+
MIT — see [LICENSE](LICENSE).
|
|
File without changes
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import os
|
|
3
|
+
import socket
|
|
4
|
+
import sys
|
|
5
|
+
from datetime import datetime, timezone
|
|
6
|
+
|
|
7
|
+
_state = {
|
|
8
|
+
"log_file": None,
|
|
9
|
+
"warned_uninit": False,
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def init_logger(path):
|
|
14
|
+
if not isinstance(path, str) or not path:
|
|
15
|
+
raise ValueError("init_logger(): 'path' must be a non-empty string")
|
|
16
|
+
os.makedirs(path, exist_ok=True)
|
|
17
|
+
log_file = os.path.join(os.path.realpath(path), "omnibench-events.jsonl")
|
|
18
|
+
_state["log_file"] = log_file
|
|
19
|
+
_state["warned_uninit"] = False
|
|
20
|
+
return log_file
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _iso_ts():
|
|
24
|
+
now = datetime.now(timezone.utc)
|
|
25
|
+
return now.strftime("%Y-%m-%dT%H:%M:%S.") + f"{now.microsecond // 1000:03d}Z"
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def emit(event, phase, attrs=None):
|
|
29
|
+
if not isinstance(event, str) or not event:
|
|
30
|
+
raise ValueError("emit(): 'event' must be a non-empty string")
|
|
31
|
+
if phase not in ("start", "end"):
|
|
32
|
+
raise ValueError('emit(): \'phase\' must be "start" or "end"')
|
|
33
|
+
|
|
34
|
+
log_file = _state["log_file"]
|
|
35
|
+
if log_file is None:
|
|
36
|
+
if not _state["warned_uninit"]:
|
|
37
|
+
print(
|
|
38
|
+
"obkit: emit() called before init_logger(); events discarded.",
|
|
39
|
+
file=sys.stderr,
|
|
40
|
+
)
|
|
41
|
+
_state["warned_uninit"] = True
|
|
42
|
+
return False
|
|
43
|
+
|
|
44
|
+
rec = {
|
|
45
|
+
"ts": _iso_ts(),
|
|
46
|
+
"event": event,
|
|
47
|
+
"phase": phase,
|
|
48
|
+
"pid": os.getpid(),
|
|
49
|
+
"host": socket.gethostname(),
|
|
50
|
+
}
|
|
51
|
+
if attrs is not None:
|
|
52
|
+
if not isinstance(attrs, dict):
|
|
53
|
+
raise ValueError("emit(): 'attrs' must be a dict")
|
|
54
|
+
rec["attrs"] = attrs
|
|
55
|
+
|
|
56
|
+
try:
|
|
57
|
+
line = json.dumps(rec, separators=(",", ":"))
|
|
58
|
+
with open(log_file, "a", encoding="utf-8") as f:
|
|
59
|
+
f.write(line + "\n")
|
|
60
|
+
return True
|
|
61
|
+
except Exception as e:
|
|
62
|
+
print(f"obkit: emit() write failed: {e}", file=sys.stderr)
|
|
63
|
+
return False
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: obkit
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Utility toolkit for omnibenchmark modules and Snakemake workflows
|
|
5
|
+
Author: Omnibenchmark Contributors
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2026 Omnibenchmark Contributors
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Project-URL: Homepage, https://omnibenchmark.org
|
|
29
|
+
Project-URL: Repository, https://github.com/omnibenchmark/obkit
|
|
30
|
+
Project-URL: Issues, https://github.com/omnibenchmark/obkit/issues
|
|
31
|
+
Keywords: omnibenchmark,snakemake,benchmarking,logging,profiling
|
|
32
|
+
Classifier: Development Status :: 3 - Alpha
|
|
33
|
+
Classifier: Intended Audience :: Science/Research
|
|
34
|
+
Classifier: Intended Audience :: Developers
|
|
35
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
36
|
+
Classifier: Operating System :: OS Independent
|
|
37
|
+
Classifier: Programming Language :: Python :: 3
|
|
38
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
39
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
40
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
41
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
42
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
43
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
44
|
+
Classifier: Topic :: Scientific/Engineering
|
|
45
|
+
Classifier: Topic :: System :: Logging
|
|
46
|
+
Classifier: Typing :: Typed
|
|
47
|
+
Requires-Python: >=3.9
|
|
48
|
+
Description-Content-Type: text/markdown
|
|
49
|
+
License-File: LICENSE
|
|
50
|
+
Provides-Extra: dev
|
|
51
|
+
Requires-Dist: pytest>=7; extra == "dev"
|
|
52
|
+
Requires-Dist: ruff>=0.6; extra == "dev"
|
|
53
|
+
Dynamic: license-file
|
|
54
|
+
|
|
55
|
+
# obkit
|
|
56
|
+
|
|
57
|
+
Utility toolkit for [omnibenchmark](https://omnibenchmark.org) modules and
|
|
58
|
+
Snakemake workflows. Pure stdlib, zero runtime dependencies.
|
|
59
|
+
|
|
60
|
+
The R implementation lives in the same repository under `r/obkit`.
|
|
61
|
+
|
|
62
|
+
## Install
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
pip install obkit
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Modules
|
|
69
|
+
|
|
70
|
+
| module | purpose |
|
|
71
|
+
|---------------|---------|
|
|
72
|
+
| `obkit.logger` | Structured JSONL lifecycle event logging — drop phase-boundary anchors into a log file so downstream tooling can attribute profiler samples to named phases of a rule. |
|
|
73
|
+
| `obkit.prof` | Parse and align profiler output (denet, Snakemake bench files) with logger events for per-phase resource attribution. *(in progress)* |
|
|
74
|
+
|
|
75
|
+
## Usage
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
from obkit.logger import init_logger, emit
|
|
79
|
+
|
|
80
|
+
init_logger("/path/to/logdir")
|
|
81
|
+
emit("align", "start")
|
|
82
|
+
# ... do work ...
|
|
83
|
+
emit("align", "end", attrs={"reads": 12345})
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Events are written to `omnibench-events.jsonl` inside the directory passed to
|
|
87
|
+
`init_logger`. See the [wire format spec](https://github.com/omnibenchmark/obkit/blob/main/docs/spec-logger.md)
|
|
88
|
+
for the record schema.
|
|
89
|
+
|
|
90
|
+
## Status
|
|
91
|
+
|
|
92
|
+
v0.1, pre-release. Wire format is stable; API may still shift.
|
|
93
|
+
|
|
94
|
+
## License
|
|
95
|
+
|
|
96
|
+
MIT — see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
obkit/__init__.py
|
|
5
|
+
obkit.egg-info/PKG-INFO
|
|
6
|
+
obkit.egg-info/SOURCES.txt
|
|
7
|
+
obkit.egg-info/dependency_links.txt
|
|
8
|
+
obkit.egg-info/requires.txt
|
|
9
|
+
obkit.egg-info/top_level.txt
|
|
10
|
+
obkit/logger/__init__.py
|
|
11
|
+
obkit/prof/__init__.py
|
|
12
|
+
tests/test_emit.py
|
|
13
|
+
tests/test_init.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
obkit
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "obkit"
|
|
7
|
+
version = "0.0.1"
|
|
8
|
+
description = "Utility toolkit for omnibenchmark modules and Snakemake workflows"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = { file = "LICENSE" }
|
|
11
|
+
requires-python = ">=3.9"
|
|
12
|
+
authors = [{ name = "Omnibenchmark Contributors" }]
|
|
13
|
+
keywords = ["omnibenchmark", "snakemake", "benchmarking", "logging", "profiling"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 3 - Alpha",
|
|
16
|
+
"Intended Audience :: Science/Research",
|
|
17
|
+
"Intended Audience :: Developers",
|
|
18
|
+
"License :: OSI Approved :: MIT License",
|
|
19
|
+
"Operating System :: OS Independent",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
22
|
+
"Programming Language :: Python :: 3.9",
|
|
23
|
+
"Programming Language :: Python :: 3.10",
|
|
24
|
+
"Programming Language :: Python :: 3.11",
|
|
25
|
+
"Programming Language :: Python :: 3.12",
|
|
26
|
+
"Programming Language :: Python :: 3.13",
|
|
27
|
+
"Topic :: Scientific/Engineering",
|
|
28
|
+
"Topic :: System :: Logging",
|
|
29
|
+
"Typing :: Typed",
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
[project.optional-dependencies]
|
|
33
|
+
dev = ["pytest>=7", "ruff>=0.6"]
|
|
34
|
+
|
|
35
|
+
[project.urls]
|
|
36
|
+
Homepage = "https://omnibenchmark.org"
|
|
37
|
+
Repository = "https://github.com/omnibenchmark/obkit"
|
|
38
|
+
Issues = "https://github.com/omnibenchmark/obkit/issues"
|
|
39
|
+
|
|
40
|
+
[tool.setuptools.packages.find]
|
|
41
|
+
include = ["obkit*"]
|
|
42
|
+
exclude = ["tests*"]
|
|
43
|
+
|
|
44
|
+
[tool.pytest.ini_options]
|
|
45
|
+
testpaths = ["tests"]
|
obkit-0.0.1/setup.cfg
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import re
|
|
3
|
+
import tempfile
|
|
4
|
+
|
|
5
|
+
import pytest
|
|
6
|
+
|
|
7
|
+
from obkit.logger import emit, init_logger
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def read_events(log_file):
|
|
11
|
+
with open(log_file) as f:
|
|
12
|
+
return [json.loads(line) for line in f if line.strip()]
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def test_emit_writes_required_fields_in_jsonl():
|
|
16
|
+
with tempfile.TemporaryDirectory() as d:
|
|
17
|
+
log_file = init_logger(d)
|
|
18
|
+
|
|
19
|
+
emit("align", "start")
|
|
20
|
+
emit("align", "end", attrs={"nreads": 12345, "ok": True})
|
|
21
|
+
|
|
22
|
+
events = read_events(log_file)
|
|
23
|
+
assert len(events) == 2
|
|
24
|
+
|
|
25
|
+
ts_pattern = re.compile(r"^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$")
|
|
26
|
+
for e in events:
|
|
27
|
+
assert all(k in e for k in ("ts", "event", "phase", "pid", "host"))
|
|
28
|
+
assert ts_pattern.match(e["ts"])
|
|
29
|
+
assert e["event"] == "align"
|
|
30
|
+
|
|
31
|
+
assert events[0]["phase"] == "start"
|
|
32
|
+
assert events[1]["phase"] == "end"
|
|
33
|
+
assert events[1]["attrs"]["nreads"] == 12345
|
|
34
|
+
assert events[1]["attrs"]["ok"] is True
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def test_emit_validates_phase():
|
|
38
|
+
with tempfile.TemporaryDirectory() as d:
|
|
39
|
+
init_logger(d)
|
|
40
|
+
with pytest.raises(ValueError, match=r"start.*end"):
|
|
41
|
+
emit("x", "begin")
|
|
42
|
+
with pytest.raises(ValueError, match=r"non-empty"):
|
|
43
|
+
emit("", "start")
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def test_emit_appends_across_calls_does_not_truncate():
|
|
47
|
+
with tempfile.TemporaryDirectory() as d:
|
|
48
|
+
log_file = init_logger(d)
|
|
49
|
+
for i in range(5):
|
|
50
|
+
emit(f"e{i}", "start")
|
|
51
|
+
with open(log_file) as f:
|
|
52
|
+
lines = f.readlines()
|
|
53
|
+
assert len(lines) == 5
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import tempfile
|
|
3
|
+
|
|
4
|
+
import pytest
|
|
5
|
+
|
|
6
|
+
from obkit.logger import _state, emit, init_logger
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def test_init_logger_creates_missing_directory_and_returns_log_path():
|
|
10
|
+
with tempfile.TemporaryDirectory() as base:
|
|
11
|
+
d = os.path.join(base, "new-subdir")
|
|
12
|
+
assert not os.path.exists(d)
|
|
13
|
+
p = init_logger(d)
|
|
14
|
+
assert os.path.isdir(d)
|
|
15
|
+
assert os.path.basename(p) == "omnibench-events.jsonl"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def test_init_logger_rejects_bad_input():
|
|
19
|
+
with pytest.raises((ValueError, TypeError)):
|
|
20
|
+
init_logger("")
|
|
21
|
+
with pytest.raises((ValueError, TypeError)):
|
|
22
|
+
init_logger(None)
|
|
23
|
+
with pytest.raises((ValueError, TypeError)):
|
|
24
|
+
init_logger(["a", "b"])
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def test_emit_without_init_warns_once_and_noops(capsys):
|
|
28
|
+
_state["log_file"] = None
|
|
29
|
+
_state["warned_uninit"] = False
|
|
30
|
+
|
|
31
|
+
result = emit("x", "start")
|
|
32
|
+
captured = capsys.readouterr()
|
|
33
|
+
assert "before init_logger" in captured.err
|
|
34
|
+
assert result is False
|
|
35
|
+
|
|
36
|
+
emit("x", "end")
|
|
37
|
+
captured2 = capsys.readouterr()
|
|
38
|
+
assert captured2.err == ""
|