mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[pycharm] PY-79081 Fix working dir initialization for uv plugin
GitOrigin-RevId: d026b7ccaa6be64758530859880b5ac8a53f038f
This commit is contained in:
committed by
intellij-monorepo-bot
parent
8f9f32b05e
commit
203f58acf4
@@ -25,6 +25,12 @@ class VirtualEnvReader(
|
||||
else
|
||||
setOf("pypy", "python")
|
||||
|
||||
private val binFolderName = if (isWindows) {
|
||||
"Scripts"
|
||||
} else {
|
||||
"bin"
|
||||
}
|
||||
|
||||
/**
|
||||
* Dir with virtual envs
|
||||
*/
|
||||
@@ -118,6 +124,28 @@ class VirtualEnvReader(
|
||||
return findInterpreter(dir)
|
||||
}
|
||||
|
||||
fun getVenvRootPath(path: Path): Path? {
|
||||
val bin = path.parent
|
||||
|
||||
if (bin == null || bin.fileName.pathString != binFolderName) {
|
||||
return null
|
||||
}
|
||||
|
||||
val venv = bin.parent
|
||||
|
||||
if (venv == null) {
|
||||
return null
|
||||
}
|
||||
|
||||
val root = venv.parent
|
||||
|
||||
if (root == null) {
|
||||
return null
|
||||
}
|
||||
|
||||
return root
|
||||
}
|
||||
|
||||
/**
|
||||
* Looks for python binary among directory entries
|
||||
*/
|
||||
@@ -144,5 +172,6 @@ class VirtualEnvReader(
|
||||
*/
|
||||
const val DEFAULT_VIRTUALENVS_DIR: String = ".virtualenvs"
|
||||
const val DEFAULT_VIRTUALENV_DIRNAME: String = ".venv"
|
||||
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ import com.jetbrains.python.sdk.uv.isUv
|
||||
import com.jetbrains.python.sdk.uv.setupExistingEnvAndSdk
|
||||
import com.jetbrains.python.statistics.InterpreterType
|
||||
import com.jetbrains.python.statistics.version
|
||||
import com.jetbrains.python.venvReader.VirtualEnvReader
|
||||
import com.jetbrains.python.venvReader.tryResolvePath
|
||||
import java.nio.file.Path
|
||||
import kotlin.io.path.pathString
|
||||
@@ -44,13 +45,15 @@ internal class UvExistingEnvironmentSelector(model: PythonMutableTargetAddInterp
|
||||
return Result.success(existingSdk)
|
||||
}
|
||||
|
||||
val existingWorkingDir = existingSdk?.associatedModulePath?.let { tryResolvePath(it) }
|
||||
val usePip = existingWorkingDir != null && !existingSdk.isUv
|
||||
val workingDirectory =
|
||||
VirtualEnvReader().getVenvRootPath(selectedInterpreterPath)
|
||||
?: tryResolvePath(existingSdk?.associatedModulePath)
|
||||
?: projectDir
|
||||
|
||||
return setupExistingEnvAndSdk(
|
||||
envExecutable = selectedInterpreterPath,
|
||||
envWorkingDir = existingWorkingDir,
|
||||
usePip = usePip,
|
||||
envWorkingDir = workingDirectory,
|
||||
usePip = existingSdk?.isUv == true,
|
||||
projectDir = projectDir,
|
||||
existingSdks = allSdk.toList()
|
||||
)
|
||||
|
||||
@@ -52,7 +52,7 @@ suspend fun setupNewUvSdkAndEnv(
|
||||
|
||||
suspend fun setupExistingEnvAndSdk(
|
||||
envExecutable: Path,
|
||||
envWorkingDir: Path?,
|
||||
envWorkingDir: Path,
|
||||
usePip: Boolean,
|
||||
projectDir: Path,
|
||||
existingSdks: List<Sdk>,
|
||||
@@ -61,7 +61,7 @@ suspend fun setupExistingEnvAndSdk(
|
||||
envExecutable,
|
||||
existingSdks,
|
||||
projectDir.toString(),
|
||||
suggestedSdkName(projectDir),
|
||||
suggestedSdkName(envWorkingDir),
|
||||
UvSdkAdditionalData(envWorkingDir, usePip))
|
||||
|
||||
return sdk
|
||||
|
||||
Reference in New Issue
Block a user