Skip to content

Commit

Permalink
Shell out to pip instead of using the pip module (#13)
Browse files Browse the repository at this point in the history
* Shell out to pip instead of using the pip module

* Test pip install
  • Loading branch information
jacobtomlinson committed Aug 6, 2016
1 parent 8ee3d20 commit e025fc1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
17 changes: 14 additions & 3 deletions opsdroid/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import shutil
import subprocess
import importlib
import pip
import yaml
from opsdroid.const import (
DEFAULT_GIT_URL, MODULES_DIRECTORY, DEFAULT_MODULE_BRANCH)
Expand Down Expand Up @@ -51,6 +50,19 @@ def git_clone(git_url, install_path, branch):
process.wait()


def pip_install_deps(requirements_path):
"""Pip install a requirements.txt file and wait for finish."""
process = subprocess.Popen(["pip", "install", "-r", requirements_path],
shell=False,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
for output in process.communicate():
if output != "":
for line in output.splitlines():
logging.debug(str(line).strip())
process.wait()


class Loader:
"""Class to load in config and modules."""

Expand Down Expand Up @@ -174,5 +186,4 @@ def _install_module(self, config):

# Install module dependancies
if os.path.isfile(config["install_path"] + "/requirements.txt"):
pip.main(["install", "-r", config["install_path"] +
"/requirements.txt"])
pip_install_deps(config["install_path"] + "/requirements.txt")
9 changes: 9 additions & 0 deletions tests/test_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ def setup(self):
loader = ld.Loader(opsdroid)
return opsdroid, loader

def reset_subprocess_mocks(self):
sys.modules['subprocess'].mock_calls = []

def test_load_config_file(self):
opsdroid, loader = self.setup()
config = loader.load_config_file("tests/configs/minimal.yaml")
Expand All @@ -43,10 +46,16 @@ def test_setup_modules(self):
self.assertEqual(len(example_modules[0]["module"].mock_calls), 1)

def test_git_clone(self):
self.reset_subprocess_mocks()
ld.git_clone("https://github.com/rmccue/test-repository.git",
"/tmp/test", "master")
self.assertNotEqual(len(sys.modules['subprocess'].mock_calls), 0)

def test_pip_install_deps(self):
self.reset_subprocess_mocks()
ld.pip_install_deps("/path/to/some/file.txt")
self.assertNotEqual(len(sys.modules['subprocess'].mock_calls), 0)

def test_build_module_path(self):
config = {}
config["type"] = "test"
Expand Down

0 comments on commit e025fc1

Please sign in to comment.