mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Fix conda activation on Windows (PY-21923)
This commit is contained in:
@@ -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<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)
|
||||
}
|
||||
@@ -99,14 +99,27 @@ class PyVirtualEnvReader(val virtualEnvSdkPath: String) : EnvironmentUtil.ShellE
|
||||
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user