From 82a79a426d8fc4c0f7f22b250254c50c5d759679 Mon Sep 17 00:00:00 2001 From: "Ekaterina.Tuzova" Date: Mon, 16 Jan 2012 12:52:20 +0400 Subject: [PATCH] added install/uninstall packages for python --- python/helpers/packaging_tool.py | 20 +++++++++++++++++-- python/python-ide.iml | 1 + .../python/packaging/PyPackagingUtil.java | 9 ++++++++- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/python/helpers/packaging_tool.py b/python/helpers/packaging_tool.py index 92c7a2129614..45e723e49380 100644 --- a/python/helpers/packaging_tool.py +++ b/python/helpers/packaging_tool.py @@ -29,6 +29,21 @@ def do_uninstall(pkg): error("Python package management tool 'pip' not found. Please install 'pip'", ERROR_NO_PACKAGING_TOOLS) return pip.main(['uninstall', '-y', pkg]) +def do_install(pkg, options): + """ + simple realization for install packages + """ + #TODO: test install + try: + import pip + except ImportError: + error("Python package management tool 'pip' not found. Please install 'pip'", ERROR_NO_PACKAGING_TOOLS) + + if options: + return pip.main(['install', pkg, options]) + else: + return pip.main(['install', pkg]) + def main(): retcode = 0 try: @@ -41,10 +56,11 @@ def main(): usage() do_list() elif cmd == 'install': - if len(sys.argv) != 3: + if len(sys.argv) < 3: usage() pkg = sys.argv[2] - retcode = do_install(pkg) + options = sys.argv[3] + retcode = do_install(pkg, options) elif cmd == 'uninstall': if len(sys.argv) != 3: usage() diff --git a/python/python-ide.iml b/python/python-ide.iml index 7458d1e183c5..08470fc95b07 100644 --- a/python/python-ide.iml +++ b/python/python-ide.iml @@ -21,6 +21,7 @@ + diff --git a/python/src/com/jetbrains/python/packaging/PyPackagingUtil.java b/python/src/com/jetbrains/python/packaging/PyPackagingUtil.java index b7319e1ce97e..2f5848d81c03 100644 --- a/python/src/com/jetbrains/python/packaging/PyPackagingUtil.java +++ b/python/src/com/jetbrains/python/packaging/PyPackagingUtil.java @@ -9,6 +9,7 @@ import com.jetbrains.python.PythonHelpersLocator; import com.jetbrains.python.sdk.PythonSdkType; import com.jetbrains.python.sdk.SdkUtil; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.io.File; import java.util.*; @@ -41,6 +42,11 @@ public class PyPackagingUtil { myPackagesCache.remove(sdk); } + public void installPackage(@NotNull Sdk sdk, @NotNull PyPackage pkg, @Nullable String options) throws PyExternalProcessException { + runPythonHelper(sdk, PACKAGING_TOOL, list("install", pkg.getName(), options)); + myPackagesCache.remove(sdk); + } + @NotNull public static String createVirtualEnv(@NotNull Sdk sdk, @NotNull String desinationDir) throws PyExternalProcessException { // TODO: Add boolean systemSitePackages option @@ -136,7 +142,8 @@ public class PyPackagingUtil { final String name = fields.get(0); final String version = fields.get(1); final String location = fields.get(2); - packages.add(new PyPackage(name, version, location, new ArrayList())); + if (!"Python".equals(name) && !"wsgiref".equals(name)) + packages.add(new PyPackage(name, version, location, new ArrayList())); } return packages; }