promtext-cli 0.2.1.dev5__tar.gz → 0.2.1.dev8__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 (21) hide show
  1. {promtext_cli-0.2.1.dev5 → promtext_cli-0.2.1.dev8}/.copier-answers.yml +1 -1
  2. {promtext_cli-0.2.1.dev5 → promtext_cli-0.2.1.dev8}/.forgejo/workflows/commitlint.yaml +1 -1
  3. {promtext_cli-0.2.1.dev5 → promtext_cli-0.2.1.dev8}/.forgejo/workflows/lint.yaml +1 -1
  4. {promtext_cli-0.2.1.dev5 → promtext_cli-0.2.1.dev8}/.forgejo/workflows/publish.yaml +2 -2
  5. {promtext_cli-0.2.1.dev5 → promtext_cli-0.2.1.dev8}/.forgejo/workflows/test.yaml +1 -1
  6. {promtext_cli-0.2.1.dev5 → promtext_cli-0.2.1.dev8}/.pre-commit-config.yaml +1 -1
  7. {promtext_cli-0.2.1.dev5 → promtext_cli-0.2.1.dev8}/PKG-INFO +5 -4
  8. {promtext_cli-0.2.1.dev5 → promtext_cli-0.2.1.dev8}/README.md +4 -3
  9. {promtext_cli-0.2.1.dev5 → promtext_cli-0.2.1.dev8}/promtext_cli/promtext.py +16 -4
  10. {promtext_cli-0.2.1.dev5 → promtext_cli-0.2.1.dev8}/tests/test_functional.py +18 -0
  11. promtext_cli-0.2.1.dev8/uv.lock +406 -0
  12. promtext_cli-0.2.1.dev5/uv.lock +0 -406
  13. {promtext_cli-0.2.1.dev5 → promtext_cli-0.2.1.dev8}/.commitlintrc.yaml +0 -0
  14. {promtext_cli-0.2.1.dev5 → promtext_cli-0.2.1.dev8}/.gitignore +0 -0
  15. {promtext_cli-0.2.1.dev5 → promtext_cli-0.2.1.dev8}/cliff.toml +0 -0
  16. {promtext_cli-0.2.1.dev5 → promtext_cli-0.2.1.dev8}/promtext_cli/__init__.py +0 -0
  17. {promtext_cli-0.2.1.dev5 → promtext_cli-0.2.1.dev8}/promtext_cli/main.py +0 -0
  18. {promtext_cli-0.2.1.dev5 → promtext_cli-0.2.1.dev8}/pyproject.toml +0 -0
  19. {promtext_cli-0.2.1.dev5 → promtext_cli-0.2.1.dev8}/renovate.json +0 -0
  20. {promtext_cli-0.2.1.dev5 → promtext_cli-0.2.1.dev8}/tests/.gitkeep +0 -0
  21. {promtext_cli-0.2.1.dev5 → promtext_cli-0.2.1.dev8}/tests/test_blackbox.py +0 -0
@@ -1,5 +1,5 @@
1
1
  # Changes here will be overwritten by Copier.
2
- _commit: 0.9.15
2
+ _commit: 0.9.16
3
3
  _src_path: https://codeberg.org/margau/copier-python-uv.git
4
4
  code_dir: promtext_cli
5
5
  container: false
@@ -11,7 +11,7 @@ jobs:
11
11
  commitlint-check:
12
12
  runs-on: docker
13
13
  container:
14
- image: codeberg.org/margau/buildenv-commitlint:latest@sha256:f873f5dd1ee243dad024c8159e7716a551787fa7249ac72d119f827fb6fd793f
14
+ image: codeberg.org/margau/buildenv-commitlint:latest@sha256:05a8071e9a8239be1224ede0cb24b24810f7d2731ce1bd95dfcb9ae67db9adc9
15
15
 
16
16
  steps:
17
17
  - uses: https://code.forgejo.org/actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
@@ -13,7 +13,7 @@ jobs:
13
13
  env:
14
14
  UV_CACHE_DIR: /tmp/.uv-cache
15
15
  container:
16
- image: codeberg.org/margau/buildenv-uv:latest@sha256:12a9bfa0975b853a104e992b70766ba95058e6a6b59aa7c725efecc271abf601
16
+ image: codeberg.org/margau/buildenv-uv:latest@sha256:41a740b95c815bda4cc70fe9325a4c6e3c00e65f1a3ec9b979468e6202391dce
17
17
 
18
18
  steps:
19
19
  - uses: https://code.forgejo.org/actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
@@ -16,7 +16,7 @@ jobs:
16
16
  env:
17
17
  UV_CACHE_DIR: /tmp/.uv-cache
18
18
  container:
19
- image: codeberg.org/margau/buildenv-uv:latest@sha256:12a9bfa0975b853a104e992b70766ba95058e6a6b59aa7c725efecc271abf601
19
+ image: codeberg.org/margau/buildenv-uv:latest@sha256:41a740b95c815bda4cc70fe9325a4c6e3c00e65f1a3ec9b979468e6202391dce
20
20
 
21
21
  steps:
22
22
  - uses: https://code.forgejo.org/actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
@@ -67,7 +67,7 @@ jobs:
67
67
  name: "Draft Release Notes"
68
68
  runs-on: docker
69
69
  container:
70
- image: codeberg.org/margau/buildenv-uv:latest@sha256:12a9bfa0975b853a104e992b70766ba95058e6a6b59aa7c725efecc271abf601
70
+ image: codeberg.org/margau/buildenv-uv:latest@sha256:41a740b95c815bda4cc70fe9325a4c6e3c00e65f1a3ec9b979468e6202391dce
71
71
 
72
72
  steps:
73
73
  - uses: https://code.forgejo.org/actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
@@ -13,7 +13,7 @@ jobs:
13
13
  env:
14
14
  UV_CACHE_DIR: /tmp/.uv-cache
15
15
  container:
16
- image: codeberg.org/margau/buildenv-uv:latest@sha256:12a9bfa0975b853a104e992b70766ba95058e6a6b59aa7c725efecc271abf601
16
+ image: codeberg.org/margau/buildenv-uv:latest@sha256:41a740b95c815bda4cc70fe9325a4c6e3c00e65f1a3ec9b979468e6202391dce
17
17
 
18
18
  steps:
19
19
  - uses: https://code.forgejo.org/actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
@@ -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.16
13
+ rev: v0.15.17
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.dev5
3
+ Version: 0.2.1.dev8
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"