Skip to content

Commit

Permalink
Also restoring an access_url column to registry result's to_table.
Browse files Browse the repository at this point in the history
Again, that's strictly for backward compatiblity.
  • Loading branch information
msdemlei committed Jun 9, 2022
1 parent 58ddde7 commit 45c2dba
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
26 changes: 23 additions & 3 deletions pyvo/registry/regtap.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,20 +199,27 @@ def get_summary(self):
This is mainly intended for interactive use, where people would
like to inspect the matches in, perhaps, notebooks.
This returns a column access_url for backwards compatibilty. Do
not use what you find there in new code. Use get_service on the
records themselves instead.
"""
return table.Table([
list(range(len(self))),
[r.short_name for r in self],
[r.res_title for r in self],
[r.res_description for r in self],
[", ".join(sorted(r.access_modes())) for r in self]],
names=("index", "short_name", "title", "description", "interfaces"),
[", ".join(sorted(r.access_modes())) for r in self],
[r.get_unique_access_url() for r in self]],
names=("index", "short_name", "title", "description",
"interfaces", "access_url"),
descriptions=(
"Index to access the resource within self",
"Short name",
"Resource title",
"Resource description",
"Access modes offered"))
"Access modes offered",
"Unique access URL (or None for multi-interface records)"))

@functools.lru_cache(maxsize=None)
def _get_ivo_index(self):
Expand Down Expand Up @@ -534,6 +541,19 @@ def access_url(self):
" may change in the future."))
return access_urls[0]

def get_unique_access_url(self):
"""
return the access URL of this resource in case it is uniquely
defined.
This is for legacy code that assumes there is just one
access URL. It will return None if Resource has zero or more than
one interfaces.
"""
access_urls = list(sorted(set(self["access_urls"])))
if len(access_urls)==1:
return access_urls[0]

@property
def standard_id(self):
"""
Expand Down
4 changes: 3 additions & 1 deletion pyvo/registry/tests/test_regtap.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,13 +316,15 @@ def test_to_table(multi_interface_fixture, capabilities):
t = regtap.search(
ivoid="ivo://org.gavo.dc/flashheros/q/ssa").get_summary()
assert (set(t.columns.keys())
== {'index', 'short_name', 'title', 'description', 'interfaces'})
== {'index', 'short_name', 'title', 'description',
'interfaces', 'access_url'})
assert t["index"][0] == 0
assert t["title"][0] == 'Flash/Heros SSAP'
assert (t["description"][0][:40]
== 'Spectra from the Flash and Heros Echelle')
assert (t["interfaces"][0]
== 'datalink#links-1.0, soda#sync-1.0, ssa, tap#aux, web')
assert (t["access_url"][0] is None)


@pytest.fixture()
Expand Down

0 comments on commit 45c2dba

Please sign in to comment.