Skip to content

Commit

Permalink
feat: add the list of access points to describe()
Browse files Browse the repository at this point in the history
it was only printing an url when there was a single acess point before.
  • Loading branch information
ManonMarchand committed Feb 19, 2024
1 parent 9d22eec commit e598610
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 13 deletions.
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
}
5 changes: 4 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
Enhancements and Fixes
----------------------

- Add list of access points to services in ``pyvo.registry.regtap.RegistryResource.describe``
when there is more than one service available [#525]

- Fix ``pyvo.registry.Author`` to allow registry searches with author constraints. [#515]

- Add method ``list_interfaces`` to ``pyvo.registry.regtap.RegistryResource`` that returns the
list of available interfaces linked to services. Add ``keyword`` parameter in ``get_service`` which should match
``capability_description``. [#505] [#524]
``capability_description``. [#505] [#525]

- Add optional ``capability_description`` parameter and a ``__repr__`` to ``pyvo.dal.query.DALService``
abstract base class [#505]
Expand Down
3 changes: 2 additions & 1 deletion docs/registry/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ constraint on the description ``get_service(service_type='conesearch', keyword='
>>> for interface in voresource.list_interfaces():
... 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=II/283')
Interface(type='conesearch', description='Cone search capability for table II/283/sncat (List of SNe arranged in chronological order)', url='http://vizier.cds.unistra.fr/viz-bin/conesearch/II/283/sncat?')

Or construct the service object directly from the list of interfaces with:
Expand Down Expand Up @@ -446,7 +447,7 @@ the ``describe`` function.
Short Name: NVSS
IVOA Identifier: ivo://nasa.heasarc/skyview/nvss
Access modes: sia
Base URL: https://skyview.gsfc.nasa.gov/cgi-bin/vo/sia.pl?survey=nvss&
- sia: https://skyview.gsfc.nasa.gov/cgi-bin/vo/sia.pl?survey=nvss&
...

The verbose option in ``describe`` will output more information about
Expand Down
26 changes: 17 additions & 9 deletions pyvo/registry/regtap.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import functools
import itertools
import os
import textwrap
import warnings

from astropy import table
Expand Down Expand Up @@ -400,8 +401,9 @@ def __init__(self, access_url, *, standard_id=None,
self.is_vosi = False

def __repr__(self):
if self.standard_id is None:
return (f"Interface(description={self.capability_description!r}, "
if not self.standard_id or self.standard_id is None:
return (f"Interface(type={self.type!r}, "
f"description={self.capability_description!r}, "
f"url={self.access_url!r})")
return (f"Interface(type={self.standard_id.rsplit('/')[-1]!r}, "
f"description={self.capability_description!r}, "
Expand Down Expand Up @@ -903,8 +905,11 @@ def list_interfaces(self, service_type: str = None):
service_type = expand_stdid(rtcons.SERVICE_TYPE_MAP.get(service_type, service_type))

list_interfaces = [interface for interface in self.interfaces
if (interface.is_standard
and (service_type is None or interface.supports(service_type)))]
if interface.is_standard or interface.type == "vr:webbrowser"]

if service_type is not None:
list_interfaces = [interface for interface in list_interfaces
if interface.is_standard and interface.supports(service_type)]

return sorted(list_interfaces, key=lambda interface: interface.access_url)

Expand Down Expand Up @@ -967,11 +972,14 @@ def describe(self, *, verbose=False, width=78, file=None):
print("IVOA Identifier: " + self.ivoid, file=file)
print("Access modes: " + ", ".join(sorted(self.access_modes())),
file=file)

if len(self._mapping["access_urls"]) == 1:
print("Base URL: " + self.access_url, file=file)
else:
print("Multi-capability service -- use get_service()", file=file)
for interface in self.list_interfaces():
if interface.type == "vr:webbrowser":
print(f"- webpage: {interface.access_url}", file=file)
elif all(dont_print not in interface.standard_id for dont_print in ["vosi", "datalink", "soda"]):
service_item = f"- {interface.standard_id.rsplit('/')[-1]}: {interface.access_url}"
if interface.capability_description:
service_item += f", description: {interface.capability_description}"
print(textwrap.fill(service_item, width), file=file)

if self.res_description:
print(file=file)
Expand Down
7 changes: 5 additions & 2 deletions pyvo/registry/tests/test_regtap.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def test_repr(self):
assert (repr(intf) == "Interface(type='a', description='An example description.',"
" url='http://example.org')")
intf = regtap.Interface("http://example.org", capability_description=description)
assert repr(intf) == ("Interface(description='An example description.',"
assert repr(intf) == ("Interface(type=None, description='An example description.',"
" url='http://example.org')")

def test_unknown_standard(self):
Expand Down Expand Up @@ -769,7 +769,10 @@ def test_describe_multi(self, flash_service):
assert "Flash/Heros SSAP" in output
assert ("Access modes: datalink#links-1.1, soda#sync-1.0,"
" ssa, tap#aux, web" in output)
assert "Multi-capability service" in output
assert "- webpage: http://dc.zah.uni-heidelberg.de/flashheros/q/web/form" in output
assert "- tap#aux: http://dc.zah.uni-heidelberg.de/tap" in output
# datalink, soda and vosi are not printed here
assert "- datalink" not in output
assert "Source: 1996A&A...312..539S" in output
assert "Authors: Wolf" in output
assert "Alternative identifier(s): doi:10.21938/" in output
Expand Down

0 comments on commit e598610

Please sign in to comment.