/
version.py
67 lines (50 loc) · 2.17 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# ../core/version.py
"""Provides the Source.Python version."""
# =============================================================================
# >> IMPORTS
# =============================================================================
# Python Imports
from urllib.request import urlopen
# Source.Python Imports
# Cvars
from cvars.public import PublicConVar
# =============================================================================
# >> ALL DECLARATION
# =============================================================================
__all__ = ('VERSION',
'GIT_COMMIT',
'get_last_successful_build_number',
'is_unversioned',
)
# =============================================================================
# >> CONSTANTS
# =============================================================================
#: Version of the Source.Python intallation.
VERSION = None
#: The Github commit this Source.Python version was built with.
GIT_COMMIT = None
LAST_SUCCESSFUL_BUILD_NUMBER_URL = (
'http://downloads.sourcepython.com/version.txt')
# =============================================================================
# >> GLOBAL VARIABLES
# =============================================================================
_sp_version = PublicConVar('sp_version', str(VERSION), 'Source.Python version')
# =============================================================================
# >> FUNCTIONS
# =============================================================================
def get_last_successful_build_number(timeout=3):
"""Return the latest successful build number as an integer.
:param float timeout:
Number of seconds that need to pass until a timeout occurs.
:rtype: int
"""
with urlopen(LAST_SUCCESSFUL_BUILD_NUMBER_URL, timeout=timeout) as url:
return int(url.read().decode('utf-8'))
def is_unversioned():
"""Return ``True`` if this Source.Python installation has no version.
This can happen in multiple cases:
* This is an unofficial build (not a build from the build server).
* The Python files have been updated directly from the repository.
:rtype: bool
"""
return VERSION is None