mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 04:51:24 +07:00
Fix configuring inner venv for idea + python plugin (PY-49082)
Python project base directory stored in context was ignored during looking for virtual envs because module was not passed. Such inner venv did not have a precedence in sorting by the same reason. GitOrigin-RevId: 99bf42d3c9c254878e944cbfc186bdd26b8e580b
This commit is contained in:
committed by
intellij-monorepo-bot
parent
f48f210237
commit
bf9324167f
@@ -11,6 +11,7 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.projectRoots.ProjectJdkTable;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.jetbrains.python.PyBundle;
|
||||
import com.jetbrains.python.facet.PythonFacet;
|
||||
import com.jetbrains.python.facet.PythonFacetType;
|
||||
import com.jetbrains.python.sdk.PyDetectedSdk;
|
||||
import com.jetbrains.python.sdk.PySdkExtKt;
|
||||
@@ -120,7 +121,10 @@ public class PythonPluginCommandLineInspectionProjectConfigurator implements Com
|
||||
if (facet == null) {
|
||||
logger.reportMessage(3, "Setting Python facet for: " + m.getName());
|
||||
|
||||
WriteAction.runAndWait(() -> facetManager.addFacet(facetType, facetType.getPresentableName(), null));
|
||||
WriteAction.runAndWait(() -> {
|
||||
final PythonFacet addedFacet = facetManager.addFacet(facetType, facetType.getPresentableName(), null);
|
||||
PySdkExtKt.excludeInnerVirtualEnv(m, addedFacet.getConfiguration().getSdk());
|
||||
});
|
||||
}
|
||||
else {
|
||||
logger.reportMessage(3, "Python facet already here: " + m.getName());
|
||||
|
||||
@@ -59,7 +59,7 @@ import java.nio.file.Paths
|
||||
* @author vlan
|
||||
*/
|
||||
|
||||
val BASE_DIR: Key<Path> = Key.create("PYTHON_BASE_PATH")
|
||||
val BASE_DIR: Key<Path> = Key.create("PYTHON_PROJECT_BASE_PATH")
|
||||
|
||||
fun findAllPythonSdks(baseDir: Path?): List<Sdk> {
|
||||
val context: UserDataHolder = UserDataHolderBase()
|
||||
@@ -104,14 +104,14 @@ fun resetSystemWideSdksDetectors() {
|
||||
}
|
||||
|
||||
fun detectVirtualEnvs(module: Module?, existingSdks: List<Sdk>, context: UserDataHolder): List<PyDetectedSdk> =
|
||||
filterSuggestedPaths(VirtualEnvSdkFlavor.getInstance().suggestHomePaths(module, context), existingSdks, module)
|
||||
filterSuggestedPaths(VirtualEnvSdkFlavor.getInstance().suggestHomePaths(module, context), existingSdks, module, context)
|
||||
|
||||
fun filterSharedCondaEnvs(module: Module?, existingSdks: List<Sdk>): List<Sdk> {
|
||||
return existingSdks.filter { it.sdkType is PythonSdkType && PythonSdkUtil.isConda(it) && !it.isAssociatedWithAnotherModule(module) }
|
||||
}
|
||||
|
||||
fun detectCondaEnvs(module: Module?, existingSdks: List<Sdk>, context: UserDataHolder): List<PyDetectedSdk> =
|
||||
filterSuggestedPaths(CondaEnvSdkFlavor.getInstance().suggestHomePaths(module, context), existingSdks, module, true)
|
||||
filterSuggestedPaths(CondaEnvSdkFlavor.getInstance().suggestHomePaths(module, context), existingSdks, module, context, true)
|
||||
|
||||
fun filterAssociatedSdks(module: Module, existingSdks: List<Sdk>): List<Sdk> {
|
||||
return existingSdks.filter { it.sdkType is PythonSdkType && it.isAssociatedWithModule(module) }
|
||||
@@ -309,8 +309,12 @@ private val Sdk.sitePackagesDirectory: VirtualFile?
|
||||
get() = PythonSdkUtil.getSitePackagesDirectory(this)
|
||||
|
||||
private fun Sdk.isLocatedInsideModule(module: Module?): Boolean {
|
||||
return isLocatedInsideBaseDir(module?.baseDir?.toNioPath())
|
||||
}
|
||||
|
||||
private fun Sdk.isLocatedInsideBaseDir(baseDir: Path?): Boolean {
|
||||
val homePath = homePath ?: return false
|
||||
val basePath = module?.basePath ?: return false
|
||||
val basePath = baseDir?.toString() ?: return false
|
||||
return FileUtil.isAncestor(basePath, homePath, true)
|
||||
}
|
||||
|
||||
@@ -341,8 +345,10 @@ fun Sdk.getOrCreateAdditionalData(): PythonSdkAdditionalData {
|
||||
private fun filterSuggestedPaths(suggestedPaths: Collection<String>,
|
||||
existingSdks: List<Sdk>,
|
||||
module: Module?,
|
||||
context: UserDataHolder,
|
||||
mayContainCondaEnvs: Boolean = false): List<PyDetectedSdk> {
|
||||
val existingPaths = existingSdks.mapTo(HashSet()) { it.homePath }
|
||||
val baseDirFromContext = context.getUserData(BASE_DIR)
|
||||
return suggestedPaths
|
||||
.asSequence()
|
||||
.filterNot { it in existingPaths }
|
||||
@@ -350,7 +356,7 @@ private fun filterSuggestedPaths(suggestedPaths: Collection<String>,
|
||||
.map { PyDetectedSdk(it) }
|
||||
.sortedWith(
|
||||
compareBy(
|
||||
{ !it.isAssociatedWithModule(module) },
|
||||
{ !it.isAssociatedWithModule(module) && !it.isLocatedInsideBaseDir(baseDirFromContext) },
|
||||
{ if (mayContainCondaEnvs) !PythonSdkUtil.isBaseConda(it.homePath) else false },
|
||||
{ it.homePath }
|
||||
)
|
||||
|
||||
@@ -20,6 +20,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@@ -46,14 +47,16 @@ public final class VirtualEnvSdkFlavor extends CPythonSdkFlavor {
|
||||
public Collection<String> suggestHomePaths(@Nullable Module module, @Nullable UserDataHolder context) {
|
||||
return ReadAction.compute(() -> {
|
||||
final List<String> candidates = new ArrayList<>();
|
||||
if (module != null) {
|
||||
VirtualFile baseDir = BasePySdkExtKt.getBaseDir(module);
|
||||
if (baseDir == null && context != null && context.getUserData(PySdkExtKt.getBASE_DIR()) != null) {
|
||||
//noinspection ConstantConditions
|
||||
baseDir = VfsUtil.findFile(context.getUserData(PySdkExtKt.getBASE_DIR()), false);
|
||||
}
|
||||
if (baseDir != null) {
|
||||
candidates.addAll(findInBaseDirectory(baseDir));
|
||||
final VirtualFile baseDirFromModule = module == null ? null : BasePySdkExtKt.getBaseDir(module);
|
||||
final Path baseDirFromContext = context == null ? null : context.getUserData(PySdkExtKt.getBASE_DIR());
|
||||
|
||||
if (baseDirFromModule != null) {
|
||||
candidates.addAll(findInBaseDirectory(baseDirFromModule));
|
||||
}
|
||||
else if (baseDirFromContext != null) {
|
||||
final VirtualFile dir = VfsUtil.findFile(baseDirFromContext, false);
|
||||
if (dir != null) {
|
||||
candidates.addAll(findInBaseDirectory(dir));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user