@@ -52,23 +52,24 @@ def log(evt, **kwargs):
5252 kwargs ['timestamp' ] = time .strftime ("%Y-%m-%d %H:%M:%S %z" )
5353 return sys .stderr .write (str (kwargs ) + "\n " )
5454
55- # Check that this client's version matches the most recent available, runs just once per program execution (on initial module load).
55+ # Check that this client's version matches the most recent available. This
56+ # is intended to run just once per program execution, on initial module load.
57+ # See the bottom of this file for the ultimate call to this method.
5658 @staticmethod
5759 def _version_check ():
5860 try :
59- latest_version = requests .get ('https://pypi.org/pypi/delphi-epidata/json' ).json ()['info' ]['version' ]
60- if latest_version != __version__ :
61- Epidata .log (
62- "Client version not up to date" ,
63- client_version = __version__ ,
64- latest_version = latest_version
65- )
61+ request = requests .get ('https://pypi.org/pypi/delphi-epidata/json' , timeout = 5 )
62+ latest_version = request .json ()['info' ]['version' ]
6663 except Exception as e :
6764 Epidata .log ("Error getting latest client version" , exception = str (e ))
65+ return
6866
69- # Run this once on module load. Use dunder method for Python <= 3.9 compatibility
70- # https://stackoverflow.com/a/12718272
71- _version_check .__func__ ()
67+ if latest_version != __version__ :
68+ Epidata .log (
69+ "Client version not up to date" ,
70+ client_version = __version__ ,
71+ latest_version = latest_version
72+ )
7273
7374 # Helper function to cast values and/or ranges to strings
7475 @staticmethod
@@ -708,3 +709,10 @@ async def async_make_calls(param_combos):
708709 future = asyncio .ensure_future (async_make_calls (param_list ))
709710 responses = loop .run_until_complete (future )
710711 return responses
712+
713+
714+
715+ # This should only run once per program execution, on initial module load,
716+ # as a result of how Python's module system works:
717+ # https://docs.python.org/3/reference/import.html#the-module-cache
718+ Epidata ._version_check ()
0 commit comments