PY-87789 Fix existing venv alert for uv

The alert for existing venv in SDK creation dialog was missing. This
commit adds it back, also tying it together with the venv path field
validator. In particular, we now support existing venv alert for any
venv typed in the field (including on remotes). Also, it's now possible
to override existing venv.

Also these changes fix broken alert for in-project poetry environment.


(cherry picked from commit 3cf7202ab0a1393c510abb07e2e0d5676cff9a69)

IJ-MR-192485

GitOrigin-RevId: 79b6852ddd6edef14a1c808a1a5bf83e2ac5fc31
This commit is contained in:
Alexey Katsman
2026-02-20 08:45:28 +00:00
committed by intellij-monorepo-bot
parent d80ed8cda1
commit edaad5131e
6 changed files with 83 additions and 25 deletions
@@ -181,7 +181,7 @@ class VirtualEnvReader private constructor(
}
}
fun getVenvRootPath(path: Path): Path? {
fun getVenvName(path: Path): String? {
val bin = path.parent
val binFolderName = when (forcedOs ?: path.osFamily) {
@@ -194,18 +194,24 @@ class VirtualEnvReader private constructor(
}
val venv = bin.parent
return venv?.name
}
if (venv == null) {
fun getVenvNameForTarget(path: FullPathOnTarget, platform: Platform): String? {
val separator = platform.fileSeparator
val bin = path.substringBeforeLast(separator)
val binFolderName = when (platform) {
Platform.UNIX -> "bin"
Platform.WINDOWS -> "Scripts"
}
if (bin.substringAfterLast(separator) != binFolderName) {
return null
}
val root = venv.parent
if (root == null) {
return null
}
return root
val venv = bin.substringBeforeLast(separator)
return venv.substringAfterLast(separator).takeIf { it.isNotBlank() }
}
/**