mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-29902 Check if site-packages is writable to find out if we need admin permissions to modify the SDK
This commit is contained in:
@@ -28,10 +28,7 @@ import com.intellij.util.messages.MessageBusConnection;
|
||||
import com.intellij.util.net.HttpConfigurable;
|
||||
import com.jetbrains.python.PythonHelpersLocator;
|
||||
import com.jetbrains.python.psi.LanguageLevel;
|
||||
import com.jetbrains.python.sdk.PyDetectedSdk;
|
||||
import com.jetbrains.python.sdk.PyLazySdk;
|
||||
import com.jetbrains.python.sdk.PythonEnvUtil;
|
||||
import com.jetbrains.python.sdk.PythonSdkType;
|
||||
import com.jetbrains.python.sdk.*;
|
||||
import com.jetbrains.python.sdk.flavors.PythonSdkFlavor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -240,20 +237,6 @@ public class PyPackageManagerImpl extends PyPackageManager {
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private String getWriteAccessAnchorPath() throws ExecutionException {
|
||||
final VirtualFile sitePackagesDir = PythonSdkType.getSitePackagesDirectory(mySdk);
|
||||
if (sitePackagesDir == null) {
|
||||
// Perhaps a system interpreter on Linux that has only "dist-packages", use executable path as a fallback then
|
||||
final String homePath = mySdk.getHomePath();
|
||||
if (homePath == null) {
|
||||
throw new ExecutionException("Cannot find Python interpreter for SDK " + mySdk.getName());
|
||||
}
|
||||
return homePath;
|
||||
}
|
||||
return sitePackagesDir.getPath();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void uninstall(@NotNull List<PyPackage> packages) throws ExecutionException {
|
||||
final List<String> args = new ArrayList<>();
|
||||
@@ -519,7 +502,7 @@ public class PyPackageManagerImpl extends PyPackageManager {
|
||||
flavor.commandLinePatcher().patchCommandLine(commandLine);
|
||||
}
|
||||
final Process process;
|
||||
final boolean useSudo = askForSudo && !Files.isWritable(Paths.get(getWriteAccessAnchorPath()));
|
||||
final boolean useSudo = askForSudo && PySdkExtKt.adminPermissionsNeeded(mySdk);
|
||||
if (useSudo) {
|
||||
process = ExecUtil.sudo(commandLine, "Please enter your password to make changes in system packages: ");
|
||||
}
|
||||
|
||||
@@ -129,8 +129,8 @@ val Sdk.associatedModule: Module?
|
||||
}
|
||||
|
||||
fun Sdk.adminPermissionsNeeded(): Boolean {
|
||||
val homePath = homePath ?: return false
|
||||
return !Files.isWritable(Paths.get(homePath))
|
||||
val pathToCheck = sitePackagesDirectory?.path ?: homePath ?: return false
|
||||
return !Files.isWritable(Paths.get(pathToCheck))
|
||||
}
|
||||
|
||||
fun PyDetectedSdk.setup(existingSdks: List<Sdk>): Sdk? {
|
||||
@@ -208,6 +208,9 @@ private val Sdk.associatedPathFromDotProject: String?
|
||||
private val Sdk.associatedPathFromAdditionalData: String?
|
||||
get() = (sdkAdditionalData as? PythonSdkAdditionalData)?.associatedModulePath
|
||||
|
||||
private val Sdk.sitePackagesDirectory: VirtualFile?
|
||||
get() = PythonSdkType.getSitePackagesDirectory(this)
|
||||
|
||||
private fun Sdk.isLocatedInsideModule(module: Module?): Boolean {
|
||||
val homePath = homePath ?: return false
|
||||
val basePath = module?.basePath ?: return false
|
||||
|
||||
Reference in New Issue
Block a user