Commits

Ryan Wilcox committed 91da204

can now programatically install packages (v1)

Comments (0)

Files changed (1)

+from __future__ import print_function  # requires at least Python 2.6
+
 import subprocess
 
+from pip.index import PackageFinder
+from pip.req import InstallRequirement, RequirementSet
+from pip.locations import build_prefix, src_prefix
+
+
 def applypatch(patchfile, to):
     """apply patchfile to file"""
     subprocess.call( ["/usr/bin/patch", to, patchfile] )
     subprocess.call( ["/bin/cp", src, dest])
 
 def install_python_module(module_name):
-    """Install a Python module. This function should respect virtualenvs,
-        and install the specified packagein the currently active virtualenv"""
-    # TODO: implement me!
-    pass
+    """Install a Python module using PIP 0.8.2 This function does respect virtualenvs,
+        and install the specified package in the currently active virtualenv"""
+    requirement_set = RequirementSet(
+        build_dir=build_prefix,
+        src_dir=src_prefix,
+        download_dir=None)
+
+    requirement_set.add_requirement( InstallRequirement.from_line(module_name, None) )
+
+    install_options = []
+    global_options = []
+    finder = PackageFinder(find_links=[], index_urls=["http://pypi.python.org/simple/"])
+
+    requirement_set.prepare_files(finder, force_root_egg_info=False, bundle=False)
+    requirement_set.install(install_options, global_options)
+
+    print("")
+    print("Installed")
+    print("==================================")
+    [ print(package.name) for package in requirement_set.successfully_installed ]
+    print("")