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<String>(activateFile.path, activate.second!!, ">", envFile.absolutePath)
- else listOf<String>(activateFile.path, ">", envFile.absolutePath)
+ val command = if (activate.second != null) listOf<String>(activateFile.path, activate.second!!)
+ else listOf<String>(activateFile.path)
return runProcessAndReadEnvs(command, envFile, LineSeparator.CRLF.separatorString)
}
fun findActivateScript(path: String?, shellPath: String?): Pair<String, String?>? {
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