Skip to content

Commit f848924

Browse files
authored
Merge pull request #742 from stvoutsin/issue-708
ENH: Provide users with easy access to global variables
2 parents 8167742 + b52d461 commit f848924

File tree

10 files changed

+64
-8
lines changed

10 files changed

+64
-8
lines changed

CHANGES.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
Enhancements and Fixes
55
----------------------
66

7+
- Add ``pyvo.registry.get_RegTAP_service_url()`` to allow users to inspect the
8+
currently configured registry endpoint. Expose other user-facing constants at their package level. [#742]
9+
710
- Improve handling of timeouts in tap wait and _update [#740]
811

912
- Preserve text/plain error body in raise_if_error() after stream is consumed. [#736]

docs/registry/index.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,15 @@ Within a Python session, you can use the
604604
`pyvo.registry.choose_RegTAP_service` function, which also takes the
605605
TAP access URL.
606606

607+
To inspect which endpoint is currently in use, call
608+
`pyvo.registry.get_RegTAP_service_url`:
609+
610+
.. doctest::
611+
612+
>>> from pyvo import registry
613+
>>> registry.get_RegTAP_service_url()
614+
'http://reg.g-vo.org/tap'
615+
607616
As long as you have on working registry endpoint, you can find the other
608617
RegTAP services using:
609618

pyvo/auth/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# Licensed under a 3-clause BSD style license - see LICENSE.rst
22

3-
__all__ = ["AuthSession", "AuthURLs", "CredentialStore"]
3+
__all__ = ["AuthSession", "AuthURLs", "CredentialStore",
4+
"ANONYMOUS", "BASIC", "CLIENT_CERTIFICATE", "COOKIE"]
45

56
from .authsession import AuthSession
67
from .authurls import AuthURLs
78
from .credentialstore import CredentialStore
9+
from .securitymethods import ANONYMOUS, BASIC, CLIENT_CERTIFICATE, COOKIE

pyvo/dal/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
from .ssa import SSAService, SSAQuery, SSAResults, SSARecord
1414
from .sla import SLAService, SLAQuery, SLAResults, SLARecord
1515
from .scs import SCSService, SCSQuery, SCSResults, SCSRecord
16-
from .tap import TAPService, TAPQuery, TAPResults, AsyncTAPJob
16+
from .tap import TAPService, TAPQuery, TAPResults, AsyncTAPJob, DEFAULT_JOB_POLL_TIMEOUT, DEFAULT_JOB_WAIT_TIMEOUT
17+
from .adhoc import DATALINK_BATCH_CALL_SIZE
1718

1819

1920
from .exceptions import (
@@ -31,4 +32,6 @@
3132
"SIARecord", "SSARecord", "SLARecord", "SCSRecord",
3233
"AsyncTAPJob",
3334
"DALAccessError", "DALProtocolError", "DALFormatError", "DALServiceError",
34-
"DALQueryError", "DALOverflowWarning", "DALRateLimitError"]
35+
"DALQueryError", "DALOverflowWarning", "DALRateLimitError",
36+
"DEFAULT_JOB_POLL_TIMEOUT", "DEFAULT_JOB_WAIT_TIMEOUT",
37+
"DATALINK_BATCH_CALL_SIZE"]

pyvo/dal/adhoc.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ def new_resource_unknown_tag(self, iterator, tag, data, config, pos):
8383
__all__ = [
8484
"AdhocServiceResultsMixin", "DatalinkResultsMixin", "DatalinkRecordMixin",
8585
"DatalinkService", "DatalinkQuery", "DatalinkResults", "DatalinkRecord",
86-
"SodaRecordMixin", "SodaQuery"]
86+
"SodaRecordMixin", "SodaQuery",
87+
"DATALINK_BATCH_CALL_SIZE"]
8788

8889

8990
def _get_input_params_from_resource(resource):

pyvo/dal/tests/test_tap.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
import requests
1717
import requests_mock
1818

19+
from pyvo import dal
1920
from pyvo.dal.tap import escape, search, AsyncTAPJob, TAPService
2021
from pyvo.dal import DALQueryError, DALServiceError, DALOverflowWarning, DALRateLimitError
21-
2222
from pyvo.io.uws import JobFile
2323
from pyvo.io.uws.tree import Parameter, Result, ErrorSummary, Message
2424
from pyvo.io.vosi.exceptions import VOSIError
@@ -1828,3 +1828,9 @@ def test_rate_limit_on_tables_endpoint(self):
18281828
error = excinfo.value
18291829
assert error.retry_after_seconds == 60
18301830
assert error.code == 429
1831+
1832+
1833+
def test_public_constants_accessible_from_dal():
1834+
assert isinstance(dal.DEFAULT_JOB_POLL_TIMEOUT, (int, float))
1835+
assert isinstance(dal.DEFAULT_JOB_WAIT_TIMEOUT, (int, float))
1836+
assert isinstance(dal.DATALINK_BATCH_CALL_SIZE, int)

pyvo/dam/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Licensed under a 3-clause BSD style license - see LICENSE.rst
22
from .obscore import *
33

4-
__all__ = ["ObsCoreMetadata"]
4+
__all__ = ["ObsCoreMetadata", "POLARIZATION_STATES", "CALIBRATION_LEVELS"]

pyvo/registry/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from .regtap import (search, ivoid2service,
99
get_RegTAP_query,
10+
get_RegTAP_service_url,
1011
choose_RegTAP_service,
1112
RegistryResults, RegistryResource)
1213

@@ -15,7 +16,8 @@
1516
UCD, UAT, Spatial, Spectral, Temporal,
1617
RegTAPFeatureMissing)
1718

18-
__all__ = ["search", "get_RegTAP_query", "Constraint", "SubqueriedConstraint",
19+
__all__ = ["search", "get_RegTAP_query", "get_RegTAP_service_url",
20+
"Constraint", "SubqueriedConstraint",
1921
"Freetext", "Author",
2022
"Servicetype", "Waveband", "Datamodel", "Ivoid", "UCD",
2123
"UAT", "Spatial", "Spectral", "Temporal",

pyvo/registry/regtap.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
from ..utils.formatting import para_format_desc
3535

3636

37-
__all__ = ["search", "get_RegTAP_query", "Interface",
37+
__all__ = ["search", "get_RegTAP_query", "get_RegTAP_service_url", "Interface",
3838
"RegistryResource", "RegistryResults", "ivoid2service"]
3939

4040
REGISTRY_BASEURL = os.environ.get("IVOA_REGISTRY", "http://reg.g-vo.org/tap"
@@ -111,6 +111,22 @@ def get_RegTAP_service():
111111
return tap.TAPService(REGISTRY_BASEURL)
112112

113113

114+
def get_RegTAP_service_url():
115+
"""
116+
Return the access URL of the currently configured RegTAP service.
117+
118+
By default, pyVO uses whatever is given in the environment variable
119+
``IVOA_REGISTRY``, defaulting to GAVO's TAP service. To change this
120+
use :py:func:`pyvo.registry.choose_RegTAP_service`.
121+
122+
Returns
123+
-------
124+
str
125+
The TAP access URL of the current RegTAP endpoint.
126+
"""
127+
return REGISTRY_BASEURL
128+
129+
114130
def choose_RegTAP_service(access_url):
115131
"""
116132
changes the RegTAP service used by :py:func:`search`

pyvo/registry/tests/test_regtap.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -930,6 +930,20 @@ def test_sia2_service_operation():
930930
assert "s_dec" in res.to_table().columns
931931

932932

933+
def test_get_RegTAP_service_url_default():
934+
assert regtap.get_RegTAP_service_url() == regtap.REGISTRY_BASEURL
935+
936+
937+
def test_get_RegTAP_service_url_reflects_changes():
938+
alt_svc = "https://example.com/tap"
939+
previous_url = regtap.REGISTRY_BASEURL
940+
try:
941+
regtap.choose_RegTAP_service(alt_svc)
942+
assert regtap.get_RegTAP_service_url() == alt_svc
943+
finally:
944+
regtap.choose_RegTAP_service(previous_url)
945+
946+
933947
@pytest.mark.remote_data
934948
def test_endpoint_switching():
935949
alt_svc = "https://mast.stsci.edu/vo-tap/api/v0.1/registry"

0 commit comments

Comments
 (0)