-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.py
More file actions
60 lines (53 loc) · 1.73 KB
/
bootstrap.py
File metadata and controls
60 lines (53 loc) · 1.73 KB
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
import subprocess
import sys
from pathlib import Path
import requests
import json
def get_installed_version():
"""Get the currently installed version of lasso."""
try:
result = subprocess.run(
[sys.executable, "-m", "pip", "show", "lasso"],
capture_output=True,
text=True
)
for line in result.stdout.split('\n'):
if line.startswith('Version:'):
return line.split(':')[1].strip()
except Exception as e:
print(f"Error getting installed version: {e}")
return None
def get_latest_stable_version():
"""Fetch the latest stable release version from git/PyPI."""
try:
response = requests.get("https://pypi.org/pypi/lasso/json", timeout=5)
data = response.json()
return data['info']['version']
except Exception as e:
print(f"Error fetching latest version: {e}")
return None
def update_lasso():
"""Update lasso to the latest stable release."""
try:
subprocess.run(
[sys.executable, "-m", "pip", "install", "--upgrade", "lasso"],
check=True
)
print("Lasso updated successfully!")
return True
except subprocess.CalledProcessError as e:
print(f"Error updating lasso: {e}")
return False
def bootstrap():
"""Main bootstrap function."""
installed = get_installed_version()
latest = get_latest_stable_version()
print(f"Installed version: {installed}")
print(f"Latest stable version: {latest}")
if installed and latest and installed != latest:
print("Update available. Updating...")
update_lasso()
else:
print("Lasso is up to date!")
if __name__ == "__main__":
bootstrap()