Ryan Wilcox avatar 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("")
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.