forked from RascalSoftware/RAT-Docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathversion.py
30 lines (22 loc) · 1.03 KB
/
version.py
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
27
28
29
30
import os
import re
# The regex for major, minor and bugfix version, including alpha/beta/rc tags
VERSION_REGEX = re.compile(r"(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)"
r"(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)"
r"(?:\.(?:0|[1-9]\d*|\d *[a-zA-Z-][0-9a-zA-Z-]*))*))?"
r"(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?")
DOCS_PATH = os.path.abspath(os.path.dirname(__file__))
VERSION_FILE = os.path.join(DOCS_PATH, 'API', 'version.txt')
def get_doc_version():
"""Grabs doc version from environment variable otherwise fallback to version
file in RAT if not set"""
doc_version = 'dev'
version = os.environ.get('RAT_VERSION')
if version is None:
with open(VERSION_FILE, 'r') as version_file:
version = version_file.read()
tmp = VERSION_REGEX.match(version.replace(' ', ''))
if tmp is not None:
major, minor, *other = list(tmp.groups())
doc_version = f'{major}.{minor}'
return doc_version