Skip to content

Commit

Permalink
Merge pull request #82 from LLNL/checkver-hardening
Browse files Browse the repository at this point in the history
Make Checkver more resilient to failures
  • Loading branch information
holm10 authored May 28, 2024
2 parents eb340ed + d3260d3 commit ba4871c
Showing 1 changed file with 22 additions and 32 deletions.
54 changes: 22 additions & 32 deletions src/uedge/checkver.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,28 @@
pkg = "uedge"

import json
try:
import json
import urllib.request

pkg = 'uedge'
try:
import importlib.metadata

try:
import importlib.metadata
thisver = importlib.metadata.version(pkg)
except:
import pkg_resources
thisver = pkg_resources.get_distribution(pkg).version
thisver = importlib.metadata.version(pkg)
except:
import pkg_resources

try:
import urllib.request
contents = urllib.request.urlopen('https://pypi.org/pypi/'+pkg+'/json').read()
data = json.loads(contents.decode())
thatver = data['info']['version']
except:
import urllib
contents = urllib.urlopen('https://pypi.org/pypi/'+pkg+'/json').read()
data = json.loads(contents)
thatver = str(data['info']['version'])
thisver = pkg_resources.get_distribution(pkg).version

contents = urllib.request.urlopen("https://pypi.org/pypi/" + pkg + "/json").read()
data = json.loads(contents.decode())
thatver = data["info"]["version"]

if thisver < thatver:
print()
print("Uedge version " + thisver + ", an update is available to " + thatver)
print()

if thisver > thatver:
#print('Uedge version '+thisver+' is newer than available with pip ('+thatver+')')
pass
elif thisver == thatver:
#print('Uedge version '+thisver+' is up-to-date')
pass
elif thisver < thatver:
print()
print('Uedge version '+thisver+', an update is available to '+thatver)
print()
else:
print()
print('Some error checking pypi version')
print()
except Exception as err:
print()
print("Error checking pypi version: {}".format(err))
print()

0 comments on commit ba4871c

Please sign in to comment.