Skip to content

Commit

Permalink
Make AlmanacQuery callable in line with other query class
Browse files Browse the repository at this point in the history
  • Loading branch information
teutoburg committed Oct 25, 2023
1 parent 7f7a5b7 commit 2e2a20e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
12 changes: 11 additions & 1 deletion skycalc_ipy/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ class AlmanacQuery(ESOQueryBase):
"""

def __init__(self, indic):
# FIXME: This basically checks isinstance(indic, ui.SkyCalc), but we
# can't import that because it would create a circual import.
# TODO: Find a better way to do this!!
if hasattr(indic, "defaults"):
indic = indic.values

Expand Down Expand Up @@ -207,7 +210,7 @@ def _get_jsondata(self, file_path: Path):

return jsondata

def query(self):
def __call__(self):
"""
Query the ESO Skycalc server with the parameters in self.params.
Expand Down Expand Up @@ -240,6 +243,13 @@ def query(self):

return almdata

def query(self):
"""Deprecated feature. Class is now callable, use that instead."""
warnings.warn("The .query() method is deprecated and will be removed "
"in a future release. Please simply call the instance.",
DeprecationWarning, stacklevel=2)
return self()


class SkyModel(ESOQueryBase):
"""
Expand Down
2 changes: 1 addition & 1 deletion skycalc_ipy/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,4 @@ def test_load_skymodel_from_cache(self):
skymodel(**params)

alm = core.AlmanacQuery(params)
alm.query()
_ = alm()
2 changes: 1 addition & 1 deletion skycalc_ipy/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def get_almanac_data(
skycalc_params.values["observatory"] = observatory
skycalc_params.validate_params()
alm = AlmanacQuery(skycalc_params.values)
response = alm.query()
response = alm()

if return_full_dict:
skycalc_params.values.update(response)
Expand Down

0 comments on commit 2e2a20e

Please sign in to comment.