Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to create blocks from Python API #9

Merged
merged 9 commits into from
Apr 11, 2024
Prev Previous commit
Next Next commit
Make supported server versions configurable at client level
  • Loading branch information
ml-evs committed Apr 11, 2024
commit 491ee9dd45a55921b8b1da751e30217dd4573615
15 changes: 9 additions & 6 deletions src/datalab_api/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
import httpx
from rich.logging import RichHandler

BAD_SERVER_VERSIONS = ((0, 2, 0),)
BAD_API_VERSIONS = ((0, 0, 0),)
MIN_API_VERSION = (0, 1, 0)

__version__ = version("datalab-api")

__all__ = ("__version__", "BaseDatalabClient")
Expand All @@ -27,6 +23,13 @@ class BaseDatalabClient:
_session: httpx.Client | None = None
_headers: dict[str, str] = {}

bad_server_versions: tuple[tuple[int, int, int]] | None = ((0, 2, 0),)
"""Any known server versions that are not supported by this client."""

min_server_version: tuple[int, int, int] = (0, 1, 0)
"""The minimum supported server version that this client supports."""


def __init__(self, datalab_api_url: str, log_level: str = "WARNING"):
"""Creates an authenticated client.

Expand Down Expand Up @@ -91,13 +94,13 @@ def _version_negotiation(self):

for available_api_version in sorted(self._datalab_api_versions):
major, minor, _ = (int(_) for _ in available_api_version.split("."))
if major == MIN_API_VERSION[0] and minor == MIN_API_VERSION[1]:
if major == self.min_api_version[0] and minor == self.min_api_version[1]:
self._selected_api_version = available_api_version
break
else:
raise RuntimeError(f"No supported API versions found in {self._datalab_api_versions=}")

if self._datalab_server_version in BAD_SERVER_VERSIONS:
if self._datalab_server_version in self.bad_server_versions:
raise RuntimeError(
f"Server version {self._datalab_server_version} is not supported by this client."
)
Expand Down
Loading