From 2bf0bfbd1101f9f579f6d90b85d258b70e51e259 Mon Sep 17 00:00:00 2001 From: "Ilya.Kazakevich" Date: Mon, 17 Oct 2022 23:12:41 +0200 Subject: [PATCH] Conda (rename method, remove env duplication) GitOrigin-RevId: fd658f2ba4411e43e73c6b1c6bdf18093d9bd9c9 --- .../sdk/add/target/conda/PyAddCondaPanelModel.kt | 11 ++++++----- .../sdk/add/target/conda/PyAddCondaPanelView.kt | 2 +- .../jetbrains/env/conda/PyAddCondaPanelModelTest.kt | 6 +++--- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/python/src/com/jetbrains/python/sdk/add/target/conda/PyAddCondaPanelModel.kt b/python/src/com/jetbrains/python/sdk/add/target/conda/PyAddCondaPanelModel.kt index 11878fd60118..ec481c48646a 100644 --- a/python/src/com/jetbrains/python/sdk/add/target/conda/PyAddCondaPanelModel.kt +++ b/python/src/com/jetbrains/python/sdk/add/target/conda/PyAddCondaPanelModel.kt @@ -27,7 +27,7 @@ import kotlin.coroutines.CoroutineContext * Model for [PyAddCondaPanelView] * Each boundable property ends with "Prop" and either "ro" (view can read it) or "rw" (view can set it) * - * First, user fills [condaPathTextBoxRwProp] then clicks [onCondaPathSetOkClicked] + * First, user fills [condaPathTextBoxRwProp] then clicks [onLoadEnvsClicked] * (if [showCondaPathSetOkButtonRoProp] is true). * * After path validation [showCondaActionsPanelRoProp] becomes "true", hence radio buttons should be displayed @@ -125,13 +125,13 @@ class PyAddCondaPanelModel(val targetConfiguration: TargetEnvironmentConfigurati private var condaEnvs: Result = Result.failure(Exception(PyBundle.message("python.sdk.conda.no.exec"))) /** - * To be called when user sets path to conda and clicks "On". + * To be called when user sets path to conda and clicks "Load Envs". * * [uiContext] is for swing. * Result may contain an error */ - suspend fun onCondaPathSetOkClicked(uiContext: CoroutineContext, - progressSink: ProgressSink? = null): Result> = withContext(uiContext) { + suspend fun onLoadEnvsClicked(uiContext: CoroutineContext, + progressSink: ProgressSink? = null): Result> = withContext(uiContext) { val path = condaPathTextBoxRwProp.get() progressSink?.text(PyBundle.message("python.sdk.conda.getting.list.envs")) PyCondaEnv.getEnvs(PyCondaCommand(path.trim(), targetConfiguration)) @@ -141,6 +141,7 @@ class PyAddCondaPanelModel(val targetConfiguration: TargetEnvironmentConfigurati showCondaActionsPanelRoProp.set(false) } .onSuccess { condaEnvsList -> + condaEnvModel.removeAllElements() condaEnvs = Result.success(CondaInfo(path, condaEnvsList)) condaEnvModel.addAll(condaEnvsList.map { it.envIdentity }) condaEnvModel.selectedItem = condaEnvModel.getElementAt(0) @@ -164,7 +165,7 @@ class PyAddCondaPanelModel(val targetConfiguration: TargetEnvironmentConfigurati withContext(uiContext) { condaPathTextBoxRwProp.set(condaPath) // Since path is set, lets click button on behalf of user - onCondaPathSetOkClicked(uiContext, progressSink) + onLoadEnvsClicked(uiContext, progressSink) } } diff --git a/python/src/com/jetbrains/python/sdk/add/target/conda/PyAddCondaPanelView.kt b/python/src/com/jetbrains/python/sdk/add/target/conda/PyAddCondaPanelView.kt index 29083b8b7a7e..aa9e5dea13c2 100644 --- a/python/src/com/jetbrains/python/sdk/add/target/conda/PyAddCondaPanelView.kt +++ b/python/src/com/jetbrains/python/sdk/add/target/conda/PyAddCondaPanelView.kt @@ -57,7 +57,7 @@ class PyAddCondaPanelView(private val model: PyAddCondaPanelModel) : PyAddTarget button(PyBundle.message("python.add.sdk.panel.load.envs")) { runBlockingModal(model.project, PyBundle.message("python.sdk.conda.getting.list.envs")) { - model.onCondaPathSetOkClicked(Dispatchers.EDT, this.progressSink) + model.onLoadEnvsClicked(Dispatchers.EDT, this.progressSink) }.onFailure { showError(it.localizedMessage) } diff --git a/python/testSrc/com/jetbrains/env/conda/PyAddCondaPanelModelTest.kt b/python/testSrc/com/jetbrains/env/conda/PyAddCondaPanelModelTest.kt index 1c02b7a2d1e0..9dfd863d1e01 100644 --- a/python/testSrc/com/jetbrains/env/conda/PyAddCondaPanelModelTest.kt +++ b/python/testSrc/com/jetbrains/env/conda/PyAddCondaPanelModelTest.kt @@ -69,7 +69,7 @@ class PyAddCondaPanelModelTest { fun testCondaUseExistingEnv(): Unit = runTest { val model = PyAddCondaPanelModel(null, emptyList(), projectRule.project) model.condaPathTextBoxRwProp.set(condaRule.condaPath.toString()) - model.onCondaPathSetOkClicked(coroutineContext) + model.onLoadEnvsClicked(coroutineContext) model.condaActionUseExistingEnvRadioRwProp.set(true) model.condaActionCreateNewEnvRadioRwProp.set(false) model.condaEnvModel.selectedItem = model.condaEnvModel.getElementAt(0) @@ -86,11 +86,11 @@ class PyAddCondaPanelModelTest { Assert.assertFalse(model.showCondaPathSetOkButtonRoProp.get()) model.condaPathTextBoxRwProp.set("Some random path that doesn't exist") Assert.assertTrue(model.showCondaPathSetOkButtonRoProp.get()) - model.onCondaPathSetOkClicked(coroutineContext) + model.onLoadEnvsClicked(coroutineContext) Assert.assertNotNull("No validation error, but path is incorrect", model.getValidationError()) model.condaPathTextBoxRwProp.set(condaRule.condaPath.toString()) - model.onCondaPathSetOkClicked(coroutineContext) + model.onLoadEnvsClicked(coroutineContext) Assert.assertNull("Unexpected validation error", model.getValidationError()) Assert.assertTrue(model.showCondaActionsPanelRoProp.get())