mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-13 15:52:01 +07:00
PY-76417: Show all python3 pythons on Unix.
There was a filter to include `python3` only to exclude python2. While `python3` is usually a symlink to the good version of python3, there might be more than one file i.e `python3.11`, `python3.12` etc. We now use regex to find all python3 (cherry picked from commit 024dd2d20ed728e5d4f4fef2c2b1dbaf3c6dcc97) KT-CR-18710 GitOrigin-RevId: 26d813c98e389fa83e6ddc5c2fcd60b91fe5dac8
This commit is contained in:
committed by
intellij-monorepo-bot
parent
1087c97645
commit
8a7073429b
@@ -5,8 +5,9 @@ import com.google.common.collect.Sets;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.util.UserDataHolder;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.jetbrains.python.sdk.VirtualEnvReader;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -14,19 +15,21 @@ import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
public final class UnixPythonSdkFlavor extends CPythonSdkFlavor<PyFlavorData.Empty> {
|
||||
private static final String[] BIN_DIRECTORIES = new String[]{"/usr/bin", "/usr/local/bin"};
|
||||
// file names of system pythons
|
||||
private static final Set<@NonNls String> SYS_PYTHON_FILE_NAMES = Sets.newHashSet("pypy", "python3");
|
||||
private static final Set<Pattern> SYS_PYTHON_FILE_NAMES =
|
||||
Sets.newHashSet(Pattern.compile("pypy$"), Pattern.compile("python3(\\.[0-9]+)?$"));
|
||||
|
||||
private UnixPythonSdkFlavor() {
|
||||
}
|
||||
|
||||
public static UnixPythonSdkFlavor getInstance() {
|
||||
return PythonSdkFlavor.EP_NAME.findExtension(UnixPythonSdkFlavor.class);
|
||||
return EP_NAME.findExtension(UnixPythonSdkFlavor.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -64,10 +67,14 @@ public final class UnixPythonSdkFlavor extends CPythonSdkFlavor<PyFlavorData.Emp
|
||||
return rootPath != null ? rootPath.resolve(dir.getRoot().relativize(dir)) : dir;
|
||||
}
|
||||
|
||||
static void collectUnixPythons(@NotNull Path binDirectory, @NotNull Collection<Path> candidates) {
|
||||
@ApiStatus.Internal
|
||||
public static void collectUnixPythons(@NotNull Path binDirectory, @NotNull Collection<Path> candidates) {
|
||||
try (var entries = Files.list(binDirectory)) {
|
||||
// Hack to exclude system python2
|
||||
entries.filter(path -> SYS_PYTHON_FILE_NAMES.contains(path.getFileName().toString()))
|
||||
entries
|
||||
.filter(path ->
|
||||
ContainerUtil.exists(SYS_PYTHON_FILE_NAMES, regex -> regex.matcher(path.getFileName().toString()).matches())
|
||||
)
|
||||
.collect(Collectors.toCollection(() -> candidates));
|
||||
}
|
||||
catch (IOException ignored) {
|
||||
|
||||
Reference in New Issue
Block a user