Skip to content

Commit

Permalink
Merge pull request #523 from msdemlei/fix-alt-identifier-overselect
Browse files Browse the repository at this point in the history
Backing out of requesting alt_identifiers every time.
  • Loading branch information
bsipocz committed Feb 22, 2024
1 parent bd551b5 commit 559de7c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 19 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Enhancements and Fixes

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

- Backing out of having alt_identifier in RegistryResource throughout.
Use get_alt_identifier() instead [#523]


1.5 (2023-12-19)
Expand Down
32 changes: 20 additions & 12 deletions pyvo/registry/regtap.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,8 +487,7 @@ class RegistryResource(dalq.Record):
(f"\n ivo_string_agg(COALESCE(intf_type, ''), '{TOKEN_SEP}')",
"intf_types"),
(f"\n ivo_string_agg(COALESCE(intf_role, ''), '{TOKEN_SEP}')",
"intf_roles"),
"alt_identifier"]
"intf_roles")]

def __init__(self, results, index, session=None):
dalq.Record.__init__(self, results, index, session=session)
Expand Down Expand Up @@ -584,14 +583,6 @@ def reference_url(self):
"""
return self.get("reference_url", decode=True)

@property
def alt_identifier(self):
"""Alternative identifier.
It is often used to provide the resource associated DOI.
"""
return self.get("alt_identifier", decode=True)

@property
def creators(self):
"""
Expand Down Expand Up @@ -935,8 +926,14 @@ def describe(self, verbose=False, width=78, file=None):
else:
print(f"Authors: {', '.join(creators[:nmax_authors])} et al.\n"
"See creators attribute for the complete list of authors.", file=file)
if self.alt_identifier:
print(f"Alternative identifier: {self.alt_identifier}", file=file)

alt_identifiers = self.get_alt_identifiers()
if alt_identifiers:
print(
"Alternative identifier(s): {}".format(
", ".join(alt_identifiers)),
file=file)

if self.reference_url:
print("More info: " + self.reference_url, file=file)

Expand Down Expand Up @@ -965,6 +962,17 @@ def get_contact(self):

return "\n".join(contacts)

def get_alt_identifiers(self):
"""return a sequence of non-ivoid identifiers for the resource.
This is typically used to provide a DOI for the resource.
"""
res = get_RegTAP_service().run_sync("""
SELECT alt_identifier
FROM rr.alt_identifier
WHERE ivoid={}""".format(rtcons.make_sql_literal(self.ivoid)))
return [r["alt_identifier"] for r in res]

def _build_vosi_column(self, column_row):
"""
return a io.vosi.vodataservice.Column element for a
Expand Down
14 changes: 13 additions & 1 deletion pyvo/registry/tests/test_regtap.py
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,15 @@ def test_get_contact():
" <gavo@ari.uni-heidelberg.de>")


@pytest.mark.remote_data
def test_get_alt_identifier():
rsc = _makeRegistryRecord(ivoid="ivo://cds.vizier/i/337")
assert set(rsc.get_alt_identifiers()) == {
'doi:10.26093/cds/vizier.1337',
'bibcode:doi:10.5270/esa-ogmeula',
'bibcode:2016yCat.1337....0G'}


@pytest.mark.remote_data
class TestDatamodelQueries:
# right now, the data model queries are all rather sui generis, and
Expand Down Expand Up @@ -725,6 +734,7 @@ def test_unique_standard_id(self):
intf_roles=["std"])
assert rsc.standard_id == "ivo://ivoa.net/std/tap"

@pytest.mark.remote_data
def test_describe_multi(self, flash_service):
out = io.StringIO()
flash_service.describe(verbose=True, file=out)
Expand All @@ -736,9 +746,10 @@ def test_describe_multi(self, flash_service):
assert "Multi-capability service" in output
assert "Source: 1996A&A...312..539S" in output
assert "Authors: Wolf" in output
assert "Alternative identifier: doi:10.21938/" in output
assert "Alternative identifier(s): doi:10.21938/" in output
assert "More info: http://dc.zah" in output

@pytest.mark.remote_data
def test_describe_long_authors_list(self):
"""Check that long list of authors use et al.."""
rsc = _makeRegistryRecord(
Expand All @@ -756,6 +767,7 @@ def test_describe_long_authors_list(self):
# output should cut at 5 authors
assert "Authors: a, a, a, a, a et al." in output

@pytest.mark.remote_data
def test_describe_long_author_name(self):
"""Check that long author names are truncated."""
rsc = _makeRegistryRecord(
Expand Down
9 changes: 3 additions & 6 deletions pyvo/registry/tests/test_rtcons.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,8 +449,7 @@ def test_expected_columns(self):
"\n ivo_string_agg(COALESCE(access_url, ''), ':::py VO sep:::') AS access_urls, "
"\n ivo_string_agg(COALESCE(standard_id, ''), ':::py VO sep:::') AS standard_ids, "
"\n ivo_string_agg(COALESCE(intf_type, ''), ':::py VO sep:::') AS intf_types, "
"\n ivo_string_agg(COALESCE(intf_role, ''), ':::py VO sep:::') AS intf_roles, "
"alt_identifier")
"\n ivo_string_agg(COALESCE(intf_role, ''), ':::py VO sep:::') AS intf_roles, ")

def test_group_by_columns(self):
# Again, this will break as regtap.RegistryResource.expected_columns
Expand All @@ -471,8 +470,7 @@ def test_group_by_columns(self):
"source_format, "
"source_value, "
"region_of_regard, "
"waveband, "
"alt_identifier"))
"waveband"))

def test_joined_tables(self):
expected_tables = [
Expand All @@ -482,7 +480,6 @@ def test_joined_tables(self):
"rr.resource",
"rr.capability",
"rr.interface",
"rr.alt_identifier"
]
assert all(table in _build_regtap_query_with_fake([rtcons.Author("%Hubble%")])
for table in expected_tables)
Expand Down Expand Up @@ -510,4 +507,4 @@ def test_all_constraints():
'reference_url', 'creator_seq', 'created', 'updated',
'rights', 'content_type', 'source_format', 'source_value',
'region_of_regard', 'waveband', 'access_urls', 'standard_ids',
'intf_types', 'intf_roles', 'cap_descriptions', 'alt_identifier')
'intf_types', 'intf_roles', 'cap_descriptions')

0 comments on commit 559de7c

Please sign in to comment.