pipen-poplog 0.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.
- pipen_poplog-0.0.0/LICENSE +21 -0
- pipen_poplog-0.0.0/PKG-INFO +79 -0
- pipen_poplog-0.0.0/README.md +58 -0
- pipen_poplog-0.0.0/pipen_poplog.py +109 -0
- pipen_poplog-0.0.0/pyproject.toml +35 -0
- pipen_poplog-0.0.0/setup.py +29 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 pwwang
|
|
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.
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: pipen-poplog
|
|
3
|
+
Version: 0.0.0
|
|
4
|
+
Summary: Populate logs from jobs to running log of the pipeline
|
|
5
|
+
Home-page: https://github.com/pwwang/pipen-poplog
|
|
6
|
+
License: MIT
|
|
7
|
+
Author: pwwang
|
|
8
|
+
Author-email: pwwang@pwwang.com
|
|
9
|
+
Requires-Python: >=3.8,<4.0
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Requires-Dist: pipen (>=0.13,<0.14)
|
|
18
|
+
Project-URL: Repository, https://github.com/pwwang/pipen-poplog
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
|
|
21
|
+
# pipen-poplog
|
|
22
|
+
|
|
23
|
+
Populate logs from jobs to running log of the pipeline
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
pip install -U pipen-poplog
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Enabling/Disabling the plugin
|
|
32
|
+
|
|
33
|
+
The plugin is registered via entrypoints. It's by default enabled. To disable it:
|
|
34
|
+
`plugins=[..., "no:log2file"]`, or uninstall this plugin.
|
|
35
|
+
|
|
36
|
+
## Usage
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
from pipen import Proc, Pipen
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class Poplog(Proc):
|
|
43
|
+
input = "var:var"
|
|
44
|
+
input_data = [0, 1, 2]
|
|
45
|
+
script = """
|
|
46
|
+
echo -n "[PIPEN-POPLOG][INFO] Log message "
|
|
47
|
+
sleep 1 # Simulate message not read in time
|
|
48
|
+
echo "by {{in.var}} 1"
|
|
49
|
+
sleep 1
|
|
50
|
+
echo "[PIPEN-POPLOG][ERROR] Log message by {{in.var}} 2"
|
|
51
|
+
sleep 1
|
|
52
|
+
echo "[PIPEN-POPLOG][INFO] Log message by {{in.var}} 3"
|
|
53
|
+
"""
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
if __name__ == "__main__":
|
|
57
|
+
Pipen().run()
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
```
|
|
61
|
+
01-12 11:23:52 I core ╭═══════════════ PoplogDefault ═════════════════╮
|
|
62
|
+
01-12 11:23:52 I core ║ A default poplog proc ║
|
|
63
|
+
01-12 11:23:52 I core ╰═══════════════════════════════════════════════╯
|
|
64
|
+
01-12 11:23:52 I core PoplogDefault: Workdir: '.pipen/Pipeline/PoplogDefault'
|
|
65
|
+
01-12 11:23:52 I core PoplogDefault: <<< [START]
|
|
66
|
+
01-12 11:23:52 I core PoplogDefault: >>> [END]
|
|
67
|
+
01-12 11:23:56 I poplog PoplogDefault: [0/2] Log message by 0 1
|
|
68
|
+
01-12 11:23:59 E poplog PoplogDefault: [0/2] Log message by 0 2
|
|
69
|
+
01-12 11:24:02 I poplog PoplogDefault: [0/2] Log message by 0 3
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Configuration
|
|
73
|
+
|
|
74
|
+
- `plugin_opts.poplog_loglevel`: The log level for poplog. Default: `info`.
|
|
75
|
+
- `plugin_opts.poplog_pattern`: The pattern to match the log message. Default: `r'\[PIPEN-POPLOG\]\[(?P<level>\w+)\] (?P<message>.*)'`.
|
|
76
|
+
- `plugin_opts.poplog_jobs`: The job indices to be populated. Default: `[0]` (the first job).
|
|
77
|
+
- `plugin_opts.poplog_max`: The max number of the log message to be poplutated for each job. Default: `99`.
|
|
78
|
+
- `plugin_opts.poplog_source`: The source of the log message. Default: `stdout`.
|
|
79
|
+
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# pipen-poplog
|
|
2
|
+
|
|
3
|
+
Populate logs from jobs to running log of the pipeline
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install -U pipen-poplog
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Enabling/Disabling the plugin
|
|
12
|
+
|
|
13
|
+
The plugin is registered via entrypoints. It's by default enabled. To disable it:
|
|
14
|
+
`plugins=[..., "no:log2file"]`, or uninstall this plugin.
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
```python
|
|
19
|
+
from pipen import Proc, Pipen
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class Poplog(Proc):
|
|
23
|
+
input = "var:var"
|
|
24
|
+
input_data = [0, 1, 2]
|
|
25
|
+
script = """
|
|
26
|
+
echo -n "[PIPEN-POPLOG][INFO] Log message "
|
|
27
|
+
sleep 1 # Simulate message not read in time
|
|
28
|
+
echo "by {{in.var}} 1"
|
|
29
|
+
sleep 1
|
|
30
|
+
echo "[PIPEN-POPLOG][ERROR] Log message by {{in.var}} 2"
|
|
31
|
+
sleep 1
|
|
32
|
+
echo "[PIPEN-POPLOG][INFO] Log message by {{in.var}} 3"
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
if __name__ == "__main__":
|
|
37
|
+
Pipen().run()
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
01-12 11:23:52 I core ╭═══════════════ PoplogDefault ═════════════════╮
|
|
42
|
+
01-12 11:23:52 I core ║ A default poplog proc ║
|
|
43
|
+
01-12 11:23:52 I core ╰═══════════════════════════════════════════════╯
|
|
44
|
+
01-12 11:23:52 I core PoplogDefault: Workdir: '.pipen/Pipeline/PoplogDefault'
|
|
45
|
+
01-12 11:23:52 I core PoplogDefault: <<< [START]
|
|
46
|
+
01-12 11:23:52 I core PoplogDefault: >>> [END]
|
|
47
|
+
01-12 11:23:56 I poplog PoplogDefault: [0/2] Log message by 0 1
|
|
48
|
+
01-12 11:23:59 E poplog PoplogDefault: [0/2] Log message by 0 2
|
|
49
|
+
01-12 11:24:02 I poplog PoplogDefault: [0/2] Log message by 0 3
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Configuration
|
|
53
|
+
|
|
54
|
+
- `plugin_opts.poplog_loglevel`: The log level for poplog. Default: `info`.
|
|
55
|
+
- `plugin_opts.poplog_pattern`: The pattern to match the log message. Default: `r'\[PIPEN-POPLOG\]\[(?P<level>\w+)\] (?P<message>.*)'`.
|
|
56
|
+
- `plugin_opts.poplog_jobs`: The job indices to be populated. Default: `[0]` (the first job).
|
|
57
|
+
- `plugin_opts.poplog_max`: The max number of the log message to be poplutated for each job. Default: `99`.
|
|
58
|
+
- `plugin_opts.poplog_source`: The source of the log message. Default: `stdout`.
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"""Populate logs from stdout/stderr to pipen runnning logs"""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
from typing import TYPE_CHECKING
|
|
4
|
+
|
|
5
|
+
import re
|
|
6
|
+
from pipen.pluginmgr import plugin
|
|
7
|
+
from pipen.utils import get_logger
|
|
8
|
+
|
|
9
|
+
if TYPE_CHECKING:
|
|
10
|
+
from pipen import Pipen, Proc
|
|
11
|
+
from pipen.job import Job
|
|
12
|
+
|
|
13
|
+
__version__ = "0.0.0"
|
|
14
|
+
PATTERN = r'\[PIPEN-POPLOG\]\[(?P<level>\w+?)\] (?P<message>.*)'
|
|
15
|
+
logger = get_logger("poplog")
|
|
16
|
+
levels = {"warn": "warning"}
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class PipenPoplogPlugin:
|
|
20
|
+
"""Populate logs from stdout/stderr to pipen runnning logs"""
|
|
21
|
+
name = "poplog"
|
|
22
|
+
priority = -1
|
|
23
|
+
__version__: str = __version__
|
|
24
|
+
|
|
25
|
+
def __init__(self) -> None:
|
|
26
|
+
self.handlers = {}
|
|
27
|
+
self.residules = {}
|
|
28
|
+
|
|
29
|
+
def _poplog(self, proc: Proc, job: Job, end: bool = False):
|
|
30
|
+
if job.index not in proc.plugin_opts.poplog_jobs:
|
|
31
|
+
return
|
|
32
|
+
|
|
33
|
+
if proc.plugin_opts.poplog_source == "stdout":
|
|
34
|
+
source = job.stdout_file
|
|
35
|
+
else:
|
|
36
|
+
source = job.stderr_file
|
|
37
|
+
|
|
38
|
+
poplog_pattern = proc.plugin_opts.get("poplog_pattern", PATTERN)
|
|
39
|
+
poplog_max = proc.plugin_opts.get("poplog_max", 99)
|
|
40
|
+
poplog_pattern = re.compile(poplog_pattern)
|
|
41
|
+
|
|
42
|
+
if job.index not in self.handlers:
|
|
43
|
+
self.handlers[job.index] = open(source, "r")
|
|
44
|
+
self.residules[job.index] = ""
|
|
45
|
+
|
|
46
|
+
handler = self.handlers[job.index]
|
|
47
|
+
handler.flush()
|
|
48
|
+
residue = self.residules[job.index]
|
|
49
|
+
content = residue + handler.read()
|
|
50
|
+
has_residue = content.endswith("\n")
|
|
51
|
+
lines = content.splitlines()
|
|
52
|
+
if has_residue or not lines:
|
|
53
|
+
self.residules[job.index] = ""
|
|
54
|
+
else:
|
|
55
|
+
self.residules[job.index] = lines.pop(-1)
|
|
56
|
+
for line in lines:
|
|
57
|
+
match = poplog_pattern.match(line)
|
|
58
|
+
if not match:
|
|
59
|
+
continue
|
|
60
|
+
level = match.group("level").lower()
|
|
61
|
+
level = levels.get(level, level)
|
|
62
|
+
msg = match.group("message").rstrip()
|
|
63
|
+
job.log(level, msg, limit=poplog_max, logger=logger)
|
|
64
|
+
|
|
65
|
+
@plugin.impl
|
|
66
|
+
async def on_init(self, pipen: Pipen):
|
|
67
|
+
"""Initialize the options"""
|
|
68
|
+
# default options
|
|
69
|
+
pipen.config.plugin_opts.poplog_loglevel = "info"
|
|
70
|
+
pipen.config.plugin_opts.poplog_pattern = PATTERN
|
|
71
|
+
pipen.config.plugin_opts.poplog_jobs = [0]
|
|
72
|
+
pipen.config.plugin_opts.poplog_source = "stdout"
|
|
73
|
+
pipen.config.plugin_opts.poplog_max = 99
|
|
74
|
+
|
|
75
|
+
@plugin.impl
|
|
76
|
+
async def on_start(self, pipen: Pipen):
|
|
77
|
+
"""Set the log level"""
|
|
78
|
+
logger.setLevel(pipen.config.plugin_opts.poplog_loglevel.upper())
|
|
79
|
+
|
|
80
|
+
@plugin.impl
|
|
81
|
+
async def on_job_polling(self, proc: Proc, job: Job):
|
|
82
|
+
if proc.plugin_opts.poplog_source == "stdout":
|
|
83
|
+
source = job.stdout_file
|
|
84
|
+
else:
|
|
85
|
+
source = job.stderr_file
|
|
86
|
+
|
|
87
|
+
if source.exists():
|
|
88
|
+
self._poplog(proc, job)
|
|
89
|
+
|
|
90
|
+
@plugin.impl
|
|
91
|
+
async def on_job_succeeded(self, proc: Proc, job: Job):
|
|
92
|
+
self._poplog(proc, job, end=True)
|
|
93
|
+
|
|
94
|
+
@plugin.impl
|
|
95
|
+
async def on_job_failed(self, proc: Proc, job: Job):
|
|
96
|
+
self._poplog(proc, job, end=True)
|
|
97
|
+
|
|
98
|
+
@plugin.impl
|
|
99
|
+
async def on_proc_done(self, proc: Proc, succeeded: bool | str):
|
|
100
|
+
for handler in self.handlers.values():
|
|
101
|
+
try:
|
|
102
|
+
handler.close()
|
|
103
|
+
except Exception:
|
|
104
|
+
pass
|
|
105
|
+
self.handlers.clear()
|
|
106
|
+
self.residules.clear()
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
poplog_plugin = PipenPoplogPlugin()
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
[tool.poetry]
|
|
2
|
+
name = "pipen-poplog"
|
|
3
|
+
version = "0.0.0"
|
|
4
|
+
description = "Populate logs from jobs to running log of the pipeline"
|
|
5
|
+
authors = ["pwwang <pwwang@pwwang.com>"]
|
|
6
|
+
license = "MIT"
|
|
7
|
+
readme = "README.md"
|
|
8
|
+
homepage = "https://github.com/pwwang/pipen-poplog"
|
|
9
|
+
repository = "https://github.com/pwwang/pipen-poplog"
|
|
10
|
+
|
|
11
|
+
[tool.poetry.dependencies]
|
|
12
|
+
python = "^3.8"
|
|
13
|
+
pipen = "^0.13"
|
|
14
|
+
|
|
15
|
+
[tool.poetry.build]
|
|
16
|
+
generate-setup-file = true
|
|
17
|
+
|
|
18
|
+
[build-system]
|
|
19
|
+
requires = ["poetry>=1.0.0"]
|
|
20
|
+
build-backend = "poetry.masonry.api"
|
|
21
|
+
|
|
22
|
+
[tool.poetry.plugins.pipen]
|
|
23
|
+
log2file = "pipen_poplog:poplog_plugin"
|
|
24
|
+
|
|
25
|
+
[tool.mypy]
|
|
26
|
+
ignore_missing_imports = true
|
|
27
|
+
allow_redefinition = true
|
|
28
|
+
disable_error_code = ["attr-defined", "no-redef"]
|
|
29
|
+
show_error_codes = true
|
|
30
|
+
strict_optional = false
|
|
31
|
+
|
|
32
|
+
[tool.black]
|
|
33
|
+
line-length = 88
|
|
34
|
+
target-version = ['py37', 'py38', 'py39', 'py310']
|
|
35
|
+
include = '\.pyi?$'
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
from setuptools import setup
|
|
3
|
+
|
|
4
|
+
modules = \
|
|
5
|
+
['pipen_poplog']
|
|
6
|
+
install_requires = \
|
|
7
|
+
['pipen>=0.13,<0.14']
|
|
8
|
+
|
|
9
|
+
entry_points = \
|
|
10
|
+
{'pipen': ['log2file = pipen_poplog:poplog_plugin']}
|
|
11
|
+
|
|
12
|
+
setup_kwargs = {
|
|
13
|
+
'name': 'pipen-poplog',
|
|
14
|
+
'version': '0.0.0',
|
|
15
|
+
'description': 'Populate logs from jobs to running log of the pipeline',
|
|
16
|
+
'long_description': '# pipen-poplog\n\nPopulate logs from jobs to running log of the pipeline\n\n## Installation\n\n```bash\npip install -U pipen-poplog\n```\n\n## Enabling/Disabling the plugin\n\nThe plugin is registered via entrypoints. It\'s by default enabled. To disable it:\n`plugins=[..., "no:log2file"]`, or uninstall this plugin.\n\n## Usage\n\n```python\nfrom pipen import Proc, Pipen\n\n\nclass Poplog(Proc):\n input = "var:var"\n input_data = [0, 1, 2]\n script = """\n echo -n "[PIPEN-POPLOG][INFO] Log message "\n sleep 1 # Simulate message not read in time\n echo "by {{in.var}} 1"\n sleep 1\n echo "[PIPEN-POPLOG][ERROR] Log message by {{in.var}} 2"\n sleep 1\n echo "[PIPEN-POPLOG][INFO] Log message by {{in.var}} 3"\n """\n\n\nif __name__ == "__main__":\n Pipen().run()\n```\n\n```\n01-12 11:23:52 I core ╭═══════════════ PoplogDefault ═════════════════╮\n01-12 11:23:52 I core ║ A default poplog proc ║\n01-12 11:23:52 I core ╰═══════════════════════════════════════════════╯\n01-12 11:23:52 I core PoplogDefault: Workdir: \'.pipen/Pipeline/PoplogDefault\'\n01-12 11:23:52 I core PoplogDefault: <<< [START]\n01-12 11:23:52 I core PoplogDefault: >>> [END]\n01-12 11:23:56 I poplog PoplogDefault: [0/2] Log message by 0 1\n01-12 11:23:59 E poplog PoplogDefault: [0/2] Log message by 0 2\n01-12 11:24:02 I poplog PoplogDefault: [0/2] Log message by 0 3\n```\n\n## Configuration\n\n- `plugin_opts.poplog_loglevel`: The log level for poplog. Default: `info`.\n- `plugin_opts.poplog_pattern`: The pattern to match the log message. Default: `r\'\\[PIPEN-POPLOG\\]\\[(?P<level>\\w+)\\] (?P<message>.*)\'`.\n- `plugin_opts.poplog_jobs`: The job indices to be populated. Default: `[0]` (the first job).\n- `plugin_opts.poplog_max`: The max number of the log message to be poplutated for each job. Default: `99`.\n- `plugin_opts.poplog_source`: The source of the log message. Default: `stdout`.\n',
|
|
17
|
+
'author': 'pwwang',
|
|
18
|
+
'author_email': 'pwwang@pwwang.com',
|
|
19
|
+
'maintainer': 'None',
|
|
20
|
+
'maintainer_email': 'None',
|
|
21
|
+
'url': 'https://github.com/pwwang/pipen-poplog',
|
|
22
|
+
'py_modules': modules,
|
|
23
|
+
'install_requires': install_requires,
|
|
24
|
+
'entry_points': entry_points,
|
|
25
|
+
'python_requires': '>=3.8,<4.0',
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
setup(**setup_kwargs)
|