mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-21 22:11:40 +07:00
Persist associate path changes. Cleanup association logic a bit; PY-72692
(cherry picked from commit a3ee1feb4f98f0f66760762819800bbc6342bd08) IJ-MR-140559 GitOrigin-RevId: dbff236b7fbe20b23d6dea7b324a3f1ac031d2d6
This commit is contained in:
committed by
intellij-monorepo-bot
parent
5a5671d785
commit
f3082fb053
@@ -130,18 +130,15 @@ class PythonSdkConfigurator : DirectoryProjectConfigurator {
|
||||
LOGGER.debug("Looking for a virtual environment related to the project")
|
||||
guardIndicator(indicator) { detectAssociatedEnvironments(module, existingSdks, context).firstOrNull() }?.let {
|
||||
LOGGER.debug { "Detected virtual environment related to the project: $it" }
|
||||
val newSdk = it.setupAssociated(existingSdks, module.basePath).getOrElse { err->
|
||||
val newSdk = it.setupAssociated(existingSdks, module.basePath, true).getOrElse { err->
|
||||
LOGGER.error(err)
|
||||
return
|
||||
}
|
||||
|
||||
LOGGER.debug { "Created virtual environment related to the project: $newSdk" }
|
||||
|
||||
runInEdt {
|
||||
SdkConfigurationUtil.addSdk(newSdk)
|
||||
newSdk.associateWithModule(module, null)
|
||||
ApplicationManager.getApplication().runWriteAction {
|
||||
newSdk.sdkModificator.commitChanges()
|
||||
}
|
||||
setReadyToUseSdk(project, module, newSdk)
|
||||
}
|
||||
|
||||
|
||||
@@ -26,22 +26,19 @@ import com.jetbrains.python.configuration.PyConfigurableInterpreterList
|
||||
import com.jetbrains.python.pathValidation.PlatformAndRoot
|
||||
import com.jetbrains.python.psi.PyUtil
|
||||
import com.jetbrains.python.run.PythonInterpreterTargetEnvironmentFactory
|
||||
import com.jetbrains.python.sdk.PythonSdkUpdater
|
||||
import com.jetbrains.python.sdk.add.PyAddNewCondaEnvFromFilePanel
|
||||
import com.jetbrains.python.sdk.add.target.conda.createCondaSdkAlongWithNewEnv
|
||||
import com.jetbrains.python.sdk.add.target.conda.suggestCondaPath
|
||||
import com.jetbrains.python.sdk.associateWithModule
|
||||
import com.jetbrains.python.sdk.basePath
|
||||
import com.jetbrains.python.sdk.conda.PyCondaSdkCustomizer
|
||||
import com.intellij.pycharm.community.ide.impl.configuration.PySdkConfigurationCollector.CondaEnvResult
|
||||
import com.intellij.pycharm.community.ide.impl.configuration.PySdkConfigurationCollector.InputData
|
||||
import com.intellij.pycharm.community.ide.impl.configuration.PySdkConfigurationCollector.Source
|
||||
import com.jetbrains.python.sdk.*
|
||||
import com.jetbrains.python.sdk.configuration.PyProjectSdkConfigurationExtension
|
||||
import com.jetbrains.python.sdk.flavors.conda.CondaEnvSdkFlavor
|
||||
import com.jetbrains.python.sdk.flavors.conda.NewCondaEnvRequest
|
||||
import com.jetbrains.python.sdk.flavors.conda.PyCondaCommand
|
||||
import com.jetbrains.python.sdk.flavors.listCondaEnvironments
|
||||
import com.jetbrains.python.sdk.showSdkExecutionException
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import java.awt.BorderLayout
|
||||
@@ -120,15 +117,12 @@ class PyEnvironmentYmlSdkConfiguration : PyProjectSdkConfigurationExtension {
|
||||
val basePath = module.basePath
|
||||
|
||||
ApplicationManager.getApplication().invokeAndWait {
|
||||
if (shared) {
|
||||
LOGGER.debug("Adding conda environment: ${sdk.homePath}")
|
||||
}
|
||||
else {
|
||||
LOGGER.debug("Adding associated conda environment: ${sdk.homePath}, $basePath")
|
||||
LOGGER.debug("Adding conda environment: ${sdk.homePath}, associated ${shared}}, module path ${basePath})")
|
||||
if (!shared) {
|
||||
sdk.setAssociationToModule(module)
|
||||
}
|
||||
|
||||
SdkConfigurationUtil.addSdk(sdk)
|
||||
if (!shared) sdk.associateWithModule(module, null)
|
||||
}
|
||||
|
||||
return sdk
|
||||
|
||||
@@ -120,9 +120,9 @@ class PyPipfileSdkConfiguration : PyProjectSdkConfigurationExtension {
|
||||
|
||||
ApplicationManager.getApplication().invokeAndWait {
|
||||
LOGGER.debug("Adding associated pipenv environment: $path, $basePath")
|
||||
SdkConfigurationUtil.addSdk(sdk)
|
||||
sdk.isPipEnv = true
|
||||
sdk.associateWithModule(module, null)
|
||||
sdk.setAssociationToModule(module)
|
||||
SdkConfigurationUtil.addSdk(sdk)
|
||||
}
|
||||
|
||||
return sdk
|
||||
|
||||
@@ -112,9 +112,9 @@ class PyPoetrySdkConfiguration : PyProjectSdkConfigurationExtension {
|
||||
|
||||
ApplicationManager.getApplication().invokeAndWait {
|
||||
LOGGER.debug("Adding associated poetry environment: $path, $basePath")
|
||||
SdkConfigurationUtil.addSdk(sdk)
|
||||
sdk.isPoetry = true
|
||||
sdk.associateWithModule(module, null)
|
||||
sdk.setAssociationToModule(module)
|
||||
SdkConfigurationUtil.addSdk(sdk)
|
||||
}
|
||||
|
||||
return sdk
|
||||
|
||||
@@ -125,12 +125,13 @@ class PyRequirementsTxtOrSetupPySdkConfiguration : PyProjectSdkConfigurationExte
|
||||
val basePath = module.basePath
|
||||
|
||||
thisLogger().debug("Setting up associated virtual environment: $path, $basePath")
|
||||
val sdk = PyDetectedSdk(path).setupAssociated(existingSdks, basePath).getOrElse { return Result.failure(it) }
|
||||
val sdk = PyDetectedSdk(path).setupAssociated(existingSdks, basePath, true).getOrElse {
|
||||
return Result.failure(it)
|
||||
}
|
||||
|
||||
ApplicationManager.getApplication().invokeAndWait {
|
||||
thisLogger().debug("Adding associated virtual environment: $path, $basePath")
|
||||
SdkConfigurationUtil.addSdk(sdk)
|
||||
sdk.associateWithModule(module, null)
|
||||
}
|
||||
|
||||
val requirementsTxtOrSetupPyFile = VfsUtil.findFile(Paths.get(requirementsTxtOrSetupPy), false)
|
||||
|
||||
@@ -138,7 +138,7 @@ public final class PyInterpreterInspection extends PyInspection {
|
||||
}
|
||||
}
|
||||
|
||||
if (! PySdkExtKt.getSdkSeemsValid(sdk)) {
|
||||
if (!PySdkExtKt.getSdkSeemsValid(sdk)) {
|
||||
final @InspectionMessage String message;
|
||||
if (pyCharm) {
|
||||
message = PyPsiBundle.message("INSP.interpreter.invalid.python.interpreter.selected.for.project");
|
||||
@@ -154,11 +154,11 @@ public final class PyInterpreterInspection extends PyInspection {
|
||||
final @InspectionMessage String message;
|
||||
if (pyCharm) {
|
||||
message = PyPsiBundle.message("INSP.interpreter.python.has.reached.its.end.of.life.and.is.no.longer.supported.in.pycharm",
|
||||
languageLevel);
|
||||
languageLevel);
|
||||
}
|
||||
else {
|
||||
message = PyPsiBundle.message("INSP.interpreter.python.has.reached.its.end.life.and.is.no.longer.supported.in.python.plugin",
|
||||
languageLevel);
|
||||
languageLevel);
|
||||
}
|
||||
registerProblemWithCommonFixes(node, message, module, sdk, fixes, pyCharm);
|
||||
}
|
||||
@@ -166,7 +166,12 @@ public final class PyInterpreterInspection extends PyInspection {
|
||||
}
|
||||
}
|
||||
|
||||
private void registerProblemWithCommonFixes(PyFile node, @InspectionMessage String message, Module module, Sdk sdk, List<LocalQuickFix> fixes, boolean pyCharm) {
|
||||
private void registerProblemWithCommonFixes(PyFile node,
|
||||
@InspectionMessage String message,
|
||||
Module module,
|
||||
Sdk sdk,
|
||||
List<LocalQuickFix> fixes,
|
||||
boolean pyCharm) {
|
||||
if (pyCharm && sdk == null) {
|
||||
final String sdkName = ProjectRootManager.getInstance(node.getProject()).getProjectSdkName();
|
||||
ContainerUtil.addIfNotNull(fixes, getSuitableSdkFix(sdkName, module));
|
||||
@@ -207,12 +212,17 @@ public final class PyInterpreterInspection extends PyInspection {
|
||||
break;
|
||||
}
|
||||
}
|
||||
final var detectedAssociatedSdk = ContainerUtil.getFirstItem(detectedAssociatedEnvs);
|
||||
if (detectedAssociatedSdk != null) return new UseDetectedInterpreterFix(detectedAssociatedSdk, existingSdks, true, module);
|
||||
|
||||
final Pair<@IntentionName String, PyProjectSdkConfigurationExtension> textAndExtension
|
||||
= PyProjectSdkConfigurationExtension.findForModule(module);
|
||||
if (textAndExtension != null) return new UseProvidedInterpreterFix(module, textAndExtension.getSecond(), textAndExtension.getFirst());
|
||||
final var detectedAssociatedSdk = ContainerUtil.getFirstItem(detectedAssociatedEnvs);
|
||||
if (detectedAssociatedSdk != null) {
|
||||
return new UseDetectedInterpreterFix(detectedAssociatedSdk, existingSdks, true, module);
|
||||
}
|
||||
|
||||
final Pair<@IntentionName String, PyProjectSdkConfigurationExtension> textAndExtension =
|
||||
PyProjectSdkConfigurationExtension.findForModule(module);
|
||||
if (textAndExtension != null) {
|
||||
return new UseProvidedInterpreterFix(module, textAndExtension.getSecond(), textAndExtension.getFirst());
|
||||
}
|
||||
|
||||
if (name != null) {
|
||||
final Matcher matcher = NAME.matcher(name);
|
||||
@@ -226,21 +236,29 @@ public final class PyInterpreterInspection extends PyInspection {
|
||||
}
|
||||
else {
|
||||
final PyDetectedSdk detectedSystemWideSdk = detectSystemWideSdk(matcher.group("version"), module, existingSdks, context);
|
||||
if (detectedSystemWideSdk != null) return new UseDetectedInterpreterFix(detectedSystemWideSdk, existingSdks, false, module);
|
||||
if (detectedSystemWideSdk != null) {
|
||||
return new UseDetectedInterpreterFix(detectedSystemWideSdk, existingSdks, false, module);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (PyCondaSdkCustomizer.Companion.getInstance().getSuggestSharedCondaEnvironments()) {
|
||||
final var sharedCondaEnv = PySdkExtKt.mostPreferred(PySdkExtKt.filterSharedCondaEnvs(module, existingSdks));
|
||||
if (sharedCondaEnv != null) return new UseExistingInterpreterFix(sharedCondaEnv, module);
|
||||
if (sharedCondaEnv != null) {
|
||||
return new UseExistingInterpreterFix(sharedCondaEnv, module);
|
||||
}
|
||||
}
|
||||
|
||||
final var systemWideSdk = PySdkExtKt.mostPreferred(PySdkExtKt.filterSystemWideSdks(existingSdks));
|
||||
if (systemWideSdk != null) return new UseExistingInterpreterFix(systemWideSdk, module);
|
||||
if (systemWideSdk != null) {
|
||||
return new UseExistingInterpreterFix(systemWideSdk, module);
|
||||
}
|
||||
|
||||
final var detectedSystemWideSdk = ContainerUtil.getFirstItem(PySdkExtKt.detectSystemWideSdks(module, existingSdks));
|
||||
if (detectedSystemWideSdk != null) return new UseDetectedInterpreterFix(detectedSystemWideSdk, existingSdks, false, module);
|
||||
if (detectedSystemWideSdk != null) {
|
||||
return new UseDetectedInterpreterFix(detectedSystemWideSdk, existingSdks, false, module);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -457,7 +475,8 @@ public final class PyInterpreterInspection extends PyInspection {
|
||||
|
||||
@Override
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
PyProjectSdkConfiguration.INSTANCE.configureSdkUsingExtension(myModule, myExtension, () -> myExtension.createAndAddSdkForInspection(myModule));
|
||||
PyProjectSdkConfiguration.INSTANCE.configureSdkUsingExtension(myModule, myExtension,
|
||||
() -> myExtension.createAndAddSdkForInspection(myModule));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -511,7 +530,7 @@ public final class PyInterpreterInspection extends PyInspection {
|
||||
|
||||
private final @NotNull List<Sdk> myExistingSdks;
|
||||
|
||||
private final boolean myAssociate;
|
||||
private final boolean doAssociate;
|
||||
|
||||
private final @NotNull Module myModule;
|
||||
|
||||
@@ -521,20 +540,19 @@ public final class PyInterpreterInspection extends PyInspection {
|
||||
@NotNull Module module) {
|
||||
super(detectedSdk);
|
||||
myExistingSdks = existingSdks;
|
||||
myAssociate = associate;
|
||||
doAssociate = associate;
|
||||
myModule = module;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
PyUiUtil.clearFileLevelInspectionResults(project);
|
||||
final Sdk newSdk = myAssociate
|
||||
? PySdkExtKt.setupAssociatedLogged(mySdk, myExistingSdks, BasePySdkExtKt.getBasePath(myModule))
|
||||
: PySdkExtKt.setup(mySdk, myExistingSdks);
|
||||
if (newSdk == null) return;
|
||||
final Sdk newSdk = PySdkExtKt.setupAssociatedLogged(mySdk, myExistingSdks, BasePySdkExtKt.getBasePath(myModule), doAssociate);
|
||||
if (newSdk == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
SdkConfigurationUtil.addSdk(newSdk);
|
||||
if (myAssociate) PySdkExtKt.associateWithModule(newSdk, myModule, null);
|
||||
PyProjectSdkConfiguration.INSTANCE.setReadyToUseSdk(project, myModule, newSdk);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,15 +56,6 @@ interface NewProjectWizardPythonData : NewProjectWizardBaseData {
|
||||
* The Python module after it has been created during [NewProjectWizardStep.setupProject].
|
||||
*/
|
||||
val module: Module?
|
||||
|
||||
companion object {
|
||||
|
||||
val KEY = Key.create<NewProjectWizardPythonData>(NewProjectWizardPythonData::class.java.name)
|
||||
|
||||
@JvmStatic
|
||||
val NewProjectWizardStep.pythonData: NewProjectWizardPythonData?
|
||||
get() = data.getUserData(KEY)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -125,10 +116,6 @@ class NewPythonProjectStep(parent: NewProjectWizardStep)
|
||||
SdkConfigurationUtil.setDirectoryProjectSdk(project, sdk)
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
data.putUserData(NewProjectWizardPythonData.KEY, this)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -165,10 +165,14 @@ fun createSdkByGenerateTask(
|
||||
showSdkExecutionException(baseSdk, e, PyBundle.message("python.sdk.failed.to.create.interpreter.title"))
|
||||
throw e
|
||||
}
|
||||
|
||||
val suggestedName = suggestedSdkName ?: suggestAssociatedSdkName(homeFile.path, associatedProjectPath)
|
||||
return SdkConfigurationUtil.setupSdk(existingSdks.toTypedArray(), homeFile,
|
||||
PythonSdkType.getInstance(),
|
||||
null, suggestedName)
|
||||
return SdkConfigurationUtil.setupSdk(
|
||||
existingSdks.toTypedArray(),
|
||||
homeFile,
|
||||
PythonSdkType.getInstance(),
|
||||
null,
|
||||
suggestedName)
|
||||
}
|
||||
|
||||
fun showSdkExecutionException(sdk: Sdk?, e: ExecutionException, @NlsContexts.DialogTitle title: String) {
|
||||
@@ -189,8 +193,15 @@ fun Sdk.associateWithModule(module: Module?, newProjectPath: String?) {
|
||||
}
|
||||
|
||||
fun Sdk.setAssociationToModule(module: Module) {
|
||||
val data = getOrCreateAdditionalData().apply {
|
||||
associateWithModule(module)
|
||||
setAssociationToPath(module.basePath)
|
||||
}
|
||||
|
||||
fun Sdk.setAssociationToPath(path: String?) {
|
||||
val data = getOrCreateAdditionalData().also {
|
||||
when {
|
||||
path != null -> it.associateWithModulePath(path)
|
||||
else -> it.associatedModulePath = null
|
||||
}
|
||||
}
|
||||
|
||||
val modificator = sdkModificator
|
||||
@@ -234,28 +245,49 @@ fun PyDetectedSdk.setup(existingSdks: List<Sdk>): Sdk? {
|
||||
return SdkConfigurationUtil.setupSdk(existingSdks.toTypedArray(), homeDir, PythonSdkType.getInstance(), null, null)
|
||||
}
|
||||
|
||||
|
||||
// For Java only
|
||||
internal fun PyDetectedSdk.setupAssociatedLogged(existingSdks: List<Sdk>, associatedModulePath: String?): Sdk? = setupAssociated(existingSdks, associatedModulePath).getOrLogException(LOGGER)
|
||||
fun PyDetectedSdk.setupAssociated(existingSdks: List<Sdk>, associatedModulePath: String?): Result<Sdk> {
|
||||
if (!sdkSeemsValid) return Result.failure(Throwable("sdk not valid"))
|
||||
val homePath = this.homePath ?: return Result.failure(Throwable("homePath os null"))
|
||||
val suggestedName = suggestAssociatedSdkName(homePath, associatedModulePath) ?: homePath
|
||||
val sdk = SdkConfigurationUtil.createSdk(existingSdks, homePath, PythonSdkType.getInstance(), null, suggestedName)
|
||||
internal fun PyDetectedSdk.setupAssociatedLogged(existingSdks: List<Sdk>, associatedModulePath: String?, doAssociate: Boolean): Sdk? {
|
||||
return setupAssociated(existingSdks, associatedModulePath, doAssociate).getOrLogException(LOGGER)
|
||||
}
|
||||
|
||||
targetEnvConfiguration?.let { targetConfig ->
|
||||
// Target-based sdk, not local one
|
||||
sdk.sdkModificator.let { modificator ->
|
||||
modificator.sdkAdditionalData = PyTargetAwareAdditionalData(PyFlavorAndData.UNKNOWN_FLAVOR_DATA)
|
||||
.also {
|
||||
it.targetEnvironmentConfiguration = targetConfig
|
||||
}
|
||||
ApplicationManager.getApplication().runWriteAction {
|
||||
modificator.commitChanges()
|
||||
}
|
||||
}
|
||||
fun PyDetectedSdk.setupAssociated(existingSdks: List<Sdk>, associatedModulePath: String?, doAssociate: Boolean): Result<Sdk> {
|
||||
if (!sdkSeemsValid) {
|
||||
return Result.failure(Throwable("sdk is not valid"))
|
||||
}
|
||||
PythonSdkType.getInstance().setupSdkPaths(sdk)
|
||||
|
||||
val homePath = this.homePath
|
||||
if (homePath == null) {
|
||||
// e.g. directory is not there anymore
|
||||
return Result.failure(Throwable("homePath is null"))
|
||||
}
|
||||
|
||||
val homeDir = this.homeDirectory
|
||||
if (homeDir == null) {
|
||||
return Result.failure(Throwable("homeDir is null"))
|
||||
}
|
||||
|
||||
val suggestedName = if (doAssociate) {
|
||||
suggestAssociatedSdkName(homePath, associatedModulePath)
|
||||
}
|
||||
else null
|
||||
|
||||
val data = targetEnvConfiguration?.let { targetConfig ->
|
||||
PyTargetAwareAdditionalData(PyFlavorAndData.UNKNOWN_FLAVOR_DATA).also {
|
||||
it.targetEnvironmentConfiguration = targetConfig
|
||||
}
|
||||
} ?: PythonSdkAdditionalData()
|
||||
|
||||
if (doAssociate && associatedModulePath != null) {
|
||||
data.associateWithModulePath(associatedModulePath)
|
||||
}
|
||||
|
||||
val sdk = SdkConfigurationUtil.setupSdk(
|
||||
existingSdks.toTypedArray(),
|
||||
homeDir,
|
||||
PythonSdkType.getInstance(),
|
||||
data,
|
||||
suggestedName)
|
||||
|
||||
return Result.success(sdk)
|
||||
}
|
||||
|
||||
@@ -342,9 +374,6 @@ private fun suggestAssociatedSdkName(sdkHome: String, associatedPath: String?):
|
||||
return "$baseSdkName ($associatedName)"
|
||||
}
|
||||
|
||||
val File.isNotEmptyDirectory: Boolean
|
||||
get() = exists() && isDirectory && list()?.isEmpty()?.not() ?: false
|
||||
|
||||
private val Sdk.isSystemWide: Boolean
|
||||
get() = !PythonSdkUtil.isRemote(this) && !PythonSdkUtil.isVirtualEnv(
|
||||
this) && !PythonSdkUtil.isCondaVirtualEnv(this)
|
||||
|
||||
@@ -30,7 +30,6 @@ import com.jetbrains.python.PyBundle
|
||||
import com.jetbrains.python.PySdkBundle
|
||||
import com.jetbrains.python.packaging.PyCondaPackageService
|
||||
import com.jetbrains.python.sdk.PyDetectedSdk
|
||||
import com.jetbrains.python.sdk.associateWithModule
|
||||
import com.jetbrains.python.sdk.conda.PyCondaSdkCustomizer
|
||||
import com.jetbrains.python.sdk.setupAssociated
|
||||
import com.jetbrains.python.icons.PythonIcons
|
||||
@@ -38,11 +37,13 @@ import java.awt.BorderLayout
|
||||
import java.awt.event.ItemEvent
|
||||
import javax.swing.Icon
|
||||
|
||||
open class PyAddExistingCondaEnvPanel(private val project: Project?,
|
||||
private val module: Module?,
|
||||
private val existingSdks: List<Sdk>,
|
||||
override var newProjectPath: String?,
|
||||
context: UserDataHolder) : PyAddSdkPanel() {
|
||||
open class PyAddExistingCondaEnvPanel(
|
||||
private val project: Project?,
|
||||
private val module: Module?,
|
||||
private val existingSdks: List<Sdk>,
|
||||
override var newProjectPath: String?,
|
||||
context: UserDataHolder,
|
||||
) : PyAddSdkPanel() {
|
||||
override val panelName: String get() = PyBundle.message("python.add.sdk.panel.name.existing.environment")
|
||||
override val icon: Icon = PythonIcons.Python.Anaconda
|
||||
protected val sdkComboBox = PySdkPathChoosingComboBox()
|
||||
@@ -93,11 +94,8 @@ open class PyAddExistingCondaEnvPanel(private val project: Project?,
|
||||
val sdk = sdkComboBox.selectedSdk
|
||||
PyCondaPackageService.onCondaEnvCreated(condaPathField.text)
|
||||
return when (sdk) {
|
||||
is PyDetectedSdk -> sdk.setupAssociated(existingSdks, newProjectPath ?: project?.basePath).getOrLogException(thisLogger())?.apply {
|
||||
if (!makeSharedField.isSelected) {
|
||||
associateWithModule(module, newProjectPath)
|
||||
}
|
||||
}
|
||||
is PyDetectedSdk -> sdk.setupAssociated(existingSdks, newProjectPath ?: project?.basePath, !makeSharedField.isSelected)
|
||||
.getOrLogException(thisLogger())
|
||||
else -> sdk
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,11 +30,13 @@ import com.jetbrains.python.icons.PythonIcons
|
||||
import java.awt.BorderLayout
|
||||
import javax.swing.Icon
|
||||
|
||||
open class PyAddExistingVirtualEnvPanel(private val project: Project?,
|
||||
private val module: Module?,
|
||||
private val existingSdks: List<Sdk>,
|
||||
override var newProjectPath: String?,
|
||||
context:UserDataHolder ) : PyAddSdkPanel() {
|
||||
open class PyAddExistingVirtualEnvPanel(
|
||||
private val project: Project?,
|
||||
private val module: Module?,
|
||||
private val existingSdks: List<Sdk>,
|
||||
override var newProjectPath: String?,
|
||||
context: UserDataHolder,
|
||||
) : PyAddSdkPanel() {
|
||||
override val panelName: String get() = PyBundle.message("python.add.sdk.panel.name.existing.environment")
|
||||
override val icon: Icon = PythonIcons.Python.Virtualenv
|
||||
protected val sdkComboBox = PySdkPathChoosingComboBox()
|
||||
@@ -62,11 +64,8 @@ open class PyAddExistingVirtualEnvPanel(private val project: Project?,
|
||||
|
||||
override fun getOrCreateSdk(): Sdk? {
|
||||
return when (val sdk = sdkComboBox.selectedSdk) {
|
||||
is PyDetectedSdk -> sdk.setupAssociated(existingSdks, newProjectPath ?: project?.basePath).getOrLogException(LOGGER)?.apply {
|
||||
if (!makeSharedField.isSelected) {
|
||||
associateWithModule(module, newProjectPath)
|
||||
}
|
||||
}
|
||||
is PyDetectedSdk -> sdk.setupAssociated(existingSdks, newProjectPath ?: project?.basePath, !makeSharedField.isSelected)
|
||||
.getOrLogException(LOGGER)
|
||||
else -> sdk
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,8 +119,12 @@ open class PyAddNewCondaEnvPanel(
|
||||
val associatedPath = if (!shared) projectBasePath else null
|
||||
val sdk = createSdkByGenerateTask(task, existingSdks, null, associatedPath, null)
|
||||
if (!shared) {
|
||||
sdk.associateWithModule(module, newProjectPath)
|
||||
when {
|
||||
newProjectPath != null -> sdk.setAssociationToPath(newProjectPath)
|
||||
module != null -> sdk.setAssociationToModule(module)
|
||||
}
|
||||
}
|
||||
|
||||
PyCondaPackageService.onCondaEnvCreated(condaPath)
|
||||
project.excludeInnerVirtualEnv(sdk)
|
||||
// Old conda created, convert to new
|
||||
|
||||
@@ -41,14 +41,15 @@ import java.util.function.Supplier
|
||||
/**
|
||||
* Panel with a control that allows to add either new or selecting existing virtualenv.
|
||||
*/
|
||||
class PyAddVirtualEnvPanel(project: Project?,
|
||||
module: Module?,
|
||||
private val existingSdks: List<Sdk> = emptyList(),
|
||||
allowAddNewVirtualenv: Boolean = false,
|
||||
private val context: UserDataHolder,
|
||||
targetSupplier: Supplier<TargetEnvironmentConfiguration>?,
|
||||
config: PythonLanguageRuntimeConfiguration)
|
||||
: PyAddSdkPanelBase(project, module, targetSupplier) {
|
||||
class PyAddVirtualEnvPanel(
|
||||
project: Project?,
|
||||
module: Module?,
|
||||
private val existingSdks: List<Sdk> = emptyList(),
|
||||
allowAddNewVirtualenv: Boolean = false,
|
||||
private val context: UserDataHolder,
|
||||
targetSupplier: Supplier<TargetEnvironmentConfiguration>?,
|
||||
config: PythonLanguageRuntimeConfiguration,
|
||||
) : PyAddSdkPanelBase(project, module, targetSupplier) {
|
||||
|
||||
override val panelName = PyBundle.message("python.add.sdk.panel.name.virtualenv.environment")
|
||||
|
||||
@@ -216,10 +217,8 @@ class PyAddVirtualEnvPanel(project: Project?,
|
||||
private fun configureExistingVirtualenvSdk(targetEnvironmentConfiguration: TargetEnvironmentConfiguration?, selectedSdk: Sdk): Sdk {
|
||||
if (targetEnvironmentConfiguration == null) {
|
||||
return when (selectedSdk) {
|
||||
is PyDetectedSdk -> selectedSdk.setupAssociated(existingSdks, newProjectPath ?: project?.basePath).getOrThrow().apply {
|
||||
// TODO [targets] Restore `makeSharedField` flag
|
||||
associateWithModule(module, newProjectPath)
|
||||
}
|
||||
is PyDetectedSdk -> selectedSdk.setupAssociated(existingSdks, newProjectPath ?: project?.basePath, true)
|
||||
.getOrThrow()
|
||||
else -> selectedSdk
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,12 +85,14 @@ fun createVirtualEnvSynchronously(
|
||||
createSdkForTarget(project, it, homePath, existingSdks, targetPanelExtension)
|
||||
}
|
||||
}
|
||||
|
||||
if (!makeShared) {
|
||||
venvSdk.associateWithModule(module, projectPath)
|
||||
ApplicationManager.getApplication().runWriteAction {
|
||||
venvSdk.sdkModificator.commitChanges()
|
||||
when {
|
||||
projectPath != null -> venvSdk.setAssociationToPath(projectPath)
|
||||
module != null -> venvSdk.setAssociationToModule(module)
|
||||
}
|
||||
}
|
||||
|
||||
project.excludeInnerVirtualEnv(venvSdk)
|
||||
if (targetEnvironmentConfiguration.isLocal()) {
|
||||
// The method `onVirtualEnvCreated(..)` stores preferred base path to virtual envs. Storing here the base path from the non-local
|
||||
@@ -135,12 +137,12 @@ internal fun createSdkForTarget(
|
||||
else {
|
||||
name = PythonInterpreterTargetEnvironmentFactory.findDefaultSdkName(project, data, sdkVersion)
|
||||
}
|
||||
|
||||
val sdk = SdkConfigurationUtil.createSdk(existingSdks, interpreterPath, PythonSdkType.getInstance(), data, name)
|
||||
|
||||
if (project != null && project.modules.isNotEmpty() &&
|
||||
PythonInterpreterTargetEnvironmentFactory.by(environmentConfiguration)?.needAssociateWithModule() == true) {
|
||||
sdk.associateWithModule(project.modules[0], null)
|
||||
if (PythonInterpreterTargetEnvironmentFactory.by(environmentConfiguration)?.needAssociateWithModule() == true) {
|
||||
// FIXME: multi module project support
|
||||
project?.modules?.firstOrNull()?.let {
|
||||
sdk.setAssociationToModule(it)
|
||||
}
|
||||
}
|
||||
|
||||
sdk.sdkModificator.let { modifiableSdk ->
|
||||
@@ -150,6 +152,7 @@ internal fun createSdkForTarget(
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: should we persist it?
|
||||
data.isValid = true
|
||||
|
||||
return sdk
|
||||
|
||||
@@ -145,8 +145,9 @@ fun setupPipEnvSdkUnderProgress(project: Project?,
|
||||
return PythonSdkUtil.getPythonExecutable(pipEnv) ?: FileUtil.join(pipEnv, "bin", "python")
|
||||
}
|
||||
}
|
||||
return createSdkByGenerateTask(task, existingSdks, null, projectPath, suggestedSdkName(projectPath)).apply {
|
||||
associateWithModule(module, newProjectPath)
|
||||
return createSdkByGenerateTask(task, existingSdks, null, projectPath, suggestedSdkName(projectPath))?.apply {
|
||||
// FIXME: multi module project support - associate with module path
|
||||
setAssociationToPath(projectPath)
|
||||
isPipEnv = true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -190,18 +190,9 @@ fun setupPoetrySdkUnderProgress(project: Project?,
|
||||
}
|
||||
}
|
||||
|
||||
return createSdkByGenerateTask(task, existingSdks, null, projectPath, suggestedSdkName(projectPath)).apply {
|
||||
associateWithModule(module ?: project?.modules?.firstOrNull(), newProjectPath)
|
||||
return createSdkByGenerateTask(task, existingSdks, null, projectPath, suggestedSdkName(projectPath))?.apply {
|
||||
module?.let { setAssociationToModule(it) }
|
||||
isPoetry = true
|
||||
// project?.let { project ->
|
||||
// existingSdks.find {
|
||||
// it.associatedModulePath == projectPath && isPoetry(project, it) && it.homePath == homePath
|
||||
// }?.run {
|
||||
// re-use existing invalid sdk
|
||||
// return null
|
||||
// }
|
||||
// PoetryConfigService.getInstance(project).poetryVirtualenvPaths.add(homePath!!)
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user