Skip to content

Commit

Permalink
More information in get_endpoint exceptions and small docstring fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
stvoutsin committed Feb 3, 2025
1 parent 50d3e7a commit b2517a9
Show file tree
Hide file tree
Showing 9 changed files with 430 additions and 31 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci_devtests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Set up Python 3.12
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5.4.0
with:
python-version: "3.12"
- name: Install tox
Expand All @@ -32,7 +32,7 @@ jobs:
run: tox -e py312-test-devdeps-alldeps-cov

- name: Upload coverage to codecov
uses: codecov/codecov-action@1e68e06f1dbfde0e4cefc87efeba9e4643565303 # v5.1.2
uses: codecov/codecov-action@13ce06bfc6bbe3ecf90edbbf1bc32fe5978ca1d3 # v5.3.1
with:
file: ./coverage.xml
verbose: true
Expand All @@ -42,7 +42,7 @@ jobs:
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Set up Python 3.13
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5.4.0
with:
python-version: "3.13-dev"
- name: Install tox
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/ci_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5.4.0
with:
python-version: ${{ matrix.python-version }}
- name: Install tox
Expand All @@ -61,7 +61,7 @@ jobs:
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5.4.0
with:
python-version: '3.12'
- name: Install tox
Expand All @@ -77,7 +77,7 @@ jobs:
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Set up Python 3.12
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5.4.0
with:
python-version: '3.12'
- name: Install tox
Expand All @@ -93,7 +93,7 @@ jobs:
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Set up Python 3.10
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5.4.0
with:
python-version: '3.10'
- name: Install tox
Expand Down
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ Enhancements and Fixes

- Make deletion of TAP jobs optional via a new ``delete`` kwarg. [#640]

- Provide more informative exception message when requests to endpoints fail. [#641]

- Change AsyncTAPJob.result to return None if no result is found explicitly [#644]


Deprecations and Removals
-------------------------

Expand Down
2 changes: 1 addition & 1 deletion docs/registry/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ constraint on the description ``get_service(service_type='conesearch', keyword='
... print(interface)
Interface(type='tap#aux', description='', url='http://tapvizier.cds.unistra.fr/TAPVizieR/tap')
Interface(type='vr:webbrowser', description='', url='http://vizier.cds.unistra.fr/viz-bin/VizieR-2?-source=J/ApJ/727/14')
Interface(type='conesearch', description='Cone search capability for table J/ApJ/727/14/table2 (AKARI IRC 3-24{mu}m, and Spitzer MIPS 24/70{mu}m photometry of Abell 2255 member galaxies)', url='http://vizier.cds.unistra.fr/viz-bin/conesearch/J/ApJ/727/14/table2?')
Interface(type='conesearch', description='Cone search capability for table J/ApJ/727/14/table2 (AKARI IRC 3-24{mu}m, and Spitzer MIPS 24/70{mu}m photometry of Abell 2255 member galaxies)', url='https://vizier.cds.unistra.fr/viz-bin/conesearch/J/ApJ/727/14/table2?')

Or construct the service object directly from the list of interfaces with:

Expand Down
5 changes: 3 additions & 2 deletions pyvo/dal/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
standard data model. Usually the field names are used to uniquely
identify table columns.
"""
__all__ = ["DALService", "DALQuery", "DALResults", "Record"]
__all__ = ["DALService", "DALServiceError", "DALQuery", "DALQueryError",
"DALResults", "Record"]

import os
import shutil
Expand Down Expand Up @@ -64,7 +65,7 @@ def __init__(self, baseurl, *, session=None, capability_description=None,):
the base URL that should be used for forming queries to the service.
session : object
optional session to use for network requests
description : str, optional
capability_description : str, optional
the description of the service.
"""
self._baseurl = baseurl
Expand Down
39 changes: 26 additions & 13 deletions pyvo/dal/tap.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,18 @@ def __init__(self, baseurl, *, capability_description=None, session=None):
session : object
optional session to use for network requests
"""
super().__init__(baseurl, session=session, capability_description=capability_description)

# Check if the session has an update_from_capabilities attribute.
# This means that the session is aware of IVOA capabilities,
# and can use this information in processing network requests.
# One such use case for this is auth.
if hasattr(self._session, 'update_from_capabilities'):
self._session.update_from_capabilities(self.capabilities)
try:
super().__init__(baseurl, session=session, capability_description=capability_description)

# Check if the session has an update_from_capabilities attribute.
# This means that the session is aware of IVOA capabilities,
# and can use this information in processing network requests.
# One such use case for this is auth.
if hasattr(self._session, 'update_from_capabilities'):
self._session.update_from_capabilities(self.capabilities)
except DALServiceError as e:
raise DALServiceError(f"Cannot find TAP service at '"
f"{baseurl}'.\n\n{str(e)}") from None

def get_tap_capability(self):
"""
Expand Down Expand Up @@ -373,8 +377,6 @@ def create_query(
Parameters
----------
baseurl : str
the base URL for the TAP service
query : str
the query string / parameters
mode : str
Expand Down Expand Up @@ -861,14 +863,14 @@ def results(self):
@property
def result(self):
"""
The job result if exists
Returns the UWS result with id='result' if it exists, otherwise None.
"""
try:
for r in self._job.results:
if r.id_ == 'result':
return r

return self._job.results[0]
return None
except IndexError:
return None

Expand All @@ -885,7 +887,10 @@ def result_uri(self):
the uri of the result
"""
try:
uri = self.result.href
result = self.result
if result is None:
return None
uri = result.href
if not urlparse(uri).netloc:
uri = urljoin(self.url, uri)
return uri
Expand Down Expand Up @@ -940,6 +945,8 @@ def wait(self, *, phases=None, timeout=600.):
----------
phases : list
phases to wait for
timeout : float
maximum time to wait in seconds
Raises
------
Expand Down Expand Up @@ -1007,6 +1014,12 @@ def fetch_result(self):
"""
returns the result votable if query is finished
"""
result_uri = self.result_uri
if result_uri is None:
self._update()
self.raise_if_error()
raise DALServiceError("No result URI available", self.url)

try:
response = self._session.get(self.result_uri, stream=True)
response.raise_for_status()
Expand Down
Loading

0 comments on commit b2517a9

Please sign in to comment.