diff --git a/python/python-hatch/src/com/intellij/python/hatch/cli/HatchEnv.kt b/python/python-hatch/src/com/intellij/python/hatch/cli/HatchEnv.kt index 57865cc5eec0..339543df6ea9 100644 --- a/python/python-hatch/src/com/intellij/python/hatch/cli/HatchEnv.kt +++ b/python/python-hatch/src/com/intellij/python/hatch/cli/HatchEnv.kt @@ -135,7 +135,7 @@ class HatchEnv(runtime: HatchRuntime) : HatchCommand("env", runtime) { return executeAndHandleErrors("create", *arguments) { val actualEnvName = envName ?: DEFAULT_ENV_NAME when { - it.exitCode == 0 && it.stderrString.startsWith("Creating environment") -> Result.success(CreateResult.Created) + it.isSuccessStop("Creating environment") -> Result.success(CreateResult.Created) it.exitCode == 0 -> Result.success(CreateResult.AlreadyExists) it.stderrString.startsWith("Environment `$actualEnvName` is not defined by project config") -> Result.success(CreateResult.NotDefinedInConfig) else -> Result.failure(null) @@ -188,7 +188,7 @@ class HatchEnv(runtime: HatchRuntime) : HatchCommand("env", runtime) { return executeAndHandleErrors("remove", *arguments) { val actualEnvName = envName ?: DEFAULT_ENV_NAME when { - it.exitCode == 0 && it.stderrString.startsWith("Removing environment") -> Result.success(RemoveResult.Removed) + it.isSuccessStop("Removing environment") -> Result.success(RemoveResult.Removed) it.exitCode == 0 && it.stderrString.isBlank() -> Result.success(RemoveResult.NotExists) it.stderrString.startsWith("Environment `$actualEnvName` is not defined by project config") -> Result.success(RemoveResult.NotDefinedInConfig) it.stderrString.startsWith("Cannot remove active environment") -> Result.success(RemoveResult.CantRemoveActiveEnvironment) diff --git a/python/python-hatch/src/com/intellij/python/hatch/cli/utils.kt b/python/python-hatch/src/com/intellij/python/hatch/cli/utils.kt new file mode 100644 index 000000000000..3d981ebbb6f1 --- /dev/null +++ b/python/python-hatch/src/com/intellij/python/hatch/cli/utils.kt @@ -0,0 +1,19 @@ +package com.intellij.python.hatch.cli + +import com.intellij.platform.eel.provider.utils.EelProcessExecutionResult +import com.intellij.platform.eel.provider.utils.stderrString + +/** + * Hatch has two versions of messages in the stop function: "Expected prefix ..." (old_message) and "Finished expected prefix ..." (final_text) + * https://github.com/pypa/hatch/blob/4ebce0e1fe8bf0fcdef587a704c207a063d72575/src/hatch/cli/terminal.py#L65 + */ +fun EelProcessExecutionResult.isSuccessStop(expectedPrefix: String): Boolean { + require(expectedPrefix.isNotEmpty()) { "Expected prefix can't be empty" } + if (exitCode != 0) return false + + val response = stderrString + val result = response.startsWith(expectedPrefix) || + response.startsWith("Finished ${expectedPrefix.first().lowercase()}${expectedPrefix.drop(1)}") + + return result +} \ No newline at end of file