File: get_version.py

package info (click to toggle)
python-ovoenergy 3.0.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 352 kB
  • sloc: python: 1,519; makefile: 4
file content (26 lines) | stat: -rw-r--r-- 706 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/usr/bin/env python3
"""Print the current package version from setup.py.

This script reads the version string from the repository's setup.py and prints
only the version to stdout.
"""

from __future__ import annotations

from pathlib import Path
import re


def main() -> None:
    """Print the current package version from setup.py."""
    project_root = Path(__file__).resolve().parents[1]
    setup_path = project_root / "setup.py"
    setup_contents = setup_path.read_text(encoding="utf-8")
    match = re.search(r'version="([^"]+)"', setup_contents)
    if not match:
        raise SystemExit("version field not found in setup.py")
    print(match.group(1))


if __name__ == "__main__":
    main()