From 5ad60a1bb2f59d5b2e5a0989b34c0312cf1249b7 Mon Sep 17 00:00:00 2001 From: Aaron Kanzer Date: Fri, 15 Nov 2024 10:01:29 -0500 Subject: [PATCH 1/3] Include LINC API as a supported instance type for DANDI CLI --- dandi/cli/tests/test_instances.py | 6 ++++++ dandi/consts.py | 10 ++++++++++ dandi/tests/test_dandiarchive.py | 9 +++++---- dandi/utils.py | 28 ++++++++++++++-------------- 4 files changed, 35 insertions(+), 18 deletions(-) diff --git a/dandi/cli/tests/test_instances.py b/dandi/cli/tests/test_instances.py index 4e058db28..192b69659 100644 --- a/dandi/cli/tests/test_instances.py +++ b/dandi/cli/tests/test_instances.py @@ -19,4 +19,10 @@ def test_cmd_instances(monkeypatch): "dandi-staging:\n" " api: https://api-staging.dandiarchive.org/api\n" " gui: https://gui-staging.dandiarchive.org\n" + "linc:\n" + " api: https://api.lincbrain.org/api\n" + " gui: https://lincbrain.org\n" + "linc-staging:\n" + " api: https://staging-api.lincbrain.org/api\n" + " gui: https://staging.lincbrain.org\n" ) diff --git a/dandi/consts.py b/dandi/consts.py index 14eceab4f..0b7bc1b76 100644 --- a/dandi/consts.py +++ b/dandi/consts.py @@ -132,6 +132,16 @@ def urls(self) -> Iterator[str]: f"http://{instancehost}:8085", f"http://{instancehost}:8000/api", ), + "linc": DandiInstance( + "linc", + "https://lincbrain.org", + "https://api.lincbrain.org/api", + ), + "linc-staging": DandiInstance( + "linc-staging", + "https://staging.lincbrain.org", + "https://staging-api.lincbrain.org/api", + ) } # to map back url: name known_instances_rev = { diff --git a/dandi/tests/test_dandiarchive.py b/dandi/tests/test_dandiarchive.py index 690fda63f..a6f7bd8ba 100644 --- a/dandi/tests/test_dandiarchive.py +++ b/dandi/tests/test_dandiarchive.py @@ -439,10 +439,11 @@ def test_known_instances() -> None: def test_parse_dandi_url_unknown_instance() -> None: with pytest.raises(UnknownURLError) as excinfo: parse_dandi_url("dandi://not-an-instance/000001") - assert str(excinfo.value) == ( - "Unknown instance 'not-an-instance'. Valid instances: dandi," - " dandi-api-local-docker-tests, dandi-staging" - ) + + valid_instances = ", ".join(sorted(known_instances.keys())) + expected_message = f"Unknown instance 'not-an-instance'. Valid instances: {valid_instances}" + + assert str(excinfo.value) == expected_message @mark.skipif_no_network diff --git a/dandi/utils.py b/dandi/utils.py index b7f9ed5b5..17a7cea5b 100644 --- a/dandi/utils.py +++ b/dandi/utils.py @@ -604,19 +604,19 @@ def _get_instance( f"Could not retrieve server info from {url}," " and client does not recognize URL" ) - try: - minversion = Version(server_info.cli_minimal_version) - bad_versions = [Version(v) for v in server_info.cli_bad_versions] - except ValueError as e: - raise ValueError( - f"{url} returned an incorrectly formatted version;" - f" please contact that server's administrators: {e}" - ) - our_version = Version(__version__) - if our_version < minversion: - raise CliVersionTooOldError(our_version, minversion, bad_versions) - if our_version in bad_versions: - raise BadCliVersionError(our_version, minversion, bad_versions) + # try: + # minversion = Version(server_info.cli_minimal_version) + # bad_versions = [Version(v) for v in server_info.cli_bad_versions] + # except ValueError as e: + # raise ValueError( + # f"{url} returned an incorrectly formatted version;" + # f" please contact that server's administrators: {e}" + # ) + # our_version = Version(__version__) + # if our_version < minversion: + # raise CliVersionTooOldError(our_version, minversion, bad_versions) + # if our_version in bad_versions: + # raise BadCliVersionError(our_version, minversion, bad_versions) api_url = server_info.services.api.url if dandi_id is None: # Don't use pydantic.AnyHttpUrl, as that sets the `port` attribute even @@ -642,7 +642,7 @@ def _get_instance( def is_url(s: str) -> bool: - """Very primitive url detection for now + """Very primitive url detection TODO: redo """ From e6bf1a7121d96377eec924d1326c0778a381c586 Mon Sep 17 00:00:00 2001 From: Aaron Kanzer Date: Fri, 15 Nov 2024 10:02:16 -0500 Subject: [PATCH 2/3] revert uncommented out code --- dandi/utils.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/dandi/utils.py b/dandi/utils.py index 17a7cea5b..b7f9ed5b5 100644 --- a/dandi/utils.py +++ b/dandi/utils.py @@ -604,19 +604,19 @@ def _get_instance( f"Could not retrieve server info from {url}," " and client does not recognize URL" ) - # try: - # minversion = Version(server_info.cli_minimal_version) - # bad_versions = [Version(v) for v in server_info.cli_bad_versions] - # except ValueError as e: - # raise ValueError( - # f"{url} returned an incorrectly formatted version;" - # f" please contact that server's administrators: {e}" - # ) - # our_version = Version(__version__) - # if our_version < minversion: - # raise CliVersionTooOldError(our_version, minversion, bad_versions) - # if our_version in bad_versions: - # raise BadCliVersionError(our_version, minversion, bad_versions) + try: + minversion = Version(server_info.cli_minimal_version) + bad_versions = [Version(v) for v in server_info.cli_bad_versions] + except ValueError as e: + raise ValueError( + f"{url} returned an incorrectly formatted version;" + f" please contact that server's administrators: {e}" + ) + our_version = Version(__version__) + if our_version < minversion: + raise CliVersionTooOldError(our_version, minversion, bad_versions) + if our_version in bad_versions: + raise BadCliVersionError(our_version, minversion, bad_versions) api_url = server_info.services.api.url if dandi_id is None: # Don't use pydantic.AnyHttpUrl, as that sets the `port` attribute even @@ -642,7 +642,7 @@ def _get_instance( def is_url(s: str) -> bool: - """Very primitive url detection + """Very primitive url detection for now TODO: redo """ From 284ead15d4779f85b181a8b75904df8aa53b65fb Mon Sep 17 00:00:00 2001 From: Aaron Kanzer Date: Fri, 15 Nov 2024 14:13:29 -0500 Subject: [PATCH 3/3] bump docs for instances --- docs/source/cmdline/instances.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/source/cmdline/instances.rst b/docs/source/cmdline/instances.rst index 3bdbb1f79..a4a935682 100644 --- a/docs/source/cmdline/instances.rst +++ b/docs/source/cmdline/instances.rst @@ -22,3 +22,9 @@ Example output: dandi-staging: api: https://api-staging.dandiarchive.org/api gui: https://gui-staging.dandiarchive.org + linc-staging: + api: https://staging-api.lincbrain.org/api + gui: https://staging.lincbrain.org + linc: + api: https://api.lincbrain.org/api + gui: https://lincbrain.org \ No newline at end of file