promtext-cli 0.2.1.dev7__tar.gz → 0.2.1.dev9__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.
Files changed (20) hide show
  1. {promtext_cli-0.2.1.dev7 → promtext_cli-0.2.1.dev9}/.copier-answers.yml +1 -1
  2. {promtext_cli-0.2.1.dev7 → promtext_cli-0.2.1.dev9}/.forgejo/workflows/commitlint.yaml +2 -2
  3. {promtext_cli-0.2.1.dev7 → promtext_cli-0.2.1.dev9}/.forgejo/workflows/lint.yaml +4 -4
  4. {promtext_cli-0.2.1.dev7 → promtext_cli-0.2.1.dev9}/.forgejo/workflows/publish.yaml +6 -6
  5. {promtext_cli-0.2.1.dev7 → promtext_cli-0.2.1.dev9}/.forgejo/workflows/test.yaml +4 -4
  6. {promtext_cli-0.2.1.dev7 → promtext_cli-0.2.1.dev9}/.pre-commit-config.yaml +1 -1
  7. {promtext_cli-0.2.1.dev7 → promtext_cli-0.2.1.dev9}/PKG-INFO +5 -4
  8. {promtext_cli-0.2.1.dev7 → promtext_cli-0.2.1.dev9}/README.md +4 -3
  9. {promtext_cli-0.2.1.dev7 → promtext_cli-0.2.1.dev9}/promtext_cli/promtext.py +16 -4
  10. {promtext_cli-0.2.1.dev7 → promtext_cli-0.2.1.dev9}/tests/test_functional.py +18 -0
  11. {promtext_cli-0.2.1.dev7 → promtext_cli-0.2.1.dev9}/.commitlintrc.yaml +0 -0
  12. {promtext_cli-0.2.1.dev7 → promtext_cli-0.2.1.dev9}/.gitignore +0 -0
  13. {promtext_cli-0.2.1.dev7 → promtext_cli-0.2.1.dev9}/cliff.toml +0 -0
  14. {promtext_cli-0.2.1.dev7 → promtext_cli-0.2.1.dev9}/promtext_cli/__init__.py +0 -0
  15. {promtext_cli-0.2.1.dev7 → promtext_cli-0.2.1.dev9}/promtext_cli/main.py +0 -0
  16. {promtext_cli-0.2.1.dev7 → promtext_cli-0.2.1.dev9}/pyproject.toml +0 -0
  17. {promtext_cli-0.2.1.dev7 → promtext_cli-0.2.1.dev9}/renovate.json +0 -0
  18. {promtext_cli-0.2.1.dev7 → promtext_cli-0.2.1.dev9}/tests/.gitkeep +0 -0
  19. {promtext_cli-0.2.1.dev7 → promtext_cli-0.2.1.dev9}/tests/test_blackbox.py +0 -0
  20. {promtext_cli-0.2.1.dev7 → promtext_cli-0.2.1.dev9}/uv.lock +0 -0
@@ -1,5 +1,5 @@
1
1
  # Changes here will be overwritten by Copier.
2
- _commit: 0.9.16
2
+ _commit: 0.9.21
3
3
  _src_path: https://codeberg.org/margau/copier-python-uv.git
4
4
  code_dir: promtext_cli
5
5
  container: false
@@ -11,10 +11,10 @@ jobs:
11
11
  commitlint-check:
12
12
  runs-on: docker
13
13
  container:
14
- image: codeberg.org/margau/buildenv-commitlint:latest@sha256:05a8071e9a8239be1224ede0cb24b24810f7d2731ce1bd95dfcb9ae67db9adc9
14
+ image: codeberg.org/margau/buildenv-commitlint:latest@sha256:6dfe15b4a0602b3a8bdaa46e86a00d43f7f6e85b6b1d965649a78b9dd92dda40
15
15
 
16
16
  steps:
17
- - uses: https://code.forgejo.org/actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
17
+ - uses: https://code.forgejo.org/actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
18
18
  with:
19
19
  fetch-depth: 0
20
20
  - name: Validate current commit (last commit) with commitlint
@@ -13,14 +13,14 @@ jobs:
13
13
  env:
14
14
  UV_CACHE_DIR: /tmp/.uv-cache
15
15
  container:
16
- image: codeberg.org/margau/buildenv-uv:latest@sha256:41a740b95c815bda4cc70fe9325a4c6e3c00e65f1a3ec9b979468e6202391dce
16
+ image: codeberg.org/margau/buildenv-uv:latest@sha256:a2559f0d865dbc7d13e82990f6147bd2124129b6e6f3b4d281579834f6ab0a64
17
17
 
18
18
  steps:
19
- - uses: https://code.forgejo.org/actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
19
+ - uses: https://code.forgejo.org/actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
20
20
  with:
21
21
  fetch-depth: 0
22
22
  - name: cache restore
23
- uses: https://code.forgejo.org/actions/cache/restore@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5
23
+ uses: https://code.forgejo.org/actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6
24
24
  with:
25
25
  path: /tmp/.uv-cache
26
26
  key: uv-${{ hashFiles('uv.lock') }}
@@ -38,7 +38,7 @@ jobs:
38
38
  - name: Minimize uv cache
39
39
  run: uv cache prune
40
40
  - name: cache save
41
- uses: https://code.forgejo.org/actions/cache/save@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5
41
+ uses: https://code.forgejo.org/actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6
42
42
  with:
43
43
  path: /tmp/.uv-cache
44
44
  key: uv-${{ hashFiles('uv.lock') }}
@@ -16,14 +16,14 @@ jobs:
16
16
  env:
17
17
  UV_CACHE_DIR: /tmp/.uv-cache
18
18
  container:
19
- image: codeberg.org/margau/buildenv-uv:latest@sha256:41a740b95c815bda4cc70fe9325a4c6e3c00e65f1a3ec9b979468e6202391dce
19
+ image: codeberg.org/margau/buildenv-uv:latest@sha256:a2559f0d865dbc7d13e82990f6147bd2124129b6e6f3b4d281579834f6ab0a64
20
20
 
21
21
  steps:
22
- - uses: https://code.forgejo.org/actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
22
+ - uses: https://code.forgejo.org/actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
23
23
  with:
24
24
  fetch-depth: 0
25
25
  - name: cache restore
26
- uses: https://code.forgejo.org/actions/cache/restore@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5
26
+ uses: https://code.forgejo.org/actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6
27
27
  with:
28
28
  path: /tmp/.uv-cache
29
29
  key: uv-${{ hashFiles('uv.lock') }}
@@ -58,7 +58,7 @@ jobs:
58
58
  - name: Minimize uv cache
59
59
  run: uv cache prune
60
60
  - name: cache save
61
- uses: https://code.forgejo.org/actions/cache/save@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5
61
+ uses: https://code.forgejo.org/actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6
62
62
  with:
63
63
  path: /tmp/.uv-cache
64
64
  key: uv-${{ hashFiles('uv.lock') }}
@@ -67,10 +67,10 @@ jobs:
67
67
  name: "Draft Release Notes"
68
68
  runs-on: docker
69
69
  container:
70
- image: codeberg.org/margau/buildenv-uv:latest@sha256:41a740b95c815bda4cc70fe9325a4c6e3c00e65f1a3ec9b979468e6202391dce
70
+ image: codeberg.org/margau/buildenv-uv:latest@sha256:a2559f0d865dbc7d13e82990f6147bd2124129b6e6f3b4d281579834f6ab0a64
71
71
 
72
72
  steps:
73
- - uses: https://code.forgejo.org/actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
73
+ - uses: https://code.forgejo.org/actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
74
74
  with:
75
75
  fetch-depth: 0
76
76
  - name: draft release notes
@@ -13,14 +13,14 @@ jobs:
13
13
  env:
14
14
  UV_CACHE_DIR: /tmp/.uv-cache
15
15
  container:
16
- image: codeberg.org/margau/buildenv-uv:latest@sha256:41a740b95c815bda4cc70fe9325a4c6e3c00e65f1a3ec9b979468e6202391dce
16
+ image: codeberg.org/margau/buildenv-uv:latest@sha256:a2559f0d865dbc7d13e82990f6147bd2124129b6e6f3b4d281579834f6ab0a64
17
17
 
18
18
  steps:
19
- - uses: https://code.forgejo.org/actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
19
+ - uses: https://code.forgejo.org/actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
20
20
  with:
21
21
  fetch-depth: 0
22
22
  - name: cache restore
23
- uses: https://code.forgejo.org/actions/cache/restore@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5
23
+ uses: https://code.forgejo.org/actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6
24
24
  with:
25
25
  path: /tmp/.uv-cache
26
26
  key: uv-${{ hashFiles('uv.lock') }}
@@ -36,7 +36,7 @@ jobs:
36
36
  - name: Minimize uv cache
37
37
  run: uv cache prune
38
38
  - name: cache save
39
- uses: https://code.forgejo.org/actions/cache/save@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5
39
+ uses: https://code.forgejo.org/actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6
40
40
  with:
41
41
  path: /tmp/.uv-cache
42
42
  key: uv-${{ hashFiles('uv.lock') }}
@@ -10,7 +10,7 @@ repos:
10
10
  stages: [commit-msg]
11
11
  args: []
12
12
  - repo: https://github.com/astral-sh/ruff-pre-commit
13
- rev: v0.15.17
13
+ rev: v0.15.20
14
14
  hooks:
15
15
  # Run the linter.
16
16
  - id: ruff-check
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: promtext-cli
3
- Version: 0.2.1.dev7
3
+ Version: 0.2.1.dev9
4
4
  Summary: Prometheus Textfile Tooling
5
5
  Project-URL: Documentation, https://codeberg.org/margau/promtext-cli/src/branch/main#readme
6
6
  Project-URL: Issues, https://codeberg.org/margau/promtext-cli/issues
@@ -24,13 +24,12 @@ Features:
24
24
 
25
25
  ## Usage
26
26
  ```
27
- promtext -h
28
- usage: main.py [-h] [--docs DOCS] [--label KEY=VALUE] [-v] filename metric value
27
+ usage: promtext [-h] [--docs DOCS] [--label KEY=VALUE] [-v] [filename] metric value
29
28
 
30
29
  Prometheus textfile helper
31
30
 
32
31
  positional arguments:
33
- filename Path to existing or new prometheus textfile, will be updated
32
+ filename optional path to existing or new prometheus textfile (will be created or updated)
34
33
  metric metric name (new or updated)
35
34
  value metric value
36
35
 
@@ -41,6 +40,8 @@ options:
41
40
  -v, --verbose
42
41
  ```
43
42
 
43
+ If the filename is missing, an file named after the metric in `/var/prometheus` (or the directory specificed in the `PROMTEXT_DIR`-ENV) will be used.
44
+
44
45
  ## Examples
45
46
  `tmp/backup.prom` before:
46
47
  ```
@@ -11,13 +11,12 @@ Features:
11
11
 
12
12
  ## Usage
13
13
  ```
14
- promtext -h
15
- usage: main.py [-h] [--docs DOCS] [--label KEY=VALUE] [-v] filename metric value
14
+ usage: promtext [-h] [--docs DOCS] [--label KEY=VALUE] [-v] [filename] metric value
16
15
 
17
16
  Prometheus textfile helper
18
17
 
19
18
  positional arguments:
20
- filename Path to existing or new prometheus textfile, will be updated
19
+ filename optional path to existing or new prometheus textfile (will be created or updated)
21
20
  metric metric name (new or updated)
22
21
  value metric value
23
22
 
@@ -28,6 +27,8 @@ options:
28
27
  -v, --verbose
29
28
  ```
30
29
 
30
+ If the filename is missing, an file named after the metric in `/var/prometheus` (or the directory specificed in the `PROMTEXT_DIR`-ENV) will be used.
31
+
31
32
  ## Examples
32
33
  `tmp/backup.prom` before:
33
34
  ```
@@ -2,6 +2,7 @@
2
2
 
3
3
  import argparse
4
4
  import logging
5
+ import os
5
6
  import sys
6
7
  from pathlib import Path
7
8
 
@@ -26,8 +27,11 @@ class Promtext:
26
27
  parser = argparse.ArgumentParser(description="Prometheus textfile helper")
27
28
  parser.add_argument(
28
29
  "filename",
29
- type=str,
30
- help="Path to existing or new prometheus textfile, will be updated",
30
+ nargs="?",
31
+ default=None,
32
+ type=Path,
33
+ help="""optional path to existing or new prometheus textfile
34
+ (will be created or updated)""",
31
35
  )
32
36
 
33
37
  # metric name, required
@@ -62,8 +66,15 @@ class Promtext:
62
66
  )
63
67
  self.args = parser.parse_args()
64
68
 
65
- # processing: check if file is available, if yes, parse
66
- self.textfile = Path(self.args.filename)
69
+ def _config(self):
70
+ # figure out which file name to use
71
+ if self.args.filename:
72
+ self.textfile = self.args.filename
73
+ else:
74
+ self.textfile = Path(os.getenv("PROMTEXT_DIR", "/var/prometheus")) / Path(
75
+ self.args.metric + ".prom"
76
+ )
77
+ self.logger.info("using default filename %s", self.textfile)
67
78
 
68
79
  def parse_file(self):
69
80
  """If possible, convert the input textfile to metrics in the registry"""
@@ -179,6 +190,7 @@ class Promtext:
179
190
  logging.basicConfig(level=self.args.loglevel)
180
191
  self.logger = logging.getLogger(__name__)
181
192
 
193
+ self._config()
182
194
  self.parse_file()
183
195
  self._build_metrics()
184
196
  self.output_file()
@@ -23,6 +23,24 @@ def test_new_file(tmp_path):
23
23
  )
24
24
 
25
25
 
26
+ def test_default_filename(tmp_path, monkeypatch):
27
+ """Does the command create a new file in default directory?"""
28
+ promfile = tmp_path / "test_metric.prom"
29
+ monkeypatch.setenv("PROMTEXT_DIR", str(tmp_path))
30
+
31
+ with ArgvContext("promtext", "test_metric", "0"):
32
+ promtext_main()
33
+ assert promfile.exists()
34
+ assert promfile.read_text() == (
35
+ "# HELP test_metric metric appended by promtext-cli"
36
+ "\n"
37
+ "# TYPE test_metric gauge"
38
+ "\n"
39
+ "test_metric 0.0"
40
+ "\n"
41
+ )
42
+
43
+
26
44
  def test_labels(tmp_path):
27
45
  """Does the command create a new file with metrics content?"""
28
46
  promfile = tmp_path / "label_file.prom"