diff --git a/src/ga4gh/vrs/dataproxy.py b/src/ga4gh/vrs/dataproxy.py index 8e593069..12c70790 100644 --- a/src/ga4gh/vrs/dataproxy.py +++ b/src/ga4gh/vrs/dataproxy.py @@ -247,13 +247,17 @@ class SeqRepoRESTDataProxy(_SeqRepoDataProxyBase): rest_version = "1" - def __init__(self, base_url: str): + def __init__(self, base_url: str, disable_healthcheck: bool = False): """Initialize REST-based dataproxy instance. :param base_url: root URL to server """ super().__init__() self.base_url = f"{base_url}/{self.rest_version}/" + if not disable_healthcheck: + ping_url = self.base_url + "ping" + ping_resp = requests.get(ping_url) # noqa: S113 + ping_resp.raise_for_status() def _get_sequence( self, identifier: str, start: int | None = None, end: int | None = None diff --git a/src/ga4gh/vrs/extras/annotator/cli.py b/src/ga4gh/vrs/extras/annotator/cli.py index a015698e..4ebdb206 100644 --- a/src/ga4gh/vrs/extras/annotator/cli.py +++ b/src/ga4gh/vrs/extras/annotator/cli.py @@ -11,7 +11,6 @@ from timeit import default_timer as timer import click -import requests from ga4gh.vrs.dataproxy import create_dataproxy from ga4gh.vrs.extras.annotator.vcf import VcfAnnotator, VcfAnnotatorArgsError @@ -200,14 +199,6 @@ def _annotate_vcf_cli( * seqrepo+:../relative/path/to/seqrepo/root """ # noqa: D301 data_proxy = create_dataproxy(dataproxy_uri) - try: - data_proxy.get_metadata("GRCh38:1") - except requests.exceptions.ConnectionError: - msg = f"Connection to SeqRepo dataproxy at {dataproxy_uri} failed. Is the REST service running?" - _logger.exception(msg) - if not silent: - click.echo(msg, err=True) - exit(1) annotator = VcfAnnotator(data_proxy) start = timer() msg = f"Annotating {vcf_in} with the VCF Annotator..." diff --git a/tests/conftest.py b/tests/conftest.py index 97b5b02c..4c843539 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -39,7 +39,8 @@ def dataproxy(): @pytest.fixture(scope="session") def rest_dataproxy(): return SeqRepoRESTDataProxy( - base_url=os.environ.get("SEQREPO_REST_URL", "http://localhost:5000/seqrepo") + base_url=os.environ.get("SEQREPO_REST_URL", "http://localhost:5000/seqrepo"), + disable_healthcheck=True, ) diff --git a/tests/extras/cassettes/test_annotate_vcf_grch37_attrs.yaml b/tests/extras/cassettes/test_annotate_vcf_grch37_attrs.yaml index be51c7b6..4808b890 100644 --- a/tests/extras/cassettes/test_annotate_vcf_grch37_attrs.yaml +++ b/tests/extras/cassettes/test_annotate_vcf_grch37_attrs.yaml @@ -1,4 +1,20 @@ interactions: +- request: + body: null + headers: {} + method: GET + uri: http://localhost:5000/seqrepo/1/ping + response: + body: + string: "{\n \"dependencies\": {\n \"bioutils\": {\n \"url\": \"https://github.com/biocommons/bioutils/\",\n + \ \"version\": \"0.5.8.post1\"\n },\n \"seqrepo\": {\n \"root\": + \"/usr/local/share/seqrepo/2024-12-20\",\n \"url\": \"https://github.com/biocommons/biocommons.seqrepo/\",\n + \ \"version\": \"0.6.6\"\n }\n },\n \"url\": \"https://github.com/biocommons/seqrepo-rest-service/\",\n + \ \"version\": \"0.2.3.dev0+ge4124b9.d20231114\"\n}\n" + headers: {} + status: + code: 200 + message: OK - request: body: null headers: {} diff --git a/tests/extras/cassettes/test_annotate_vcf_grch38_attrs.yaml b/tests/extras/cassettes/test_annotate_vcf_grch38_attrs.yaml index 48f1f0db..11fe7069 100644 --- a/tests/extras/cassettes/test_annotate_vcf_grch38_attrs.yaml +++ b/tests/extras/cassettes/test_annotate_vcf_grch38_attrs.yaml @@ -1,4 +1,20 @@ interactions: +- request: + body: null + headers: {} + method: GET + uri: http://localhost:5000/seqrepo/1/ping + response: + body: + string: "{\n \"dependencies\": {\n \"bioutils\": {\n \"url\": \"https://github.com/biocommons/bioutils/\",\n + \ \"version\": \"0.5.8.post1\"\n },\n \"seqrepo\": {\n \"root\": + \"/usr/local/share/seqrepo/2024-12-20\",\n \"url\": \"https://github.com/biocommons/biocommons.seqrepo/\",\n + \ \"version\": \"0.6.6\"\n }\n },\n \"url\": \"https://github.com/biocommons/seqrepo-rest-service/\",\n + \ \"version\": \"0.2.3.dev0+ge4124b9.d20231114\"\n}\n" + headers: {} + status: + code: 200 + message: OK - request: body: null headers: {} diff --git a/tests/extras/cassettes/test_annotate_vcf_grch38_attrs_altsonly.yaml b/tests/extras/cassettes/test_annotate_vcf_grch38_attrs_altsonly.yaml index 48f1f0db..11fe7069 100644 --- a/tests/extras/cassettes/test_annotate_vcf_grch38_attrs_altsonly.yaml +++ b/tests/extras/cassettes/test_annotate_vcf_grch38_attrs_altsonly.yaml @@ -1,4 +1,20 @@ interactions: +- request: + body: null + headers: {} + method: GET + uri: http://localhost:5000/seqrepo/1/ping + response: + body: + string: "{\n \"dependencies\": {\n \"bioutils\": {\n \"url\": \"https://github.com/biocommons/bioutils/\",\n + \ \"version\": \"0.5.8.post1\"\n },\n \"seqrepo\": {\n \"root\": + \"/usr/local/share/seqrepo/2024-12-20\",\n \"url\": \"https://github.com/biocommons/biocommons.seqrepo/\",\n + \ \"version\": \"0.6.6\"\n }\n },\n \"url\": \"https://github.com/biocommons/seqrepo-rest-service/\",\n + \ \"version\": \"0.2.3.dev0+ge4124b9.d20231114\"\n}\n" + headers: {} + status: + code: 200 + message: OK - request: body: null headers: {} diff --git a/tests/extras/cassettes/test_annotate_vcf_grch38_noattrs.yaml b/tests/extras/cassettes/test_annotate_vcf_grch38_noattrs.yaml index 48f1f0db..11fe7069 100644 --- a/tests/extras/cassettes/test_annotate_vcf_grch38_noattrs.yaml +++ b/tests/extras/cassettes/test_annotate_vcf_grch38_noattrs.yaml @@ -1,4 +1,20 @@ interactions: +- request: + body: null + headers: {} + method: GET + uri: http://localhost:5000/seqrepo/1/ping + response: + body: + string: "{\n \"dependencies\": {\n \"bioutils\": {\n \"url\": \"https://github.com/biocommons/bioutils/\",\n + \ \"version\": \"0.5.8.post1\"\n },\n \"seqrepo\": {\n \"root\": + \"/usr/local/share/seqrepo/2024-12-20\",\n \"url\": \"https://github.com/biocommons/biocommons.seqrepo/\",\n + \ \"version\": \"0.6.6\"\n }\n },\n \"url\": \"https://github.com/biocommons/seqrepo-rest-service/\",\n + \ \"version\": \"0.2.3.dev0+ge4124b9.d20231114\"\n}\n" + headers: {} + status: + code: 200 + message: OK - request: body: null headers: {} diff --git a/tests/extras/cassettes/test_annotate_vcf_input_validation.yaml b/tests/extras/cassettes/test_annotate_vcf_input_validation.yaml new file mode 100644 index 00000000..be104761 --- /dev/null +++ b/tests/extras/cassettes/test_annotate_vcf_input_validation.yaml @@ -0,0 +1,18 @@ +interactions: +- request: + body: null + headers: {} + method: GET + uri: http://localhost:5000/seqrepo/1/ping + response: + body: + string: "{\n \"dependencies\": {\n \"bioutils\": {\n \"url\": \"https://github.com/biocommons/bioutils/\",\n + \ \"version\": \"0.5.8.post1\"\n },\n \"seqrepo\": {\n \"root\": + \"/usr/local/share/seqrepo/2024-12-20\",\n \"url\": \"https://github.com/biocommons/biocommons.seqrepo/\",\n + \ \"version\": \"0.6.6\"\n }\n },\n \"url\": \"https://github.com/biocommons/seqrepo-rest-service/\",\n + \ \"version\": \"0.2.3.dev0+ge4124b9.d20231114\"\n}\n" + headers: {} + status: + code: 200 + message: OK +version: 1 diff --git a/tests/extras/cassettes/test_annotate_vcf_pickle_only.yaml b/tests/extras/cassettes/test_annotate_vcf_pickle_only.yaml index 48f1f0db..11fe7069 100644 --- a/tests/extras/cassettes/test_annotate_vcf_pickle_only.yaml +++ b/tests/extras/cassettes/test_annotate_vcf_pickle_only.yaml @@ -1,4 +1,20 @@ interactions: +- request: + body: null + headers: {} + method: GET + uri: http://localhost:5000/seqrepo/1/ping + response: + body: + string: "{\n \"dependencies\": {\n \"bioutils\": {\n \"url\": \"https://github.com/biocommons/bioutils/\",\n + \ \"version\": \"0.5.8.post1\"\n },\n \"seqrepo\": {\n \"root\": + \"/usr/local/share/seqrepo/2024-12-20\",\n \"url\": \"https://github.com/biocommons/biocommons.seqrepo/\",\n + \ \"version\": \"0.6.6\"\n }\n },\n \"url\": \"https://github.com/biocommons/seqrepo-rest-service/\",\n + \ \"version\": \"0.2.3.dev0+ge4124b9.d20231114\"\n}\n" + headers: {} + status: + code: 200 + message: OK - request: body: null headers: {} diff --git a/tests/extras/cassettes/test_annotate_vcf_rle.yaml b/tests/extras/cassettes/test_annotate_vcf_rle.yaml index 2ba6fd04..5f027f36 100644 --- a/tests/extras/cassettes/test_annotate_vcf_rle.yaml +++ b/tests/extras/cassettes/test_annotate_vcf_rle.yaml @@ -1,4 +1,20 @@ interactions: +- request: + body: null + headers: {} + method: GET + uri: http://localhost:5000/seqrepo/1/ping + response: + body: + string: "{\n \"dependencies\": {\n \"bioutils\": {\n \"url\": \"https://github.com/biocommons/bioutils/\",\n + \ \"version\": \"0.5.8.post1\"\n },\n \"seqrepo\": {\n \"root\": + \"/usr/local/share/seqrepo/2024-12-20\",\n \"url\": \"https://github.com/biocommons/biocommons.seqrepo/\",\n + \ \"version\": \"0.6.6\"\n }\n },\n \"url\": \"https://github.com/biocommons/seqrepo-rest-service/\",\n + \ \"version\": \"0.2.3.dev0+ge4124b9.d20231114\"\n}\n" + headers: {} + status: + code: 200 + message: OK - request: body: null headers: {} diff --git a/tests/extras/cassettes/test_annotate_vcf_vcf_only.yaml b/tests/extras/cassettes/test_annotate_vcf_vcf_only.yaml index 48f1f0db..11fe7069 100644 --- a/tests/extras/cassettes/test_annotate_vcf_vcf_only.yaml +++ b/tests/extras/cassettes/test_annotate_vcf_vcf_only.yaml @@ -1,4 +1,20 @@ interactions: +- request: + body: null + headers: {} + method: GET + uri: http://localhost:5000/seqrepo/1/ping + response: + body: + string: "{\n \"dependencies\": {\n \"bioutils\": {\n \"url\": \"https://github.com/biocommons/bioutils/\",\n + \ \"version\": \"0.5.8.post1\"\n },\n \"seqrepo\": {\n \"root\": + \"/usr/local/share/seqrepo/2024-12-20\",\n \"url\": \"https://github.com/biocommons/biocommons.seqrepo/\",\n + \ \"version\": \"0.6.6\"\n }\n },\n \"url\": \"https://github.com/biocommons/seqrepo-rest-service/\",\n + \ \"version\": \"0.2.3.dev0+ge4124b9.d20231114\"\n}\n" + headers: {} + status: + code: 200 + message: OK - request: body: null headers: {} diff --git a/tests/extras/cassettes/test_get_vrs_object_invalid_input.yaml b/tests/extras/cassettes/test_get_vrs_object_invalid_input.yaml index 11a2ee4b..8055c3b5 100644 --- a/tests/extras/cassettes/test_get_vrs_object_invalid_input.yaml +++ b/tests/extras/cassettes/test_get_vrs_object_invalid_input.yaml @@ -1,4 +1,20 @@ interactions: +- request: + body: null + headers: {} + method: GET + uri: http://localhost:5000/seqrepo/1/ping + response: + body: + string: "{\n \"dependencies\": {\n \"bioutils\": {\n \"url\": \"https://github.com/biocommons/bioutils/\",\n + \ \"version\": \"0.5.8.post1\"\n },\n \"seqrepo\": {\n \"root\": + \"/usr/local/share/seqrepo/2024-12-20\",\n \"url\": \"https://github.com/biocommons/biocommons.seqrepo/\",\n + \ \"version\": \"0.6.6\"\n }\n },\n \"url\": \"https://github.com/biocommons/seqrepo-rest-service/\",\n + \ \"version\": \"0.2.3.dev0+ge4124b9.d20231114\"\n}\n" + headers: {} + status: + code: 200 + message: OK - request: body: null headers: {} diff --git a/tests/extras/test_annotate_vcf.py b/tests/extras/test_annotate_vcf.py index 7e085f2d..0f5ca0e6 100644 --- a/tests/extras/test_annotate_vcf.py +++ b/tests/extras/test_annotate_vcf.py @@ -182,6 +182,7 @@ def test_annotate_vcf_vcf_only( assert not Path(output_vrs_pkl).exists() +@pytest.mark.vcr def test_annotate_vcf_input_validation(vcf_annotator: VcfAnnotator, input_vcf: Path): with pytest.raises( VcfAnnotatorError,