PyCharm: Add Poetry support into tests.

Current implementation doesn't destroy envs, created by tests, so it might be useful to create a fixture to do that as it is done for Conda.

This change makes `VanillaPythonEnvExtension` to look for Python with Poetry and install its path to `PropertiesComponent`.

See `PoetryTest` as an example

GitOrigin-RevId: 3d66a46a8e9b80d85e7bf47b1bf27eeb562c218b
This commit is contained in:
Ilya.Kazakevich
2024-08-05 19:20:07 +02:00
committed by intellij-monorepo-bot
parent 2b039aab98
commit 7ad77319e3

View File

@@ -30,12 +30,12 @@ typealias PathToPythonBinary = Path
*/
sealed class PythonType<T : Any>(private val tag: @NonNls String) {
suspend fun getTestEnvironment(): Result<Pair<T, AutoCloseable>> =
suspend fun getTestEnvironment(vararg additionalTags: @NonNls String): Result<Pair<T, AutoCloseable>> =
PyEnvTestSettings
.fromEnvVariables()
.pythons
.map { it.toPath() }
.firstOrNull { typeMatchesEnv(it) }
.firstOrNull { typeMatchesEnv(it, *additionalTags) }
?.let { envDir ->
Result.success(pythonPathToEnvironment(Path.of(
PythonSdkUtil.getPythonExecutable(envDir.toString())
@@ -90,12 +90,12 @@ sealed class PythonType<T : Any>(private val tag: @NonNls String) {
@RequiresBackgroundThread
private fun typeMatchesEnv(env: Path): Boolean {
private fun typeMatchesEnv(env: Path, vararg additionalTags: @NonNls String): Boolean {
val envTags = PyEnvTestCase.loadEnvTags(env.toString())
for (badTag in PythonType::class.sealedSubclasses.filterNot { it.isInstance(this) }.map { it.objectInstance!!.tag }) {
if (badTag in envTags) return false
}
return tag in envTags
return tag in envTags && additionalTags.all { it in envTags }
}
}