diff --git a/python/src/com/jetbrains/python/run/PyVirtualEnvReader.kt b/python/src/com/jetbrains/python/run/PyVirtualEnvReader.kt index 961577934eb0..7b412a228a45 100644 --- a/python/src/com/jetbrains/python/run/PyVirtualEnvReader.kt +++ b/python/src/com/jetbrains/python/run/PyVirtualEnvReader.kt @@ -67,10 +67,10 @@ class PyVirtualEnvReader(val virtualEnvSdkPath: String) : EnvironmentUtil.ShellE val envFile = FileUtil.createTempFile("pycharm-virualenv-envs.", ".tmp", false) try { FileUtil.copy(File(activate.first), activateFile); - FileUtil.appendToFile(activateFile, "\n\nset") + FileUtil.appendToFile(activateFile, "\n\nset >" + envFile.absoluteFile) - val command = if (activate.second != null) listOf(activateFile.path, activate.second!!, ">", envFile.absolutePath) - else listOf(activateFile.path, ">", envFile.absolutePath) + val command = if (activate.second != null) listOf(activateFile.path, activate.second!!) + else listOf(activateFile.path) return runProcessAndReadEnvs(command, envFile, LineSeparator.CRLF.separatorString) } @@ -99,14 +99,27 @@ class PyVirtualEnvReader(val virtualEnvSdkPath: String) : EnvironmentUtil.ShellE fun findActivateScript(path: String?, shellPath: String?): Pair? { val shellName = if (shellPath != null) File(shellPath).name else null - val activate = if (SystemInfo.isWindows) File(File(path).parentFile, "activate.bat") + val activate = if (SystemInfo.isWindows) findActivateOnWindows(path) else if (shellName == "fish" || shellName == "csh") File(File(path).parentFile, "activate." + shellName) else File(File(path).parentFile, "activate") - return if (activate.exists()) { + return if (activate != null && activate.exists()) { val sdk = PythonSdkType.findSdkByPath(path) - if (sdk != null && PythonSdkType.isCondaVirtualEnv(sdk)) Pair(activate.absolutePath, File(path).parentFile.parent) + if (sdk != null && PythonSdkType.isCondaVirtualEnv(sdk)) Pair(activate.absolutePath, condaEnvFolder(path)) else Pair(activate.absolutePath, null) } else null +} + +private fun condaEnvFolder(path: String?) = if (SystemInfo.isWindows) File(path).parent else File(path).parentFile.parent + +private fun findActivateOnWindows(path: String?): File? { + for (location in arrayListOf("activate.bat", "Scripts/activate.bat")) { + val file = File(File(path).parentFile, location) + if (file.exists()) { + return file + } + } + + return null } \ No newline at end of file