Skip to content

Commit cd1327a

Browse files
authored
Feat: Add Source.connector_version property (#211)
1 parent 6b46c9b commit cd1327a

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

airbyte/_executor.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from shutil import rmtree
1111
from typing import IO, TYPE_CHECKING, Any, NoReturn, cast
1212

13+
from overrides import overrides
1314
from rich import print
1415
from typing_extensions import Literal
1516

@@ -78,6 +79,18 @@ def install(self) -> None:
7879
def uninstall(self) -> None:
7980
pass
8081

82+
def get_installed_version(
83+
self,
84+
*,
85+
raise_on_error: bool = False,
86+
recheck: bool = False,
87+
) -> str | None:
88+
"""Detect the version of the connector installed."""
89+
_ = raise_on_error, recheck # Unused
90+
raise NotImplementedError(
91+
f"'{type(self).__name__}' class cannot yet detect connector versions."
92+
)
93+
8194

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

240253
# Assuming the installation succeeded, store the installed version
241-
self.reported_version = self._get_installed_version(raise_on_error=False, recheck=True)
254+
self.reported_version = self.get_installed_version(raise_on_error=False, recheck=True)
242255
log_install_state(self.name, state=EventState.SUCCEEDED)
243256
print(
244257
f"Connector '{self.name}' installed successfully!\n"
245258
f"For more information, see the {self.name} documentation:\n"
246259
f"{self.docs_url}#reference\n"
247260
)
248261

249-
def _get_installed_version(
262+
@overrides
263+
def get_installed_version(
250264
self,
251265
*,
252266
raise_on_error: bool = False,
@@ -315,7 +329,7 @@ def ensure_installation(
315329
"""
316330
# Store the installed version (or None if not installed)
317331
if not self.reported_version:
318-
self.reported_version = self._get_installed_version()
332+
self.reported_version = self.get_installed_version()
319333

320334
original_installed_version = self.reported_version
321335

airbyte/sources/base.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,14 @@ def _with_logging(records: Iterable[dict[str, Any]]) -> Iterator[dict[str, Any]]
435435
stream_metadata=configured_stream,
436436
)
437437

438+
@property
439+
def connector_version(self) -> str | None:
440+
"""Return the version of the connector as reported by the executor.
441+
442+
Returns None if the version cannot be determined.
443+
"""
444+
return self.executor.get_installed_version()
445+
438446
def get_documents(
439447
self,
440448
stream: str,

tests/integration_tests/test_source_test_fixture.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ def test_version_enforcement(
239239
install_if_missing=False,
240240
)
241241
if requested_version: # Don't raise if a version is not requested
242-
assert source.executor._get_installed_version(raise_on_error=True) == (
242+
assert source.executor.get_installed_version(raise_on_error=True) == (
243243
requested_version or latest_available_version
244244
).replace("latest", latest_available_version)
245245
source.executor.ensure_installation(auto_fix=False)

0 commit comments

Comments
 (0)