-
Notifications
You must be signed in to change notification settings - Fork 12
/
version_check.py
31 lines (28 loc) · 1.28 KB
/
version_check.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
import pkg_resources as pkg
from distutils.version import LooseVersion as version
import requests as req
import os
import subprocess
def check_installed_vs_pypi(package):
dist = pkg.get_distribution(package)
installed_version = dist.version
try:
latest_version = req.get(f'https://pypi.org/pypi/{package}/json').json()['info']['version']
if version(installed_version) < version(latest_version):
print(f'{package} {installed_version} is out of date. Consider rebuilding your container to update to version {latest_version}.')
else:
print(f'{package} {installed_version} is up to date.')
except req.exceptions.RequestException:
print(f'{package} {installed_version} may not be up to date; PufferTank failed to connect to the pip registry to check.')
def check_dev_version(package):
dist = pkg.get_distribution(package)
os.chdir(dist.location)
print(f'{package} {dist.version} (development)')
result = subprocess.run('git status | head -n 2', shell=True, capture_output=True, text=True)
print(result.stdout)
if __name__ == "__main__":
dist = pkg.get_distribution('pufferlib')
if '/puffertank/' in dist.location:
check_dev_version('pufferlib')
else:
check_installed_vs_pypi('pufferlib')