Skip to content

Commit

Permalink
passbands update available datetime string parsing bugfix (2.3.19 rel…
Browse files Browse the repository at this point in the history
…ease) (#411)

* some systems fail to parse common datetime strings, resulting in inability to import phoebe when checking for available passband updates.  This now prints and logs an error message, but does not prevent import.
* checking for available passband updates on import now correctly respects the PHOEBE_ENABLE_ONLINE_PASSBANDS environment variable.
* failed online passbands connection error messages are now only included in the log once (per processor) to avoid spamming the log (but are shown by default when manually calling phoebe.list_online_passbands).
  • Loading branch information
kecnry authored Feb 4, 2021
1 parent d740dbd commit 832f401
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 24 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ To understand how to use PHOEBE, please consult the [tutorials, scripts and manu
CHANGELOG
----------

### 2.3.19 - passbands update available datetime string parsing bugfix

* some systems fail to parse common datetime strings, resulting in inability to import phoebe when checking for available passband updates. This now prints and logs an error message, but does not prevent import.
* checking for available passband updates on import now correctly respects the PHOEBE_ENABLE_ONLINE_PASSBANDS environment variable.
* failed online passbands connection error messages are now only included in the log once (per processor) to avoid spamming the log (but are shown by default when manually calling phoebe.list_online_passbands).

### 2.3.18 - estimator.ebai with wide eclipse fix (attempt 2)

* actually fixes bug (see 2.3.13) that raised internal error when running ebai on an eclipse with width larger than 0.25 in phase. Note that these systems will still return nans as ebai is not well-suited to these systems, but the internal error will no longer occur.
Expand Down
11 changes: 6 additions & 5 deletions phoebe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"""

__version__ = '2.3.18'
__version__ = '2.3.19'

import os as _os
import sys as _sys
Expand Down Expand Up @@ -946,10 +946,11 @@ def list_available_solvers(devel=False):
"""
return _get_phoebe_funcs(solver, devel=devel)

for pb in list_all_update_passbands_available():
msg = 'passband "{}" has a newer version available. Run phoebe.list_passband_online_history("{}") to get a list of available changes and phoebe.update_passband("{}") or phoebe.update_all_passbands() to update.'.format(pb, pb, pb)
# NOTE: we'll print since the logger hasn't been initialized yet.
print('PHOEBE: {}'.format(msg))
if _env_variable_bool('PHOEBE_ENABLE_ONLINE_PASSBANDS', 'TRUE'):
for pb in list_all_update_passbands_available():
msg = 'passband "{}" has a newer version available. Run phoebe.list_passband_online_history("{}") to get a list of available changes and phoebe.update_passband("{}") or phoebe.update_all_passbands() to update.'.format(pb, pb, pb)
# NOTE: we'll print since the logger hasn't been initialized yet.
print('PHOEBE: {}'.format(msg))

# delete things we don't want exposed to the user at the top-level
# NOTE: we need _sys for reset_settings, that's why its __sys
Expand Down
48 changes: 32 additions & 16 deletions phoebe/atmospheres/passbands.py
Original file line number Diff line number Diff line change
Expand Up @@ -2974,7 +2974,7 @@ def _init_passbands(refresh=False, query_online=True, passband_directories=None)
# load information from online passbands first so that any that are
# available locally will override
if query_online:
online_passbands = list_online_passbands(full_dict=True, refresh=refresh)
online_passbands = list_online_passbands(full_dict=True, refresh=refresh, repeat_errors=False)
for pb, info in online_passbands.items():
_pbtable[pb] = {'fname': None, 'atms': info['atms'], 'atms_ld': info.get('atms_ld', ['ck2004']), 'pb': None}

Expand Down Expand Up @@ -3160,7 +3160,7 @@ def download_passband(passband, content=None, local=True, gzipped=None):
<phoebe.atmospheres.passbands.list_online_passbands>.
* IOError: if internet connection fails.
"""
if passband not in list_online_passbands():
if passband not in list_online_passbands(repeat_errors=False):
raise ValueError("passband '{}' not available".format(passband))

if content is None:
Expand Down Expand Up @@ -3218,7 +3218,7 @@ def list_passband_online_history(passband, since_installed=True):
----------
* (dict): dictionary with timestamps as keys and messages and values.
"""
if passband not in list_online_passbands():
if passband not in list_online_passbands(repeat_errors=False):
raise ValueError("'{}' passband not availabe online".format(passband))

url = '{}/pbs/history/{}?phoebe_version={}'.format(_url_tables_server, passband, phoebe_version)
Expand Down Expand Up @@ -3293,7 +3293,7 @@ def _return(passband, updates_available):
else:
return False

if passband not in list_online_passbands():
if passband not in list_online_passbands(repeat_errors=False):
logger.warning("{} not available in online passbands".format(passband))
return _return(passband, False)

Expand All @@ -3310,8 +3310,18 @@ def _return(passband, updates_available):
elif online_timestamp is None:
return _return(passband, False)

elif _timestamp_to_dt(installed_timestamp) < _timestamp_to_dt(online_timestamp):
return _return(passband, True)
else:
try:
installed_timestamp_dt = _timestamp_to_dt(installed_timestamp)
online_timestamp_dt = _timestamp_to_dt(online_timestamp)
except Exception as err:
msg = "failed to convert passband timestamps, so cannot determine if updates are available. To disable online passbands entirely, set the environment variable PHOEBE_ENABLE_ONLINE_PASSBANDS=FALSE. Check tables.phoebe-project.org manually for updates. Original error: {}".format(err)
print("ERROR: {}".format(msg))
logger.error(msg)
return _return(passband, False)
else:
if installed_timestamp_dt < online_timestamp_dt:
return _return(passband, True)

return _return(passband, False)

Expand Down Expand Up @@ -3513,7 +3523,7 @@ def list_passbands(refresh=False, full_dict=False, skip_keys=[]):
* (list of strings or dictionary, depending on `full_dict`)
"""
if full_dict:
d = list_online_passbands(refresh, True, skip_keys=skip_keys)
d = list_online_passbands(refresh, True, skip_keys=skip_keys, repeat_errors=False)
for k in d.keys():
if 'installed' not in skip_keys:
d[k]['installed'] = False
Expand All @@ -3524,7 +3534,7 @@ def list_passbands(refresh=False, full_dict=False, skip_keys=[]):
d[k]['installed'] = True
return d
else:
return list(set(list_installed_passbands(refresh) + list_online_passbands(refresh)))
return list(set(list_installed_passbands(refresh) + list_online_passbands(refresh, repeat_errors=False)))

def list_installed_passbands(refresh=False, full_dict=False, skip_keys=[]):
"""
Expand Down Expand Up @@ -3562,7 +3572,7 @@ def list_installed_passbands(refresh=False, full_dict=False, skip_keys=[]):
else:
return [k for k,v in _pbtable.items() if v['fname'] is not None]

def list_online_passbands(refresh=False, full_dict=False, skip_keys=[]):
def list_online_passbands(refresh=False, full_dict=False, skip_keys=[], repeat_errors=True):
"""
For convenience, this function is available at the top-level as
<phoebe.list_online_passbands> as well as
Expand All @@ -3582,6 +3592,10 @@ def list_online_passbands(refresh=False, full_dict=False, skip_keys=[]):
of names.
* `skip_keys` (list, optional, default=[]): keys to exclude from the returned
dictionary. Only applicable if `full_dict` is True.
* `repeat_errors` (bool, optional, default=True): whether to continue to show
errors if online passbands are unavailable. (Internally this is passed
as False so that the error message does not spam the log, but defaults
to True so if calling manually the error message is shown).
Returns
--------
Expand All @@ -3591,8 +3605,10 @@ def list_online_passbands(refresh=False, full_dict=False, skip_keys=[]):
global _online_passband_failedtries
if os.getenv('PHOEBE_ENABLE_ONLINE_PASSBANDS', 'TRUE').upper() == 'TRUE' and (len(_online_passbands.keys())==0 or refresh):
if _online_passband_failedtries >= 3 and not refresh:
msg = "Online passbands unavailable (reached max tries). Pass refresh=True to force another attempt."
logger.warning(msg)
if ((_online_passband_failedtries >= 3 and repeat_errors) or (_online_passband_failedtries==3)):
msg = "Online passbands unavailable (reached max tries). Pass refresh=True to force another attempt or repeat_errors=False to avoid showing this message."
logger.warning(msg)
_online_passband_failedtries += 1
else:
url = '{}/pbs/list?phoebe_version={}'.format(_url_tables_server, phoebe_version)

Expand Down Expand Up @@ -3627,7 +3643,7 @@ def list_online_passbands(refresh=False, full_dict=False, skip_keys=[]):
msg += " Original error from json.loads: {} {}".format(err.__class__.__name__, str(err))

logger.warning("(Attempt {} of 3): ".format(_online_passband_failedtries)+msg)

# also print in case logger hasn't been initialized yet
if _online_passband_failedtries == 1:
print(msg)

Expand Down Expand Up @@ -3726,7 +3742,7 @@ def get_passband(passband, content=None, reload=False, update_if_necessary=False
# then we need to make sure all the required content are met in the local version
content_installed = _pbtable[passband]['content']
timestamp_installed = _pbtable[passband]['timestamp']
online_content = list_online_passbands(full_dict=True).get(passband, {}).get('content', [])
online_content = list_online_passbands(full_dict=True, repeat_errors=False).get(passband, {}).get('content', [])

if content == 'all':
content = online_content
Expand All @@ -3745,7 +3761,7 @@ def get_passband(passband, content=None, reload=False, update_if_necessary=False

if content is not None and not np.all([c in content_installed for c in content]):
# then we can update without prompting if the timestamps match
timestamp_online = list_online_passbands(full_dict=True).get(passband, {}).get('timestamp', None)
timestamp_online = list_online_passbands(full_dict=True, repeat_errors=False).get(passband, {}).get('timestamp', None)
if timestamp_online is not None and (update_if_necessary or timestamp_installed == timestamp_online):
download_passband(passband, content=content, local=download_local, gzipped=download_gzipped)
else:
Expand All @@ -3757,10 +3773,10 @@ def get_passband(passband, content=None, reload=False, update_if_necessary=False
pass
elif os.getenv('PHOEBE_ENABLE_ONLINE_PASSBANDS', 'TRUE').upper() == 'TRUE':
# then we need to download, if available online
if passband in list_online_passbands():
if passband in list_online_passbands(repeat_errors=False):
download_passband(passband, content=content, local=download_local, gzipped=download_gzipped)
else:
raise ValueError("passband: {} not found. Try one of: {} (local) or {} (available for download)".format(passband, list_installed_passbands(), list_online_passbands()))
raise ValueError("passband: {} not found. Try one of: {} (local) or {} (available for download)".format(passband, list_installed_passbands(), list_online_passbands(repeat_errors=False)))

else:
raise ValueError("passband {} not installed locally and online passbands is disabled.".format(passband))
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,8 @@ def _env_variable_bool(key, default):
long_description = "\n".join(long_description_s[long_description_s.index("INTRODUCTION"):])

setup (name = 'phoebe',
version = '2.3.18',
description = 'PHOEBE 2.3.18',
version = '2.3.19',
description = 'PHOEBE 2.3.19',
long_description=long_description,
author = 'PHOEBE development team',
author_email = '[email protected]',
Expand All @@ -367,7 +367,7 @@ def _env_variable_bool(key, default):
'Programming Language :: Python :: 3 :: Only',
],
python_requires='>=3.6, <4',
download_url = 'https://github.com/phoebe-project/phoebe2/tarball/2.3.18',
download_url = 'https://github.com/phoebe-project/phoebe2/tarball/2.3.19',
packages = ['phoebe', 'phoebe.parameters', 'phoebe.parameters.solver', 'phoebe.parameters.figure', 'phoebe.frontend', 'phoebe.constraints', 'phoebe.dynamics', 'phoebe.distortions', 'phoebe.algorithms', 'phoebe.atmospheres', 'phoebe.backend', 'phoebe.solverbackends', 'phoebe.solverbackends.ebai', 'phoebe.utils', 'phoebe.helpers', 'phoebe.pool', 'phoebe.dependencies', 'phoebe.dependencies.autofig', 'phoebe.dependencies.nparray', 'phoebe.dependencies.distl', 'phoebe.dependencies.unitsiau2015'],
install_requires=['numpy>=1.12','scipy>=1.2','astropy>=1.0', 'corner', 'pytest', 'requests', 'python-socketio[client]']+['flask', 'flask-cors', 'flask-socketio', 'gevent-websocket'],
package_data={'phoebe.atmospheres':['tables/wd/*', 'tables/passbands/*'],
Expand Down

0 comments on commit 832f401

Please sign in to comment.