diff --git a/python/helpers/chdir_run.py b/python/helpers/chdir_run.py new file mode 100644 index 000000000000..9d3336d2d1d4 --- /dev/null +++ b/python/helpers/chdir_run.py @@ -0,0 +1,10 @@ +import os +import sys + + +if __name__ == '__main__': + working_dir = sys.argv[1] + + os.chdir(working_dir) + sys.argv[1] = sys.executable + os.execv(sys.executable, sys.argv[1:]) diff --git a/python/src/com/jetbrains/python/packaging/PyPackageManagerImpl.java b/python/src/com/jetbrains/python/packaging/PyPackageManagerImpl.java index d065036e928e..42f749c4e284 100644 --- a/python/src/com/jetbrains/python/packaging/PyPackageManagerImpl.java +++ b/python/src/com/jetbrains/python/packaging/PyPackageManagerImpl.java @@ -285,11 +285,9 @@ public class PyPackageManagerImpl extends PyPackageManager { } private void installManagement(String name) throws PyExternalProcessException { - final File helperFile = PythonHelpersLocator.getHelperFile(name + ".tar.gz"); - final String helpersPath = getHelperPath(name); - ProcessOutput output = getHelperOutput(PACKAGING_TOOL, Lists.newArrayList(UNTAR, helpersPath), false, helperFile.getParent()); + ProcessOutput output = getHelperOutput(PACKAGING_TOOL, Lists.newArrayList(UNTAR, helpersPath), false, null); if (output.getExitCode() != 0) { throw new PyExternalProcessException(output.getExitCode(), PACKAGING_TOOL, @@ -623,10 +621,10 @@ public class PyPackageManagerImpl extends PyPackageManager { private ProcessOutput getProcessOutput(@NotNull String helperPath, @NotNull List args, boolean askForSudo, - @Nullable String parentDir) + @Nullable String workingDir) throws PyExternalProcessException { final SdkAdditionalData sdkData = mySdk.getSdkAdditionalData(); - if (sdkData instanceof RemoteSdkData) { + if (sdkData instanceof RemoteSdkData) { //remote interpreter final RemoteSdkData remoteSdkData = (RemoteSdkData)sdkData; final PythonRemoteInterpreterManager manager = PythonRemoteInterpreterManager.getInstance(); if (manager != null) { @@ -640,7 +638,7 @@ public class PyPackageManagerImpl extends PyPackageManager { } ProcessOutput processOutput; do { - processOutput = manager.runRemoteProcess(null, remoteSdkData, ArrayUtil.toStringArray(cmdline), askForSudo); + processOutput = manager.runRemoteProcess(null, remoteSdkData, ArrayUtil.toStringArray(cmdline), workingDir, askForSudo); if (askForSudo && processOutput.getStderr().contains("sudo: 3 incorrect password attempts")) { continue; } @@ -663,8 +661,8 @@ public class PyPackageManagerImpl extends PyPackageManager { if (homePath == null) { throw new PyExternalProcessException(ERROR_INVALID_SDK, helperPath, args, "Cannot find interpreter for SDK"); } - if (parentDir == null) { - parentDir = new File(homePath).getParent(); + if (workingDir == null) { + workingDir = new File(homePath).getParent(); } final List cmdline = new ArrayList(); cmdline.add(homePath); @@ -678,7 +676,7 @@ public class PyPackageManagerImpl extends PyPackageManager { cmdline.add(1, helperPath); final ProcessOutput result = ExecUtil.sudoAndGetOutput(StringUtil.join(cmdline, " "), "Please enter your password to make changes in system packages: ", - parentDir); + workingDir); String message = result.getStderr(); if (result.getExitCode() != 0) { final String stdout = result.getStdout(); @@ -705,7 +703,7 @@ public class PyPackageManagerImpl extends PyPackageManager { else //vEnv interpreter { cmdline.add(1, helperPath); - return PySdkUtil.getProcessOutput(parentDir, ArrayUtil.toStringArray(cmdline), TIMEOUT); + return PySdkUtil.getProcessOutput(workingDir, ArrayUtil.toStringArray(cmdline), TIMEOUT); } } } diff --git a/python/src/com/jetbrains/python/remote/PythonRemoteInterpreterManager.java b/python/src/com/jetbrains/python/remote/PythonRemoteInterpreterManager.java index 6efa7a9c69e2..725f26d31fd4 100644 --- a/python/src/com/jetbrains/python/remote/PythonRemoteInterpreterManager.java +++ b/python/src/com/jetbrains/python/remote/PythonRemoteInterpreterManager.java @@ -50,9 +50,11 @@ public abstract class PythonRemoteInterpreterManager { @Nullable public abstract Sdk addRemoteSdk(Project project, Collection existingSdks); + public abstract ProcessOutput runRemoteProcess(@Nullable Project project, RemoteSdkData data, String[] command, + @Nullable String workingDir, boolean askForSudo) throws RemoteInterpreterException;