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

airbyte-lib: Add uninstall #34105

Merged
merged 1 commit into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions airbyte-lib/airbyte_lib/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ def ensure_installation(self):
def install(self):
pass

@abstractmethod
def uninstall(self):
pass


@contextmanager
def _stream_from_subprocess(args: List[str]) -> Generator[Iterable[str], None, None]:
Expand Down Expand Up @@ -109,6 +113,11 @@ def _run_subprocess_and_raise_on_failure(self, args: List[str]):
if result.returncode != 0:
raise Exception(f"Install process exited with code {result.returncode}")

def uninstall(self):
venv_name = self._get_venv_name()
if os.path.exists(venv_name):
self._run_subprocess_and_raise_on_failure(["rm", "-rf", venv_name])

def install(self):
venv_name = self._get_venv_name()
self._run_subprocess_and_raise_on_failure([sys.executable, "-m", "venv", venv_name])
Expand Down Expand Up @@ -187,6 +196,9 @@ def ensure_installation(self):
def install(self):
raise Exception(f"Connector {self.metadata.name} is not available - cannot install it")

def uninstall(self):
raise Exception(f"Connector {self.metadata.name} is installed manually and not managed by airbyte-lib - please remove it manually")

def execute(self, args: List[str]) -> Iterable[str]:
with _stream_from_subprocess([self.metadata.name] + args) as stream:
yield from stream
2 changes: 1 addition & 1 deletion airbyte-lib/airbyte_lib/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def get_connector(
pip_url: str | None = None,
config: dict[str, Any] | None = None,
use_local_install: bool = False,
install_if_missing: bool = False,
install_if_missing: bool = True,
):
"""
Get a connector by name and version.
Expand Down
9 changes: 9 additions & 0 deletions airbyte-lib/airbyte_lib/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,17 @@ def check(self):
raise Exception(f"Connector did not return check status. Last logs: {self._last_log_messages}")

def install(self):
"""
Install the connector if it is not yet installed.
"""
self.executor.install()

def uninstall(self):
"""
Uninstall the connector if it is installed. This only works if the use_local_install flag wasn't used and installation is managed by airbyte-lib.
"""
self.executor.uninstall()

def _read(self) -> Iterable[AirbyteRecordMessage]:
"""
Call read on the connector.
Expand Down
35 changes: 21 additions & 14 deletions airbyte-lib/docs/generated/airbyte_lib.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions airbyte-lib/docs/generated/airbyte_lib/datasets.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading