Skip to content

Commit

Permalink
added arbitrary args to InstallOfflineWheel
Browse files Browse the repository at this point in the history
  • Loading branch information
chenkasirer committed Jan 15, 2025
1 parent 63eb35f commit 3743425
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
7 changes: 5 additions & 2 deletions src/installlib/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,20 @@ def execute(self):


class InstallOfflineWheel:
def __init__(self, path, virtual_env, name=None) -> None:
def __init__(self, path, virtual_env, name=None, args=None) -> None:
self.name = name or InstallOfflineWheel.__name__
self.path = path
self.virtual_env = virtual_env
self.args = args or []

def execute(self):
try:
env = self.virtual_env() if callable(self.virtual_env) else self.virtual_env
activate_cmd = env.activate
# --quiet is important: if PIPE gets full the process will hang
install_cmd = ["python", "-m", "pip", "install", "--quiet", self.path]
install_cmd = ["python", "-m", "pip", "install", "--quiet"]
install_cmd += self.args
install_cmd += [self.path]
start_command([activate_cmd, "&&", *install_cmd])
except Exception as ex:
return False, f"Failed to install wheel: {self.path} to virtual environment: {ex}"
Expand Down
29 changes: 29 additions & 0 deletions tests/test_tasks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import pytest

from installlib.tasks import InstallOfflineWheel


def test_install_offline_wheel(mocker):
mock_start_command = mocker.patch("installlib.tasks.start_command")
mock_env = mocker.Mock(return_value=mocker.Mock(activate="activate"))

path_to_wheel = r"C:\path\to\wheel.whl"

task = InstallOfflineWheel(path_to_wheel, mock_env)

task.execute()

mock_start_command.assert_called_once_with(["activate", "&&", "python", "-m", "pip", "install", "--quiet", path_to_wheel])


def test_install_offline_wheel_extra_args(mocker):
mock_start_command = mocker.patch("installlib.tasks.start_command")
mock_env = mocker.Mock(return_value=mocker.Mock(activate="activate"))

path_to_wheel = r"C:\path\to\wheel.whl"

task = InstallOfflineWheel(path_to_wheel, mock_env, args=["--update", "--force-reinstall", "--no-deps"])

task.execute()

mock_start_command.assert_called_once_with(["activate", "&&", "python", "-m", "pip", "install", "--quiet", "--update", "--force-reinstall", "--no-deps", path_to_wheel])
5 changes: 0 additions & 5 deletions tests/test_trivial.py

This file was deleted.

0 comments on commit 3743425

Please # to comment.