Skip to content

Commit

Permalink
more py client version check cleanup/fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
melange396 authored Jul 19, 2024
1 parent 5946365 commit f52ef36
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions src/client/delphi_epidata.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,33 +46,38 @@ class Epidata:
debug = False # if True, prints extra logging statements
sandbox = False # if True, will not execute any queries

_version_checked=False
_version_checked = False

@staticmethod
def log(evt, **kwargs):
kwargs['event'] = evt
kwargs['timestamp'] = time.strftime("%Y-%m-%d %H:%M:%S %z")
return sys.stderr.write(str(kwargs) + "\n")

# Check that this client's version matches the most recent available, runs just once per program execution (on initial module load).
# Check that this client's version matches the most recent available.
# This is intended to run just once per program execution, on initial module load.
# See the bottom of this file for the ultimate call to this method.
@staticmethod
def _version_check():
_version_checked = True
if Epidata._version_checked:
# already done; nothing to do!
return

Epidata._version_checked = True

try:
request = requests.get('https://pypi.org/pypi/delphi-epidata/json', timeout=5)
latest_version = request.json()['info']['version']
if latest_version != __version__:
Epidata.log(
"Client version not up to date",
client_version=__version__,
latest_version=latest_version
)
except Exception as e:
Epidata.log("Error getting latest client version", exception=str(e))
return

# Run this once on module load. Use dunder method for Python <= 3.9 compatibility
# https://stackoverflow.com/a/12718272
_version_check.__func__()
if latest_version != __version__:
Epidata.log(
"Client version not up to date",
client_version=__version__,
latest_version=latest_version
)

# Helper function to cast values and/or ranges to strings
@staticmethod
Expand Down Expand Up @@ -713,5 +718,6 @@ async def async_make_calls(param_combos):
responses = loop.run_until_complete(future)
return responses

if Epidata._version_checked == False:
Epidata._version_check()


Epidata._version_check()

0 comments on commit f52ef36

Please sign in to comment.