Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make utils and utis/tap kwargs keyword only #2690

Merged
merged 7 commits into from
Apr 4, 2023
Merged
10 changes: 5 additions & 5 deletions astroquery/esa/hubble/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def download_product(self, observation_id, *, calibration_level=None,
params["PRODUCTTYPE"] = product_type

filename = self._get_product_filename(product_type, filename)
self._tap.load_data(params, filename, verbose=verbose)
self._tap.load_data(params_dict=params, output_file=filename, verbose=verbose)

return filename

Expand Down Expand Up @@ -254,7 +254,7 @@ def get_artifact(self, artifact_id, *, filename=None, verbose=False):
if filename is None:
filename = artifact_id

self._tap.load_data(params, filename, verbose=verbose)
self._tap.load_data(params_dict=params, output_file=filename, verbose=verbose)

return filename

Expand Down Expand Up @@ -302,7 +302,7 @@ def get_postcard(self, observation_id, *, calibration_level="RAW",
if filename is None:
filename = observation_id

self._tap.load_data(params, filename, verbose=verbose)
self._tap.load_data(params_dict=params, output_file=filename, verbose=verbose)

return filename

Expand Down Expand Up @@ -505,7 +505,7 @@ def _query_tap_target(self, target):
subContext = conf.EHST_TARGET_ACTION
connHandler = self._tap._TapPlus__getconnhandler()
data = urlencode(params)
target_response = connHandler.execute_secure(subContext, data, True)
target_response = connHandler.execute_secure(subContext, data, verbose=True)
for line in target_response:
target_result = json.loads(line.decode("utf-8"))
if target_result['objects']:
Expand Down Expand Up @@ -763,7 +763,7 @@ def get_status_messages(self):
try:
subContext = conf.EHST_MESSAGES
connHandler = self._tap._TapPlus__getconnhandler()
response = connHandler.execute_tapget(subContext, False)
response = connHandler.execute_tapget(subContext, verbose=False)
if response.status == 200:
for line in response:
string_message = line.decode("utf-8")
Expand Down
10 changes: 5 additions & 5 deletions astroquery/esa/jwst/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ def load_tables(self, *, only_names=False, include_shared_tables=False,
-------
A list of table objects
"""
return self.__jwsttap.load_tables(only_names,
include_shared_tables,
verbose)
return self.__jwsttap.load_tables(only_names=only_names,
include_shared_tables=include_shared_tables,
verbose=verbose)

def load_table(self, table, *, verbose=False):
"""Loads the specified table
Expand All @@ -112,7 +112,7 @@ def load_table(self, table, *, verbose=False):
-------
A table object
"""
return self.__jwsttap.load_table(table, verbose)
return self.__jwsttap.load_table(table, verbose=verbose)

def launch_job(self, query, *, name=None, output_file=None,
output_format="votable", verbose=False, dump_to_file=False,
Expand Down Expand Up @@ -686,7 +686,7 @@ def get_status_messages(self):
try:
subContext = conf.JWST_MESSAGES
connHandler = self.__jwsttap._TapPlus__getconnhandler()
response = connHandler.execute_tapget(subContext, False)
response = connHandler.execute_tapget(subContext, verbose=False)
if response.status == 200:
for line in response:
string_message = line.decode("utf-8")
Expand Down
8 changes: 4 additions & 4 deletions astroquery/esa/jwst/tests/test_jwsttap.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def test_list_async_jobs(self):

def test_query_region(self):
connHandler = DummyConnHandler()
tapplus = TapPlus("http://test:1111/tap", connhandler=connHandler)
tapplus = TapPlus(url="http://test:1111/tap", connhandler=connHandler)
tap = JwstClass(tap_plus_handler=tapplus, show_messages=False)

# Launch response: we use default response because the
Expand Down Expand Up @@ -364,7 +364,7 @@ def test_query_region(self):

def test_query_region_async(self):
connHandler = DummyConnHandler()
tapplus = TapPlus("http://test:1111/tap", connhandler=connHandler)
tapplus = TapPlus(url="http://test:1111/tap", connhandler=connHandler)
tap = JwstClass(tap_plus_handler=tapplus, show_messages=False)
jobid = '12345'
# Launch response
Expand Down Expand Up @@ -436,7 +436,7 @@ def test_query_region_async(self):

def test_cone_search_sync(self):
connHandler = DummyConnHandler()
tapplus = TapPlus("http://test:1111/tap", connhandler=connHandler)
tapplus = TapPlus(url="http://test:1111/tap", connhandler=connHandler)
tap = JwstClass(tap_plus_handler=tapplus, show_messages=False)
# Launch response: we use default response because the
# query contains decimals
Expand Down Expand Up @@ -521,7 +521,7 @@ def test_cone_search_sync(self):

def test_cone_search_async(self):
connHandler = DummyConnHandler()
tapplus = TapPlus("http://test:1111/tap", connhandler=connHandler)
tapplus = TapPlus(url="http://test:1111/tap", connhandler=connHandler)
tap = JwstClass(tap_plus_handler=tapplus, show_messages=False)
jobid = '12345'
# Launch response
Expand Down
2 changes: 1 addition & 1 deletion astroquery/gaia/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,7 @@ def get_status_messages(self):
try:
subContext = self.GAIA_MESSAGES
connHandler = self._TapPlus__getconnhandler()
response = connHandler.execute_tapget(subContext, False)
response = connHandler.execute_tapget(subContext, verbose=False)
if response.status == 200:
if isinstance(response, Iterable):
for line in response:
Expand Down
12 changes: 6 additions & 6 deletions astroquery/gaia/tests/test_gaiatap.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def column_attrs():
@pytest.fixture(scope="module")
def mock_querier():
conn_handler = DummyConnHandler()
tapplus = TapPlus("http://test:1111/tap", connhandler=conn_handler)
tapplus = TapPlus(url="http://test:1111/tap", connhandler=conn_handler)
launch_response = DummyResponse(200)
launch_response.set_data(method="POST", body=JOB_DATA)
# The query contains decimals: default response is more robust.
Expand All @@ -65,7 +65,7 @@ def mock_querier():
@pytest.fixture(scope="module")
def mock_querier_async():
conn_handler = DummyConnHandler()
tapplus = TapPlus("http://test:1111/tap", connhandler=conn_handler)
tapplus = TapPlus(url="http://test:1111/tap", connhandler=conn_handler)
jobid = "12345"

launch_response = DummyResponse(303)
Expand Down Expand Up @@ -105,7 +105,7 @@ def test_show_message():
tableRequest = 'notification?action=GetNotifications'
connHandler.set_response(tableRequest, dummy_response)

tapplus = TapPlus("http://test:1111/tap", connhandler=connHandler)
tapplus = TapPlus(url="http://test:1111/tap", connhandler=connHandler)
GaiaClass(tap_plus_conn_handler=connHandler, datalink_handler=tapplus, show_server_messages=True)


Expand Down Expand Up @@ -258,7 +258,7 @@ def test_cross_match_missing_mandatory_kwarg(cross_match_kwargs, missing_kwarg):
@patch.object(TapPlus, 'login')
def test_login(mock_login):
conn_handler = DummyConnHandler()
tapplus = TapPlus("http://test:1111/tap", connhandler=conn_handler)
tapplus = TapPlus(url="http://test:1111/tap", connhandler=conn_handler)
tap = GaiaClass(tap_plus_conn_handler=conn_handler, datalink_handler=tapplus, show_server_messages=False)
tap.login(user="user", password="password")
assert (mock_login.call_count == 2)
Expand All @@ -271,7 +271,7 @@ def test_login(mock_login):
@patch.object(TapPlus, 'login')
def test_login_gui(mock_login_gui, mock_login):
conn_handler = DummyConnHandler()
tapplus = TapPlus("http://test:1111/tap", connhandler=conn_handler)
tapplus = TapPlus(url="http://test:1111/tap", connhandler=conn_handler)
tap = GaiaClass(tap_plus_conn_handler=conn_handler, datalink_handler=tapplus, show_server_messages=False)
tap.login_gui()
assert (mock_login_gui.call_count == 1)
Expand All @@ -283,7 +283,7 @@ def test_login_gui(mock_login_gui, mock_login):
@patch.object(TapPlus, 'logout')
def test_logout(mock_logout):
conn_handler = DummyConnHandler()
tapplus = TapPlus("http://test:1111/tap", connhandler=conn_handler)
tapplus = TapPlus(url="http://test:1111/tap", connhandler=conn_handler)
tap = GaiaClass(tap_plus_conn_handler=conn_handler, datalink_handler=tapplus, show_server_messages=False)
tap.logout()
assert (mock_logout.call_count == 2)
Expand Down
2 changes: 1 addition & 1 deletion astroquery/sdss/tests/test_sdss.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def mockreturn(method, url, **kwargs):
with open(filename, 'rb') as infile:
content = infile.read()

return MockResponse(content, url)
return MockResponse(content=content, url=url)

mp = request.getfixturevalue("monkeypatch")

Expand Down
2 changes: 1 addition & 1 deletion astroquery/utils/commons.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def get_fits(self):

return self._fits

def save_fits(self, savepath, link_cache='hard'):
def save_fits(self, savepath, *, link_cache='hard'):
"""
Save a FITS file to savepath

Expand Down
2 changes: 1 addition & 1 deletion astroquery/utils/docstr_chompers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def dec(fn):
return dec


def prepend_docstr_nosections(doc, sections=['Returns', ]):
def prepend_docstr_nosections(doc, *, sections=['Returns', ]):
"""
Decorator to prepend to the function's docstr after stripping out the
list of sections provided (by default "Returns" only).
Expand Down
2 changes: 1 addition & 1 deletion astroquery/utils/mocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class MockResponse:
A mocked/non-remote version of `astroquery.query.AstroResponse`
"""

def __init__(self, content=None, url=None, headers={}, content_type=None,
def __init__(self, content=None, *, url=None, headers={}, content_type=None,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This content kwarg is the only kwarg that I've had to leave to be positional since the majority of the packages' testing uses it positionally. Otherwise most of the packages' testing would need to be refactored.

stream=False, auth=None, status_code=200, verify=True,
allow_redirects=True, json=None):
assert content is None or hasattr(content, 'decode')
Expand Down
2 changes: 1 addition & 1 deletion astroquery/utils/process_asyncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def newmethod(self, *args, **kwargs):
return cls


def async_to_sync_docstr(doc, returntype='table'):
def async_to_sync_docstr(doc, *, returntype='table'):
"""
Strip of the "Returns" component of a docstr and replace it with "Returns a
table" code
Expand Down
4 changes: 2 additions & 2 deletions astroquery/utils/progressbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def chunk_report(bytes_so_far, chunk_size, total_size):
(bytes_so_far / 1024. ** 2))


def chunk_read(response, chunk_size=1024, report_hook=None):
def chunk_read(response, *, chunk_size=1024, report_hook=None):
content_length = response.info().get('Content-Length')
if content_length is None:
total_size = 0
Expand Down Expand Up @@ -51,7 +51,7 @@ def chunk_read(response, chunk_size=1024, report_hook=None):
return result_string


def retrieve(url, outfile, opener=None, overwrite=False):
def retrieve(url, outfile, *, opener=None, overwrite=False):
"""
"retrieve" (i.e., download to file) a URL.
"""
Expand Down
4 changes: 2 additions & 2 deletions astroquery/utils/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def validate(self, data):

class Use:

def __init__(self, callable_, error=None):
def __init__(self, callable_, *, error=None):
assert callable(callable_)
self._callable = callable_
self._error = error
Expand Down Expand Up @@ -97,7 +97,7 @@ def priority(s):

class Schema:

def __init__(self, schema, error=None):
def __init__(self, schema, *, error=None):
self._schema = schema
self._error = error

Expand Down
Loading