-
Notifications
You must be signed in to change notification settings - Fork 4
/
version.py
36 lines (30 loc) · 1.15 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
import os
from typing import Optional
from packaging import version
import requests
DEV_VERSION = "dev"
VERSION = os.getenv("LAKEVIEW_VERSION", "dev")
VERSION_URI = "https://stats.treeverse.io/lakeview"
VERSION_UA = "lakeview_version_check"
RELEASES_URL = "https://hub.docker.com/repository/docker/treeverse/lakeview"
def get_latest_version() -> Optional[str]:
"""
Check if there's a newer lakeview version
:return: a newer version if exists, or None if we're at the latest version already
"""
if VERSION == DEV_VERSION:
return None # we don't compare dev versions
try:
response = requests.get(
VERSION_URI,
params={'version': VERSION},
headers={'User-Agent': VERSION_UA},
timeout=2 # Since this is not critical for lakeview to function, let's be aggressive
)
latest = response.json().get('latest')
if version.parse(latest) > version.parse(VERSION):
return latest
except Exception as e:
print(f'[WARNING] could not check what the latest lakeview version is: {e}\n'
f'\tFeel free to check at {RELEASES_URL}')
return None