Skip to content

Commit

Permalink
Feat: Add Source.connector_version property (#211)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronsteers authored May 7, 2024
1 parent 6b46c9b commit cd1327a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
20 changes: 17 additions & 3 deletions airbyte/_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from shutil import rmtree
from typing import IO, TYPE_CHECKING, Any, NoReturn, cast

from overrides import overrides
from rich import print
from typing_extensions import Literal

Expand Down Expand Up @@ -78,6 +79,18 @@ def install(self) -> None:
def uninstall(self) -> None:
pass

def get_installed_version(
self,
*,
raise_on_error: bool = False,
recheck: bool = False,
) -> str | None:
"""Detect the version of the connector installed."""
_ = raise_on_error, recheck # Unused
raise NotImplementedError(
f"'{type(self).__name__}' class cannot yet detect connector versions."
)


@contextmanager
def _stream_from_subprocess(args: list[str]) -> Generator[Iterable[str], None, None]:
Expand Down Expand Up @@ -238,15 +251,16 @@ def install(self) -> None:
raise exc.AirbyteConnectorInstallationError from ex

# Assuming the installation succeeded, store the installed version
self.reported_version = self._get_installed_version(raise_on_error=False, recheck=True)
self.reported_version = self.get_installed_version(raise_on_error=False, recheck=True)
log_install_state(self.name, state=EventState.SUCCEEDED)
print(
f"Connector '{self.name}' installed successfully!\n"
f"For more information, see the {self.name} documentation:\n"
f"{self.docs_url}#reference\n"
)

def _get_installed_version(
@overrides
def get_installed_version(
self,
*,
raise_on_error: bool = False,
Expand Down Expand Up @@ -315,7 +329,7 @@ def ensure_installation(
"""
# Store the installed version (or None if not installed)
if not self.reported_version:
self.reported_version = self._get_installed_version()
self.reported_version = self.get_installed_version()

original_installed_version = self.reported_version

Expand Down
8 changes: 8 additions & 0 deletions airbyte/sources/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,14 @@ def _with_logging(records: Iterable[dict[str, Any]]) -> Iterator[dict[str, Any]]
stream_metadata=configured_stream,
)

@property
def connector_version(self) -> str | None:
"""Return the version of the connector as reported by the executor.
Returns None if the version cannot be determined.
"""
return self.executor.get_installed_version()

def get_documents(
self,
stream: str,
Expand Down
2 changes: 1 addition & 1 deletion tests/integration_tests/test_source_test_fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def test_version_enforcement(
install_if_missing=False,
)
if requested_version: # Don't raise if a version is not requested
assert source.executor._get_installed_version(raise_on_error=True) == (
assert source.executor.get_installed_version(raise_on_error=True) == (
requested_version or latest_available_version
).replace("latest", latest_available_version)
source.executor.ensure_installation(auto_fix=False)
Expand Down

0 comments on commit cd1327a

Please sign in to comment.