This repository has been archived by the owner on Feb 9, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 14
[#215] Suggest existing poetry venvs that are in existing modules #217
Merged
koxudaxi
merged 4 commits into
koxudaxi:master
from
roxchkplusony:roxchkplusony/add-existing-venv-multiproject
Apr 29, 2021
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,9 @@ import com.jetbrains.python.sdk.add.PyAddSdkView | |
import com.jetbrains.python.sdk.add.PySdkPathChoosingComboBox | ||
import com.jetbrains.python.sdk.add.addInterpretersAsync | ||
import java.awt.BorderLayout | ||
import java.util.concurrent.ConcurrentHashMap | ||
import javax.swing.Icon | ||
import kotlin.streams.toList | ||
|
||
/** | ||
* @author vlan | ||
|
@@ -44,6 +46,7 @@ class PyAddExistingPoetryEnvPanel(private val project: Project?, | |
private val existingSdks: List<Sdk>, | ||
override var newProjectPath: String?, | ||
context: UserDataHolder) : PyAddSdkPanel() { | ||
private var sdkToModule = ConcurrentHashMap<String, Module>() | ||
override val panelName: String get() = PyBundle.message("python.add.sdk.panel.name.existing.environment") | ||
override val icon: Icon = POETRY_ICON | ||
private val sdkComboBox = PySdkPathChoosingComboBox() | ||
|
@@ -55,20 +58,32 @@ class PyAddExistingPoetryEnvPanel(private val project: Project?, | |
.panel | ||
add(formPanel, BorderLayout.NORTH) | ||
addInterpretersAsync(sdkComboBox) { | ||
detectPoetryEnvs(module, existingSdks, context, project?.basePath ?: newProjectPath) | ||
val existingSdkPaths = sdkHomes(existingSdks) | ||
val moduleSdks = allModules(project).parallelStream().flatMap { module -> | ||
val sdks = detectPoetryEnvs(module, existingSdkPaths, module.basePath) | ||
.filterNot { it.isAssociatedWithAnotherModule(module) } | ||
sdks.forEach { sdkToModule.putIfAbsent(it.name, module) } | ||
sdks.stream() | ||
}.toList() | ||
val rootSdks = detectPoetryEnvs(module, existingSdkPaths, project?.basePath ?: newProjectPath) | ||
.filterNot { it.isAssociatedWithAnotherModule(module) } | ||
val moduleSdkPaths = moduleSdks.map { it.name }.toSet() | ||
val sdks = rootSdks.filterNot { moduleSdkPaths.contains(it.name) } + moduleSdks | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
sdks.sortedBy { it.name } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
} | ||
|
||
override fun validateAll(): List<ValidationInfo> = listOfNotNull(validateSdkComboBox(sdkComboBox, this)) | ||
|
||
override fun getOrCreateSdk(): Sdk? { | ||
return when (val sdk = sdkComboBox.selectedSdk) { | ||
is PyDetectedSdk -> | ||
setupPoetrySdkUnderProgress(project, module, existingSdks, newProjectPath, | ||
is PyDetectedSdk -> { | ||
val mappedModule = sdkToModule[sdk.name] ?: module | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
setupPoetrySdkUnderProgress(project, mappedModule, existingSdks, newProjectPath, | ||
getPythonExecutable(sdk.name), false, sdk.name)?.apply { | ||
PySdkSettings.instance.preferredVirtualEnvBaseSdk = getPythonExecutable(sdk.name) | ||
} | ||
} | ||
else -> sdk | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does not take a crazy long time to load if there are many modules (I have 45):