Sideband/sbapp/gv.py

17 lines
495 B
Python
Raw Permalink Normal View History

2022-07-08 05:53:04 -06:00
import re
import os
def gv() -> str:
version_file = os.path.join(
os.path.dirname(__file__), "main.py"
)
version_file_data = open(version_file, "rt", encoding="utf-8").read()
version_regex = r"(?<=^__version__ = ['\"])[^'\"]+(?=['\"]$)"
try:
version = re.findall(version_regex, version_file_data, re.M)[0]
return version
except IndexError:
raise ValueError(f"Unable to find version string in {version_file}.")
print(gv(), end="")
exit(0)