mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-04 17:20:55 +07:00
Initial implementation of background caching of packages (PY-18039)
This commit is contained in:
committed by
Mikhail Golubev
parent
58b6cd235a
commit
2401d62f80
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package com.jetbrains.python.newProject.actions;
|
||||
|
||||
import com.intellij.execution.ExecutionException;
|
||||
import com.intellij.facet.ui.ValidationResult;
|
||||
import com.intellij.ide.util.projectWizard.ProjectSettingsStepBase;
|
||||
import com.intellij.ide.util.projectWizard.WebProjectTemplate;
|
||||
@@ -35,9 +34,8 @@ import com.jetbrains.python.configuration.PyConfigurableInterpreterList;
|
||||
import com.jetbrains.python.configuration.VirtualEnvProjectFilter;
|
||||
import com.jetbrains.python.newProject.PyFrameworkProjectGenerator;
|
||||
import com.jetbrains.python.newProject.PythonProjectGenerator;
|
||||
import com.jetbrains.python.packaging.PyPackageManager;
|
||||
import com.jetbrains.python.packaging.PyPackage;
|
||||
import com.jetbrains.python.packaging.PyPackageUtil;
|
||||
import com.jetbrains.python.sdk.PySdkUtil;
|
||||
import com.jetbrains.python.sdk.PythonSdkType;
|
||||
import icons.PythonIcons;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -169,14 +167,11 @@ public class ProjectSpecificSettingsStep extends ProjectSettingsStepBase impleme
|
||||
if (PyPackageUtil.packageManagementEnabled(sdk)) {
|
||||
warningList.add(frameworkName + " will be installed on the selected interpreter");
|
||||
myInstallFramework = true;
|
||||
final PyPackageManager packageManager = PyPackageManager.getInstance(sdk);
|
||||
boolean hasManagement = false;
|
||||
try {
|
||||
hasManagement = packageManager.hasManagement(PySdkUtil.isRemote(sdk));
|
||||
final List<PyPackage> packages = PyPackageUtil.refreshAndGetPackagesModally(sdk);
|
||||
if (packages == null) {
|
||||
return false;
|
||||
}
|
||||
catch (ExecutionException ignored) {
|
||||
}
|
||||
if (!hasManagement) {
|
||||
if (!PyPackageUtil.hasManagement(packages)) {
|
||||
warningList.add("Python packaging tools and " + warningList);
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -33,6 +33,7 @@ import com.intellij.util.ui.UIUtil;
|
||||
import com.jetbrains.python.PythonHelper;
|
||||
import com.jetbrains.python.packaging.PyPackage;
|
||||
import com.jetbrains.python.packaging.PyPackageManager;
|
||||
import com.jetbrains.python.packaging.PyPackageUtil;
|
||||
import com.jetbrains.python.sdk.PythonSdkType;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -269,15 +270,12 @@ public final class IpnbConnectionManager implements ProjectComponent {
|
||||
showWarning(fileEditor, "Please check Python Interpreter in Settings->Python Interpreter", null);
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
final PyPackage ipythonPackage = PyPackageManager.getInstance(sdk).findPackage("ipython", false);
|
||||
final PyPackage jupyterPackage = PyPackageManager.getInstance(sdk).findPackage("jupyter", false);
|
||||
if (ipythonPackage == null && jupyterPackage == null) {
|
||||
showWarning(fileEditor, "Add Jupyter to the interpreter of the current project.", null);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (ExecutionException ignored) {
|
||||
final List<PyPackage> packages = PyPackageManager.getInstance(sdk).getPackages();
|
||||
final PyPackage ipythonPackage = packages != null ? PyPackageUtil.findPackage(packages, "ipython") : null;
|
||||
final PyPackage jupyterPackage = packages != null ? PyPackageUtil.findPackage(packages, "jupyter") : null;
|
||||
if (ipythonPackage == null && jupyterPackage == null) {
|
||||
showWarning(fileEditor, "Add Jupyter to the interpreter of the current project.", null);
|
||||
return false;
|
||||
}
|
||||
|
||||
String url = showDialogUrl(initUrl);
|
||||
|
||||
@@ -4,7 +4,6 @@ import com.google.common.collect.Lists;
|
||||
import com.google.gson.*;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
import com.intellij.execution.ExecutionException;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.module.Module;
|
||||
@@ -17,6 +16,7 @@ import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.text.VersionComparatorUtil;
|
||||
import com.jetbrains.python.packaging.PyPackage;
|
||||
import com.jetbrains.python.packaging.PyPackageManager;
|
||||
import com.jetbrains.python.packaging.PyPackageUtil;
|
||||
import com.jetbrains.python.sdk.PythonSdkType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -79,14 +79,11 @@ public class IpnbParser {
|
||||
if (module != null) {
|
||||
final Sdk sdk = PythonSdkType.findPythonSdk(module);
|
||||
if (sdk != null) {
|
||||
try {
|
||||
final PyPackage ipython = PyPackageManager.getInstance(sdk).findPackage("ipython", true);
|
||||
final PyPackage jupyter = PyPackageManager.getInstance(sdk).findPackage("jupyter", true);
|
||||
if (jupyter == null && ipython != null && VersionComparatorUtil.compare(ipython.getVersion(), "3.0") <= 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (ExecutionException ignored) {
|
||||
final List<PyPackage> packages = PyPackageManager.getInstance(sdk).getPackages();
|
||||
final PyPackage ipython = packages != null ? PyPackageUtil.findPackage(packages, "ipython") : null;
|
||||
final PyPackage jupyter = packages != null ? PyPackageUtil.findPackage(packages, "jupyter") : null;
|
||||
if (jupyter == null && ipython != null && VersionComparatorUtil.compare(ipython.getVersion(), "3.0") <= 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,19 +31,16 @@ import java.util.Set;
|
||||
public abstract class PyPackageManager {
|
||||
public static final Key<Boolean> RUNNING_PACKAGING_TASKS = Key.create("PyPackageRequirementsInspection.RunningPackagingTasks");
|
||||
|
||||
public static final String SETUPTOOLS = "setuptools";
|
||||
public static final String PIP = "pip";
|
||||
public static final String DISTRIBUTE = "distribute";
|
||||
|
||||
public static final String USE_USER_SITE = "--user";
|
||||
|
||||
public static PyPackageManager getInstance(Sdk sdk) {
|
||||
@NotNull
|
||||
public static PyPackageManager getInstance(@NotNull Sdk sdk) {
|
||||
return PyPackageManagers.getInstance().forSdk(sdk);
|
||||
}
|
||||
|
||||
public abstract void installManagement() throws ExecutionException;
|
||||
|
||||
public abstract boolean hasManagement(boolean cachedOnly) throws ExecutionException;
|
||||
public abstract boolean hasManagement() throws ExecutionException;
|
||||
|
||||
public abstract void install(@NotNull String requirementString) throws ExecutionException;
|
||||
|
||||
@@ -57,22 +54,10 @@ public abstract class PyPackageManager {
|
||||
public abstract String createVirtualEnv(@NotNull String destinationDir, boolean useGlobalSite) throws ExecutionException;
|
||||
|
||||
@Nullable
|
||||
public abstract List<PyPackage> getPackages(boolean cachedOnly) throws ExecutionException;
|
||||
public abstract List<PyPackage> getPackages();
|
||||
|
||||
/**
|
||||
* @param cachedOnly only search through cached packages. Cache may be empty just after project opened.
|
||||
* <strong>warning</strong>: non-cache access may be slow on remote interpreters.
|
||||
* Use {@link #findPackage(String)}: this method uses cache on remote interpreters and skips
|
||||
* in local
|
||||
*/
|
||||
@Nullable
|
||||
public abstract PyPackage findPackage(@NotNull String name, boolean cachedOnly) throws ExecutionException;
|
||||
|
||||
/**
|
||||
* Like {@link #findPackage(String, boolean)} but controls cache access based on intepreter remote/local type
|
||||
*/
|
||||
@Nullable
|
||||
public abstract PyPackage findPackage(@NotNull String name) throws ExecutionException;
|
||||
@NotNull
|
||||
public abstract List<PyPackage> refreshAndGetPackages(boolean alwaysRefresh) throws ExecutionException;
|
||||
|
||||
@Nullable
|
||||
public abstract List<PyRequirement> getRequirements(@NotNull Module module);
|
||||
|
||||
@@ -32,7 +32,7 @@ public abstract class PyPackageManagers {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public abstract PyPackageManager forSdk(Sdk sdk);
|
||||
public abstract PyPackageManager forSdk(@NotNull Sdk sdk);
|
||||
|
||||
public abstract PackageManagementService getManagementService(Project project, Sdk sdk);
|
||||
|
||||
|
||||
@@ -1,101 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.jetbrains.python.templateLanguages;
|
||||
|
||||
import com.intellij.execution.ExecutionException;
|
||||
import com.intellij.facet.ui.ValidationResult;
|
||||
import com.intellij.lang.Language;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.FileViewProvider;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider;
|
||||
import com.jetbrains.python.packaging.PyPackage;
|
||||
import com.jetbrains.python.packaging.PyPackageManager;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class PyTemplatesUtil {
|
||||
private PyTemplatesUtil() {
|
||||
}
|
||||
|
||||
public static ValidationResult checkInstalled(@Nullable final Sdk sdk, @NotNull final TemplateLanguagePanel templatesPanel,
|
||||
@NotNull final String prefix) {
|
||||
if (sdk == null) return ValidationResult.OK;
|
||||
String templateBinding = null;
|
||||
@NonNls String language = templatesPanel.getTemplateLanguage();
|
||||
if (language != null) {
|
||||
String framework = StringUtil.trimEnd(prefix, '_');
|
||||
framework = StringUtil.trimEnd(framework, '-');
|
||||
String postfix = language.toLowerCase();
|
||||
if (framework.equals(postfix)) return ValidationResult.OK;
|
||||
if (language.equals(TemplatesService.JINJA2)) {
|
||||
postfix = "jinja";
|
||||
}
|
||||
templateBinding = prefix + postfix;
|
||||
}
|
||||
final PyPackageManager packageManager = PyPackageManager.getInstance(sdk);
|
||||
if (templateBinding != null) {
|
||||
if (TemplatesService.ALL_TEMPLATE_BINDINGS.contains(templateBinding)) {
|
||||
try {
|
||||
final PyPackage installedPackage = packageManager.findPackage(templateBinding, false);
|
||||
if (installedPackage == null) {
|
||||
return new ValidationResult(templateBinding + " will be installed on the selected interpreter");
|
||||
}
|
||||
}
|
||||
catch (ExecutionException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (language != null) {
|
||||
try {
|
||||
final PyPackage installedPackage = packageManager.findPackage(language, false);
|
||||
if (installedPackage == null) {
|
||||
return new ValidationResult(language + " will be installed on the selected interpreter");
|
||||
}
|
||||
}
|
||||
catch (ExecutionException ignored) {
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches template data language if file has {@link TemplateLanguageFileViewProvider}
|
||||
*
|
||||
* @param psiElement element to get lang for
|
||||
* @param expectedProvider only fetch language if provider has certain type. Pass null for any type.
|
||||
* @return template data language
|
||||
*/
|
||||
@Nullable
|
||||
public static Language getTemplateDataLanguage(@Nullable final PsiElement psiElement,
|
||||
@Nullable final Class<? extends TemplateLanguageFileViewProvider> expectedProvider) {
|
||||
if (psiElement == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final FileViewProvider provider = psiElement.getContainingFile().getViewProvider();
|
||||
if (provider instanceof TemplateLanguageFileViewProvider) {
|
||||
if (expectedProvider == null || expectedProvider.isInstance(provider)) {
|
||||
return (((TemplateLanguageFileViewProvider)provider).getTemplateDataLanguage());
|
||||
}
|
||||
}
|
||||
|
||||
return psiElement.getLanguage();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.jetbrains.python.templateLanguages;
|
||||
|
||||
import com.intellij.lang.Language;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettings;
|
||||
import com.intellij.psi.codeStyle.CommonCodeStyleSettings.IndentOptions;
|
||||
import com.intellij.psi.codeStyle.FileIndentOptionsProvider;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Injects indents for Python templates.
|
||||
* In Python we have template langs, but we should use indent from underlying language (like html)
|
||||
* because templ. language never works standalone: it is always emebedded in some language
|
||||
*
|
||||
* @author Ilya.Kazakevich
|
||||
*/
|
||||
public class PythonTemplateIndentOptionsProvider extends FileIndentOptionsProvider {
|
||||
@Nullable
|
||||
@Override
|
||||
public final IndentOptions getIndentOptions(@NotNull final CodeStyleSettings settings,
|
||||
@NotNull final PsiFile file) {
|
||||
final Language language = file.getLanguage();
|
||||
if (!(language instanceof PythonTemplateLanguage)) {
|
||||
return null; // We only care about python template files
|
||||
}
|
||||
|
||||
// This template language has no settings, lets use parent language then
|
||||
final Language templateDataLanguage = PyTemplatesUtil.getTemplateDataLanguage(file, null);
|
||||
if (templateDataLanguage == null) {
|
||||
return null; // No template data language
|
||||
}
|
||||
return settings.getIndentOptions(templateDataLanguage.getAssociatedFileType());
|
||||
}
|
||||
}
|
||||
@@ -19,9 +19,9 @@ import com.intellij.lang.Language;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleServiceManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.jetbrains.python.packaging.PyPackageManager;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -111,7 +111,7 @@ public abstract class TemplatesService {
|
||||
public abstract void setTemplateFileTypes(List<String> fileTypes);
|
||||
|
||||
public abstract void generateTemplates(@NotNull final TemplateSettingsHolder settings, VirtualFile baseDir);
|
||||
public abstract void installTemplateEngine(@NotNull final TemplateSettingsHolder settings, @NotNull final PyPackageManager packageManager,
|
||||
public abstract void installTemplateEngine(@NotNull final TemplateSettingsHolder settings, @NotNull final Sdk sdk,
|
||||
@NotNull final Project project, @NotNull final String prefix);
|
||||
|
||||
public abstract void addLanguageSelectedListener(Runnable listener);
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package com.jetbrains.rest;
|
||||
|
||||
import com.intellij.execution.ExecutionException;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.CommonDataKeys;
|
||||
import com.intellij.openapi.actionSystem.LangDataKeys;
|
||||
@@ -26,8 +25,11 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.jetbrains.python.packaging.PyPackage;
|
||||
import com.jetbrains.python.packaging.PyPackageManager;
|
||||
import com.jetbrains.python.packaging.PyPackageUtil;
|
||||
import com.jetbrains.python.sdk.PythonSdkType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* User : catherine
|
||||
*/
|
||||
@@ -45,15 +47,11 @@ public class RestPythonUtil {
|
||||
module = modules.length == 0 ? null : modules [0];
|
||||
}
|
||||
if (module != null) {
|
||||
Sdk sdk = PythonSdkType.findPythonSdk(module);
|
||||
final Sdk sdk = PythonSdkType.findPythonSdk(module);
|
||||
if (sdk != null) {
|
||||
PyPackageManager manager = PyPackageManager.getInstance(sdk);
|
||||
try {
|
||||
final PyPackage sphinx = manager.findPackage("Sphinx", false);
|
||||
presentation.setEnabled(sphinx != null);
|
||||
}
|
||||
catch (ExecutionException ignored) {
|
||||
}
|
||||
final List<PyPackage> packages = PyPackageManager.getInstance(sdk).getPackages();
|
||||
final PyPackage sphinx = packages != null ? PyPackageUtil.findPackage(packages, "Sphinx") : null;
|
||||
presentation.setEnabled(sphinx != null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,10 +25,13 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.jetbrains.python.packaging.PyPackage;
|
||||
import com.jetbrains.python.packaging.PyPackageManager;
|
||||
import com.jetbrains.python.packaging.PyPackageUtil;
|
||||
import com.jetbrains.rest.run.RestConfigurationEditor;
|
||||
import com.jetbrains.rest.run.RestRunConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* User : catherine
|
||||
*/
|
||||
@@ -42,14 +45,13 @@ public class SphinxRunConfiguration extends RestRunConfiguration {
|
||||
protected SettingsEditor<? extends RunConfiguration> createConfigurationEditor() {
|
||||
final SphinxTasksModel model = new SphinxTasksModel();
|
||||
if (!model.contains("pdf") && getSdk() != null) {
|
||||
try {
|
||||
final PyPackage rst2pdf = PyPackageManager.getInstance(getSdk()).findPackage("rst2pdf");
|
||||
final List<PyPackage> packages = PyPackageManager.getInstance(getSdk()).getPackages();
|
||||
if (packages != null) {
|
||||
final PyPackage rst2pdf = PyPackageUtil.findPackage(packages,"rst2pdf");
|
||||
if (rst2pdf != null) {
|
||||
model.add(13, "pdf");
|
||||
}
|
||||
}
|
||||
catch (ExecutionException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
RestConfigurationEditor editor = new RestConfigurationEditor(getProject(), this, model);
|
||||
|
||||
@@ -889,7 +889,7 @@ sdk.gen.reloading=Reloading generated skeletons...
|
||||
sdk.gen.reading.versions.file=Reading versions file...
|
||||
sdk.gen.notify.converting.old.skels=Converting old skeletons
|
||||
sdk.gen.notify.converting.text=Skeletons of binary modules seem to be from an older version.<br/>These will be fully re-generated, which will take some time, but will happen <i>only once</i>.<br/>Next time you open the project, only skeletons of new or updated binary modules will be re-generated.
|
||||
sdk.gen.updating.skeletons=Updating Skeletons
|
||||
sdk.gen.updating.interpreter=Updating Python Interpreter
|
||||
sdk.gen.stubs.for.binary.modules=Generate stubs for binary module {0}
|
||||
|
||||
# Active SDK configurable and related dialogs
|
||||
@@ -1009,4 +1009,4 @@ formatter.dictionary.literals=Dictionary literals
|
||||
|
||||
smartKeys.insert.backslash.in.statement.on.enter=Insert backslash when pressing Enter inside a statement
|
||||
smartKeys.insert.self.in.method=Insert 'self' when defining a method
|
||||
smartKeys.insert.type.placeholder.in.docstring.stub=Insert type placeholders in the documentation comment stub
|
||||
smartKeys.insert.type.placeholder.in.docstring.stub=Insert type placeholders in the documentation comment stub
|
||||
|
||||
@@ -39,7 +39,6 @@ import com.jetbrains.python.packaging.*;
|
||||
import com.jetbrains.python.packaging.ui.PyChooseRequirementsDialog;
|
||||
import com.jetbrains.python.psi.*;
|
||||
import com.jetbrains.python.psi.impl.PyPsiUtils;
|
||||
import com.jetbrains.python.sdk.PySdkUtil;
|
||||
import com.jetbrains.python.sdk.PythonSdkType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -158,7 +157,7 @@ public class PyPackageRequirementsInspection extends PyInspection {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (PyPackageManager.SETUPTOOLS.equals(packageName)) {
|
||||
if (PyPackageUtil.SETUPTOOLS.equals(packageName)) {
|
||||
return;
|
||||
}
|
||||
final Module module = ModuleUtilCore.findModuleForPsiElement(packageReferenceExpression);
|
||||
@@ -211,13 +210,7 @@ public class PyPackageRequirementsInspection extends PyInspection {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
final Set<PyRequirement> results = new HashSet<PyRequirement>(requirements);
|
||||
final List<PyPackage> packages;
|
||||
try {
|
||||
packages = PyPackageManager.getInstance(sdk).getPackages(PySdkUtil.isRemote(sdk));
|
||||
}
|
||||
catch (ExecutionException e) {
|
||||
return null;
|
||||
}
|
||||
final List<PyPackage> packages = PyPackageManager.getInstance(sdk).getPackages();
|
||||
if (packages == null) return null;
|
||||
for (PyRequirement req : requirements) {
|
||||
final PyPackage pkg = req.match(packages);
|
||||
@@ -237,15 +230,10 @@ public class PyPackageRequirementsInspection extends PyInspection {
|
||||
final PyPackageManager manager = PyPackageManager.getInstance(sdk);
|
||||
List<PyRequirement> requirements = manager.getRequirements(module);
|
||||
if (requirements != null) {
|
||||
final List<PyPackage> packages;
|
||||
try {
|
||||
packages = manager.getPackages(PySdkUtil.isRemote(sdk));
|
||||
}
|
||||
catch (ExecutionException e) {
|
||||
LOG.warn(e);
|
||||
final List<PyPackage> packages = manager.getPackages();
|
||||
if (packages == null) {
|
||||
return null;
|
||||
}
|
||||
if (packages == null) return null;
|
||||
final List<PyRequirement> unsatisfied = new ArrayList<PyRequirement>();
|
||||
for (PyRequirement req : requirements) {
|
||||
if (!ignoredPackages.contains(req.getName()) && req.match(packages) == null) {
|
||||
@@ -297,13 +285,11 @@ public class PyPackageRequirementsInspection extends PyInspection {
|
||||
public void applyFix(@NotNull final Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
boolean installManagement = false;
|
||||
final PyPackageManager manager = PyPackageManager.getInstance(mySdk);
|
||||
boolean hasManagement = false;
|
||||
try {
|
||||
hasManagement = manager.hasManagement(false);
|
||||
final List<PyPackage> packages = manager.getPackages();
|
||||
if (packages == null) {
|
||||
return;
|
||||
}
|
||||
catch (ExecutionException ignored) {
|
||||
}
|
||||
if (!hasManagement) {
|
||||
if (PyPackageUtil.hasManagement(packages)) {
|
||||
final int result = Messages.showYesNoDialog(project,
|
||||
"Python packaging tools are required for installing packages. Do you want to " +
|
||||
"install 'pip' and 'setuptools' for your interpreter?",
|
||||
|
||||
@@ -49,9 +49,8 @@ public class PyCondaPackageManagerImpl extends PyPackageManagerImpl {
|
||||
public void installManagement() throws ExecutionException {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean hasManagement(boolean cachedOnly) throws ExecutionException {
|
||||
public boolean hasManagement() throws ExecutionException {
|
||||
final Sdk sdk = getSdk();
|
||||
return isCondaVEnv(sdk);
|
||||
}
|
||||
@@ -126,10 +125,10 @@ public class PyCondaPackageManagerImpl extends PyPackageManagerImpl {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected List<PyPackage> getPackages() throws ExecutionException {
|
||||
protected List<PyPackage> collectPackages() throws ExecutionException {
|
||||
final ProcessOutput output = getCondaOutput("list", Lists.newArrayList("-e"));
|
||||
final Set<PyPackage> packages = Sets.newConcurrentHashSet(parseCondaToolOutput(output.getStdout()));
|
||||
packages.addAll(super.getPackages());
|
||||
packages.addAll(super.collectPackages());
|
||||
return Lists.newArrayList(packages);
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,6 @@ 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.PySdkUtil;
|
||||
import com.jetbrains.python.sdk.PythonEnvUtil;
|
||||
import com.jetbrains.python.sdk.PythonSdkType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -78,9 +77,8 @@ public class PyPackageManagerImpl extends PyPackageManager {
|
||||
public static final String UNINSTALL = "uninstall";
|
||||
public static final String UNTAR = "untar";
|
||||
|
||||
private final Object myCacheLock = new Object();
|
||||
private List<PyPackage> myPackagesCache = null;
|
||||
private ExecutionException myExceptionCache = null;
|
||||
@Nullable private volatile List<PyPackage> myPackagesCache = null;
|
||||
private volatile boolean myUpdatingCache = false;
|
||||
|
||||
@NotNull final private Sdk mySdk;
|
||||
|
||||
@@ -95,7 +93,6 @@ public class PyPackageManagerImpl extends PyPackageManager {
|
||||
VfsUtil.markDirtyAndRefresh(true, true, true, files);
|
||||
});
|
||||
PythonSdkType.getInstance().setupSdkPaths(sdk);
|
||||
clearCaches();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -103,24 +100,25 @@ public class PyPackageManagerImpl extends PyPackageManager {
|
||||
public void installManagement() throws ExecutionException {
|
||||
final Sdk sdk = getSdk();
|
||||
final boolean pre26 = PythonSdkType.getLanguageLevelForSdk(sdk).isOlderThan(LanguageLevel.PYTHON26);
|
||||
if (!hasSetuptools(false)) {
|
||||
final String name = SETUPTOOLS + "-" + (pre26 ? SETUPTOOLS_PRE_26_VERSION : SETUPTOOLS_VERSION);
|
||||
if (!refreshAndCheckForSetuptools()) {
|
||||
final String name = PyPackageUtil.SETUPTOOLS + "-" + (pre26 ? SETUPTOOLS_PRE_26_VERSION : SETUPTOOLS_VERSION);
|
||||
installManagement(name);
|
||||
}
|
||||
if (!hasPackage(PIP, false)) {
|
||||
final String name = PIP + "-" + (pre26 ? PIP_PRE_26_VERSION : PIP_VERSION);
|
||||
if (PyPackageUtil.findPackage(refreshAndGetPackages(false), PyPackageUtil.PIP) == null) {
|
||||
final String name = PyPackageUtil.PIP + "-" + (pre26 ? PIP_PRE_26_VERSION : PIP_VERSION);
|
||||
installManagement(name);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasManagement(boolean cachedOnly) throws ExecutionException {
|
||||
return hasSetuptools(cachedOnly) && hasPackage(PIP, cachedOnly);
|
||||
public boolean hasManagement() throws ExecutionException {
|
||||
return refreshAndCheckForSetuptools() && PyPackageUtil.findPackage(refreshAndGetPackages(false), PyPackageUtil.PIP) != null;
|
||||
}
|
||||
|
||||
private boolean hasSetuptools(boolean cachedOnly) throws ExecutionException {
|
||||
private boolean refreshAndCheckForSetuptools() throws ExecutionException {
|
||||
try {
|
||||
return hasPackage(SETUPTOOLS, cachedOnly) || hasPackage(DISTRIBUTE, cachedOnly);
|
||||
final List<PyPackage> packages = refreshAndGetPackages(false);
|
||||
return PyPackageUtil.findPackage(packages, PyPackageUtil.SETUPTOOLS) != null || PyPackageUtil.findPackage(packages, PyPackageUtil.DISTRIBUTE) != null;
|
||||
}
|
||||
catch (PyExecutionException e) {
|
||||
if (e.getExitCode() == ERROR_NO_SETUPTOOLS) {
|
||||
@@ -137,7 +135,6 @@ public class PyPackageManagerImpl extends PyPackageManager {
|
||||
getPythonProcessResult(fileName, Collections.singletonList(INSTALL), true, true, dirName + name);
|
||||
}
|
||||
finally {
|
||||
clearCaches();
|
||||
FileUtil.delete(new File(dirName));
|
||||
}
|
||||
}
|
||||
@@ -154,10 +151,6 @@ public class PyPackageManagerImpl extends PyPackageManager {
|
||||
return dirName;
|
||||
}
|
||||
|
||||
private boolean hasPackage(@NotNull String name, boolean cachedOnly) throws ExecutionException {
|
||||
return findPackage(name, cachedOnly) != null;
|
||||
}
|
||||
|
||||
PyPackageManagerImpl(@NotNull final Sdk sdk) {
|
||||
mySdk = sdk;
|
||||
subscribeToLocalChanges();
|
||||
@@ -224,7 +217,7 @@ public class PyPackageManagerImpl extends PyPackageManager {
|
||||
}
|
||||
finally {
|
||||
LOG.debug("Packages cache is about to be cleared because these requirements were installed: " + requirements);
|
||||
clearCaches();
|
||||
refreshPackagesSynchronously();
|
||||
FileUtil.delete(buildDir);
|
||||
}
|
||||
}
|
||||
@@ -250,50 +243,20 @@ public class PyPackageManagerImpl extends PyPackageManager {
|
||||
}
|
||||
finally {
|
||||
LOG.debug("Packages cache is about to be cleared because these packages were uninstalled: " + packages);
|
||||
clearCaches();
|
||||
refreshPackagesSynchronously();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
public List<PyPackage> getPackages(boolean cachedOnly) throws ExecutionException {
|
||||
synchronized (myCacheLock) {
|
||||
if (myPackagesCache != null) {
|
||||
return new ArrayList<PyPackage>(myPackagesCache);
|
||||
}
|
||||
if (myExceptionCache != null) {
|
||||
throw myExceptionCache;
|
||||
}
|
||||
if (cachedOnly) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
try {
|
||||
final List<PyPackage> packages = getPackages();
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Packages installed in " + mySdk.getName() + ": " + packages);
|
||||
}
|
||||
synchronized (myCacheLock) {
|
||||
myPackagesCache = packages;
|
||||
return new ArrayList<PyPackage>(myPackagesCache);
|
||||
}
|
||||
}
|
||||
catch (ExecutionException e) {
|
||||
synchronized (myCacheLock) {
|
||||
myExceptionCache = e;
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
@Override
|
||||
public List<PyPackage> getPackages() {
|
||||
final List<PyPackage> packages = myPackagesCache;
|
||||
return packages != null ? Collections.unmodifiableList(packages) : null;
|
||||
}
|
||||
|
||||
//@NotNull
|
||||
//public String fetchLatestVersion(InstalledPackage pkg) throws ExecutionException {
|
||||
// final ArrayList<String> arguments = Lists.newArrayList("latestVersion", pkg.getName());
|
||||
// arguments.addAll(PyPackageService.getInstance().additionalRepositories);
|
||||
// return getHelperResult(PACKAGING_TOOL, arguments, false, false, null);
|
||||
//}
|
||||
|
||||
@NotNull
|
||||
protected List<PyPackage> getPackages() throws ExecutionException {
|
||||
protected List<PyPackage> collectPackages() throws ExecutionException {
|
||||
final String output;
|
||||
try {
|
||||
output = getHelperResult(PACKAGING_TOOL, Collections.singletonList("list"), false, false, null);
|
||||
@@ -301,8 +264,8 @@ public class PyPackageManagerImpl extends PyPackageManager {
|
||||
catch (final ProcessNotCreatedException ex) {
|
||||
if (ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
LOG.info("Not-env unit test mode, will return mock packages");
|
||||
return Lists.newArrayList(new PyPackage(PIP, PIP_VERSION, null, Collections.<PyRequirement>emptyList()),
|
||||
new PyPackage(SETUPTOOLS, SETUPTOOLS_VERSION, null, Collections.<PyRequirement>emptyList()));
|
||||
return Lists.newArrayList(new PyPackage(PyPackageUtil.PIP, PIP_VERSION, null, Collections.<PyRequirement>emptyList()),
|
||||
new PyPackage(PyPackageUtil.SETUPTOOLS, SETUPTOOLS_VERSION, null, Collections.<PyRequirement>emptyList()));
|
||||
}
|
||||
else {
|
||||
throw ex;
|
||||
@@ -314,40 +277,17 @@ public class PyPackageManagerImpl extends PyPackageManager {
|
||||
|
||||
@Nullable
|
||||
public Set<PyPackage> getDependents(@NotNull PyPackage pkg) throws ExecutionException {
|
||||
final List<PyPackage> packages = getPackages(false);
|
||||
if (packages != null) {
|
||||
final Set<PyPackage> dependents = new HashSet<PyPackage>();
|
||||
for (PyPackage p : packages) {
|
||||
final List<PyRequirement> requirements = p.getRequirements();
|
||||
for (PyRequirement requirement : requirements) {
|
||||
if (requirement.getName().equals(pkg.getName())) {
|
||||
dependents.add(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
return dependents;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public PyPackage findPackage(@NotNull String name, boolean cachedOnly) throws ExecutionException {
|
||||
final List<PyPackage> packages = getPackages(cachedOnly);
|
||||
if (packages != null) {
|
||||
for (PyPackage pkg : packages) {
|
||||
if (name.equalsIgnoreCase(pkg.getName())) {
|
||||
return pkg;
|
||||
final List<PyPackage> packages = refreshAndGetPackages(false);
|
||||
final Set<PyPackage> dependents = new HashSet<PyPackage>();
|
||||
for (PyPackage p : packages) {
|
||||
final List<PyRequirement> requirements = p.getRequirements();
|
||||
for (PyRequirement requirement : requirements) {
|
||||
if (requirement.getName().equals(pkg.getName())) {
|
||||
dependents.add(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public final PyPackage findPackage(@NotNull final String name) throws ExecutionException {
|
||||
return findPackage(name, PySdkUtil.isRemote(mySdk));
|
||||
return dependents;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -405,11 +345,38 @@ public class PyPackageManagerImpl extends PyPackageManager {
|
||||
.orElseGet(() -> PyPackageUtil.findSetupPyRequires(module));
|
||||
}
|
||||
|
||||
protected void clearCaches() {
|
||||
synchronized (myCacheLock) {
|
||||
myPackagesCache = null;
|
||||
myExceptionCache = null;
|
||||
LOG.debug("Packages cache is cleared");
|
||||
|
||||
// public List<PyPackage> refreshAndGetPackagesIfNotInProgress(boolean alwaysRefresh) throws ExecutionException
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public List<PyPackage> refreshAndGetPackages(boolean alwaysRefresh) throws ExecutionException {
|
||||
final List<PyPackage> currentPackages = myPackagesCache;
|
||||
if (alwaysRefresh || currentPackages == null) {
|
||||
myUpdatingCache = true;
|
||||
try {
|
||||
final List<PyPackage> packages = collectPackages();
|
||||
myPackagesCache = packages;
|
||||
return packages;
|
||||
}
|
||||
finally {
|
||||
myUpdatingCache = false;
|
||||
}
|
||||
}
|
||||
return Collections.unmodifiableList(currentPackages);
|
||||
}
|
||||
|
||||
private void refreshPackagesSynchronously() {
|
||||
assert !ApplicationManager.getApplication().isDispatchThread();
|
||||
if (myUpdatingCache) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
LOG.info("Refreshing installed packages for SDK " + mySdk.getHomePath());
|
||||
refreshAndGetPackages(true);
|
||||
}
|
||||
catch (ExecutionException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -568,7 +535,7 @@ public class PyPackageManagerImpl extends PyPackageManager {
|
||||
for (VirtualFile root : roots) {
|
||||
if (VfsUtilCore.isAncestor(root, file, false)) {
|
||||
LOG.debug("Clearing packages cache on SDK change");
|
||||
clearCaches();
|
||||
ApplicationManager.getApplication().executeOnPooledThread(PyPackageManagerImpl.this::refreshPackagesSynchronously);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,10 +29,7 @@ import com.jetbrains.python.sdk.flavors.PythonSdkFlavor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
@@ -98,16 +95,16 @@ public class PyPackageManagersImpl extends PyPackageManagers {
|
||||
throw new ExecutionException(getErrorMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasManagement() throws ExecutionException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private String getErrorMessage() {
|
||||
return "Invalid interpreter \"" + myName + "\" version: " + myLanguageLevel.toString() + " type: " + myFlavor.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasManagement(boolean cachedOnly) throws ExecutionException {
|
||||
throw new ExecutionException(getErrorMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void install(@NotNull String requirementString) throws ExecutionException {
|
||||
throw new ExecutionException(getErrorMessage());
|
||||
@@ -135,19 +132,13 @@ public class PyPackageManagersImpl extends PyPackageManagers {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public List<PyPackage> getPackages(boolean cachedOnly) throws ExecutionException {
|
||||
throw new ExecutionException(getErrorMessage());
|
||||
public List<PyPackage> getPackages() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@NotNull
|
||||
@Override
|
||||
public PyPackage findPackage(@NotNull String name, boolean cachedOnly) throws ExecutionException {
|
||||
throw new ExecutionException(getErrorMessage());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public PyPackage findPackage(@NotNull String name) throws ExecutionException {
|
||||
public List<PyPackage> refreshAndGetPackages(boolean alwaysRefresh) throws ExecutionException {
|
||||
throw new ExecutionException(getErrorMessage());
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@ package com.jetbrains.python.packaging;
|
||||
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.execution.ExecutionException;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
@@ -53,6 +55,10 @@ import java.util.stream.Stream;
|
||||
* @author vlan
|
||||
*/
|
||||
public class PyPackageUtil {
|
||||
public static final String SETUPTOOLS = "setuptools";
|
||||
public static final String PIP = "pip";
|
||||
public static final String DISTRIBUTE = "distribute";
|
||||
private static final Logger LOG = Logger.getInstance(PyPackageUtil.class);
|
||||
|
||||
@NotNull
|
||||
private static final String REQUIRES = "requires";
|
||||
@@ -270,6 +276,36 @@ public class PyPackageUtil {
|
||||
}.withSshContribution(true).withVagrantContribution(true).withWebDeploymentContribution(true).check(sdk);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static List<PyPackage> refreshAndGetPackagesModally(@NotNull Sdk sdk) {
|
||||
final Ref<List<PyPackage>> packagesRef = Ref.create();
|
||||
PyUtil.runWithProgress(null, "Scanning Installed Packages", true, false, indicator -> {
|
||||
indicator.setIndeterminate(true);
|
||||
try {
|
||||
packagesRef.set(PyPackageManager.getInstance(sdk).refreshAndGetPackages(false));
|
||||
}
|
||||
catch (ExecutionException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
});
|
||||
return packagesRef.get();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static PyPackage findPackage(@NotNull List<PyPackage> packages, @NotNull String name) {
|
||||
for (PyPackage pkg : packages) {
|
||||
if (name.equalsIgnoreCase(pkg.getName())) {
|
||||
return pkg;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean hasManagement(@NotNull List<PyPackage> packages) {
|
||||
return (findPackage(packages, SETUPTOOLS) != null || findPackage(packages, DISTRIBUTE) != null) ||
|
||||
findPackage(packages, PIP) != null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static List<PyRequirement> getRequirementsFromTxt(@NotNull Module module) {
|
||||
final VirtualFile requirementsTxt = findRequirementsTxt(module);
|
||||
|
||||
@@ -214,7 +214,6 @@ public class PyRemotePackageManagerImpl extends PyPackageManagerImpl {
|
||||
try {
|
||||
manager.runVagrant(myVagrantFolder, myMachineName);
|
||||
PythonSdkType.getInstance().setupSdkPaths(sdk);
|
||||
clearCaches();
|
||||
}
|
||||
catch (ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
|
||||
@@ -93,7 +93,7 @@ public class PyInstalledPackagesPanel extends InstalledPackagesPanel {
|
||||
application.executeOnPooledThread(() -> {
|
||||
PyExecutionException exception = null;
|
||||
try {
|
||||
myHasManagement = PyPackageManager.getInstance(selectedSdk).hasManagement(false);
|
||||
myHasManagement = PyPackageManager.getInstance(selectedSdk).hasManagement();
|
||||
if (!myHasManagement) {
|
||||
throw new PyExecutionException("Python packaging tools not found", "pip", Collections.<String>emptyList(), "", "", 0,
|
||||
ImmutableList.of(new PyInstallPackageManagementFix()));
|
||||
@@ -156,9 +156,9 @@ public class PyInstalledPackagesPanel extends InstalledPackagesPanel {
|
||||
}
|
||||
}
|
||||
final String name = pkg.getName();
|
||||
if (PyPackageManager.PIP.equals(name) ||
|
||||
PyPackageManager.SETUPTOOLS.equals(name) ||
|
||||
PyPackageManager.DISTRIBUTE.equals(name) ||
|
||||
if (PyPackageUtil.PIP.equals(name) ||
|
||||
PyPackageUtil.SETUPTOOLS.equals(name) ||
|
||||
PyPackageUtil.DISTRIBUTE.equals(name) ||
|
||||
PyCondaPackageManagerImpl.PYTHON.equals(name)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.jetbrains.python.packaging.ui;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.execution.ExecutionException;
|
||||
import com.intellij.execution.RunCanceledByUserException;
|
||||
import com.intellij.openapi.project.Project;
|
||||
@@ -139,17 +140,17 @@ public class PyPackageManagementService extends PackageManagementServiceEx {
|
||||
|
||||
@Override
|
||||
public Collection<InstalledPackage> getInstalledPackages() throws IOException {
|
||||
List<PyPackage> packages;
|
||||
|
||||
final PyPackageManager manager = PyPackageManager.getInstance(mySdk);
|
||||
final List<PyPackage> packages;
|
||||
try {
|
||||
packages = PyPackageManager.getInstance(mySdk).getPackages(false);
|
||||
if (packages != null) {
|
||||
Collections.sort(packages, (pkg1, pkg2) -> pkg1.getName().compareTo(pkg2.getName()));
|
||||
}
|
||||
packages = Lists.newArrayList(manager.refreshAndGetPackages(false));
|
||||
}
|
||||
catch (ExecutionException e) {
|
||||
throw new IOException(e);
|
||||
}
|
||||
return packages != null ? new ArrayList<InstalledPackage>(packages) : new ArrayList<InstalledPackage>();
|
||||
Collections.sort(packages, (pkg1, pkg2) -> pkg1.getName().compareTo(pkg2.getName()));
|
||||
return new ArrayList<InstalledPackage>(packages);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -28,6 +28,7 @@ import com.intellij.injected.editor.VirtualFileWindow;
|
||||
import com.intellij.lang.ASTFactory;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.ModalityState;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.EditorFactory;
|
||||
@@ -38,6 +39,9 @@ import com.intellij.openapi.extensions.Extensions;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleManager;
|
||||
import com.intellij.openapi.module.ModuleUtilCore;
|
||||
import com.intellij.openapi.progress.ProgressIndicator;
|
||||
import com.intellij.openapi.progress.ProgressManager;
|
||||
import com.intellij.openapi.progress.Task;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.roots.ModuleRootManager;
|
||||
@@ -81,15 +85,11 @@ import com.jetbrains.python.refactoring.classes.PyDependenciesComparator;
|
||||
import com.jetbrains.python.refactoring.classes.extractSuperclass.PyExtractSuperclassHelper;
|
||||
import com.jetbrains.python.refactoring.classes.membersManager.PyMemberInfo;
|
||||
import com.jetbrains.python.sdk.PythonSdkType;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.*;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
@@ -858,6 +858,28 @@ public class PyUtil {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void runWithProgress(@Nullable Project project, @Nls(capitalization = Nls.Capitalization.Title) @NotNull String title,
|
||||
boolean modal, boolean canBeCancelled, @NotNull final Consumer<ProgressIndicator> function) {
|
||||
ApplicationManager.getApplication().invokeAndWait(() -> {
|
||||
if (modal) {
|
||||
ProgressManager.getInstance().run(new Task.Modal(project, title, canBeCancelled) {
|
||||
@Override
|
||||
public void run(@NotNull ProgressIndicator indicator) {
|
||||
function.consume(indicator);
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
ProgressManager.getInstance().run(new Task.Backgroundable(project, title, canBeCancelled) {
|
||||
@Override
|
||||
public void run(@NotNull ProgressIndicator indicator) {
|
||||
function.consume(indicator);
|
||||
}
|
||||
});
|
||||
}
|
||||
}, ModalityState.current());
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes code only if <pre>_PYCHARM_VERBOSE_MODE</pre> is set in env (which should be done for debug purposes only)
|
||||
* @param runnable code to call
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.jetbrains.python.sdk;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.intellij.execution.ExecutionException;
|
||||
import com.intellij.openapi.application.Application;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.ModalityState;
|
||||
@@ -44,6 +45,7 @@ import com.intellij.util.concurrency.BlockingSet;
|
||||
import com.intellij.util.concurrency.EdtExecutorService;
|
||||
import com.jetbrains.python.PyBundle;
|
||||
import com.jetbrains.python.codeInsight.userSkeletons.PyUserSkeletonsUtil;
|
||||
import com.jetbrains.python.packaging.PyPackageManager;
|
||||
import com.jetbrains.python.psi.PyUtil;
|
||||
import com.jetbrains.python.remote.PyCredentialsContribution;
|
||||
import com.jetbrains.python.remote.PyRemoteSdkAdditionalDataBase;
|
||||
@@ -138,7 +140,7 @@ public class PythonSdkUpdater implements StartupActivity {
|
||||
}
|
||||
ourScheduledToRefresh.remove(homePath);
|
||||
}
|
||||
ProgressManager.getInstance().run(new Task.Backgroundable(project, PyBundle.message("sdk.gen.updating.skeletons"), false) {
|
||||
ProgressManager.getInstance().run(new Task.Backgroundable(project, PyBundle.message("sdk.gen.updating.interpreter"), false) {
|
||||
@Override
|
||||
public void run(@NotNull ProgressIndicator indicator) {
|
||||
final Project project1 = getProject();
|
||||
@@ -152,8 +154,19 @@ public class PythonSdkUpdater implements StartupActivity {
|
||||
LOG.error("For refreshing skeletons of remote SDK, either project or owner component must be specified");
|
||||
}
|
||||
LOG.info("Performing background update of skeletons for SDK " + sdk12.getHomePath());
|
||||
indicator.setText("Updating skeletons...");
|
||||
PySkeletonRefresher.refreshSkeletonsOfSdk(project1, ownerComponent, skeletonsPath, sdk12);
|
||||
updateRemoteSdkPaths(sdk12);
|
||||
indicator.setIndeterminate(true);
|
||||
indicator.setText("Scanning installed packages...");
|
||||
indicator.setText2("");
|
||||
LOG.info("Performing background scan of packages for SDK " + sdk12.getHomePath());
|
||||
try {
|
||||
PyPackageManager.getInstance(sdk12).refreshAndGetPackages(true);
|
||||
}
|
||||
catch (ExecutionException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
}
|
||||
catch (InvalidSdkException e) {
|
||||
if (PythonSdkType.isVagrant(sdk12)
|
||||
|
||||
@@ -43,7 +43,6 @@ import com.jetbrains.python.PyBundle;
|
||||
import com.jetbrains.python.PyNames;
|
||||
import com.jetbrains.python.buildout.BuildoutFacet;
|
||||
import com.jetbrains.python.codeInsight.userSkeletons.PyUserSkeletonsUtil;
|
||||
import com.jetbrains.python.packaging.PyPackageManager;
|
||||
import com.jetbrains.python.psi.resolve.PythonSdkPathCache;
|
||||
import com.jetbrains.python.remote.PythonRemoteInterpreterManager;
|
||||
import com.jetbrains.python.sdk.InvalidSdkException;
|
||||
@@ -345,15 +344,6 @@ public class PySkeletonRefresher {
|
||||
indicate(PyBundle.message("sdk.gen.cleaning.$0", readablePath));
|
||||
cleanUpSkeletons(skeletonsDir);
|
||||
}
|
||||
if (PySdkUtil.isRemote(mySdk)) {
|
||||
try {
|
||||
// Force loading packages
|
||||
PyPackageManager.getInstance(mySdk).getPackages(false);
|
||||
}
|
||||
catch (ExecutionException e) {
|
||||
// ignore - already logged
|
||||
}
|
||||
}
|
||||
|
||||
if ((builtinsUpdated || PySdkUtil.isRemote(mySdk)) && myProject != null) {
|
||||
ApplicationManager.getApplication().invokeLater(() -> DaemonCodeAnalyzer.getInstance(myProject).restart(), myProject.getDisposed());
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package com.jetbrains.python.testing;
|
||||
|
||||
import com.intellij.execution.ExecutionException;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
@@ -30,11 +29,11 @@ import com.intellij.openapi.vfs.newvfs.events.VFileContentChangeEvent;
|
||||
import com.intellij.openapi.vfs.newvfs.events.VFileEvent;
|
||||
import com.intellij.util.Alarm;
|
||||
import com.intellij.util.messages.MessageBus;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import com.intellij.util.ui.update.MergingUpdateQueue;
|
||||
import com.intellij.util.ui.update.Update;
|
||||
import com.jetbrains.python.PyNames;
|
||||
import com.jetbrains.python.packaging.PyPackageManager;
|
||||
import com.jetbrains.python.packaging.PyPackage;
|
||||
import com.jetbrains.python.packaging.PyPackageUtil;
|
||||
import com.jetbrains.python.sdk.PySdkUtil;
|
||||
import com.jetbrains.python.sdk.PythonSdkType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -117,14 +116,11 @@ public class VFSTestFrameworkListener {
|
||||
LOG.info("Searching test runner in empty sdk");
|
||||
return null;
|
||||
}
|
||||
final PyPackageManager packageManager = PyPackageManager.getInstance(sdk);
|
||||
try {
|
||||
return packageManager.findPackage(testPackageName, false) != null;
|
||||
final List<PyPackage> packages = PyPackageUtil.refreshAndGetPackagesModally(sdk);
|
||||
if (packages == null) {
|
||||
return null;
|
||||
}
|
||||
catch (ExecutionException e) {
|
||||
LOG.info("Can't load package list " + e.getMessage());
|
||||
}
|
||||
return null;
|
||||
return PyPackageUtil.findPackage(packages, testPackageName) != null;
|
||||
}
|
||||
|
||||
public static VFSTestFrameworkListener getInstance() {
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package com.jetbrains.python.testing.pytest;
|
||||
|
||||
import com.intellij.execution.ExecutionException;
|
||||
import com.intellij.execution.Location;
|
||||
import com.intellij.execution.actions.ConfigurationContext;
|
||||
import com.intellij.openapi.module.Module;
|
||||
@@ -31,6 +30,7 @@ import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.webcore.packaging.PackageVersionComparator;
|
||||
import com.jetbrains.python.packaging.PyPackage;
|
||||
import com.jetbrains.python.packaging.PyPackageManager;
|
||||
import com.jetbrains.python.packaging.PyPackageUtil;
|
||||
import com.jetbrains.python.psi.PyClass;
|
||||
import com.jetbrains.python.psi.PyFile;
|
||||
import com.jetbrains.python.psi.PyFunction;
|
||||
@@ -115,17 +115,12 @@ public class PyTestConfigurationProducer extends PythonTestConfigurationProducer
|
||||
if (pyFunction != null) {
|
||||
keywords = pyFunction.getName();
|
||||
if (pyClass != null) {
|
||||
final PyPackageManager packageManager = PyPackageManager.getInstance(sdk);
|
||||
try {
|
||||
final PyPackage pytestPackage = packageManager.findPackage("pytest", false);
|
||||
if (pytestPackage != null && PackageVersionComparator.VERSION_COMPARATOR.compare(pytestPackage.getVersion(), "2.3.3") >= 0) {
|
||||
keywords = pyClass.getName() + " and " + keywords;
|
||||
}
|
||||
else {
|
||||
keywords = pyClass.getName() + "." + keywords;
|
||||
}
|
||||
final List<PyPackage> packages = PyPackageManager.getInstance(sdk).getPackages();
|
||||
final PyPackage pytestPackage = packages != null ? PyPackageUtil.findPackage(packages, "pytest") : null;
|
||||
if (pytestPackage != null && PackageVersionComparator.VERSION_COMPARATOR.compare(pytestPackage.getVersion(), "2.3.3") >= 0) {
|
||||
keywords = pyClass.getName() + " and " + keywords;
|
||||
}
|
||||
catch (ExecutionException e) {
|
||||
else {
|
||||
keywords = pyClass.getName() + "." + keywords;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import com.intellij.util.ui.UIUtil;
|
||||
import com.jetbrains.TestEnv;
|
||||
import com.jetbrains.python.packaging.PyPackage;
|
||||
import com.jetbrains.python.packaging.PyPackageManager;
|
||||
import com.jetbrains.python.packaging.PyPackageUtil;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -113,7 +114,7 @@ public abstract class PyEnvTestCase {
|
||||
|
||||
@Nullable
|
||||
public static PyPackage getInstalledDjango(@NotNull final Sdk sdk) throws ExecutionException {
|
||||
return PyPackageManager.getInstance(sdk).findPackage("django", false);
|
||||
return PyPackageUtil.findPackage(PyPackageManager.getInstance(sdk).refreshAndGetPackages(false), "django");
|
||||
}
|
||||
|
||||
public static String norm(String testDataPath) {
|
||||
|
||||
@@ -52,7 +52,7 @@ public class PyPackagingTest extends PyEnvTestCase {
|
||||
final Sdk sdk = createTempSdk(sdkHome, SdkCreationType.EMPTY_SDK);
|
||||
List<PyPackage> packages = null;
|
||||
try {
|
||||
packages = PyPackageManager.getInstance(sdk).getPackages(false);
|
||||
packages = PyPackageManager.getInstance(sdk).refreshAndGetPackages(false);
|
||||
}
|
||||
catch (ExecutionException ignored) {
|
||||
}
|
||||
@@ -82,7 +82,7 @@ public class PyPackagingTest extends PyEnvTestCase {
|
||||
assertNotNull(venvSdk);
|
||||
assertTrue(PythonSdkType.isVirtualEnv(venvSdk));
|
||||
assertInstanceOf(PythonSdkFlavor.getPlatformIndependentFlavor(venvSdk.getHomePath()), VirtualEnvSdkFlavor.class);
|
||||
final List<PyPackage> packages = PyPackageManager.getInstance(venvSdk).getPackages(false);
|
||||
final List<PyPackage> packages = PyPackageManager.getInstance(venvSdk).refreshAndGetPackages(false);
|
||||
final PyPackage setuptools = findPackage("setuptools", packages);
|
||||
assertNotNull(setuptools);
|
||||
assertEquals("setuptools", setuptools.getName());
|
||||
@@ -114,11 +114,11 @@ public class PyPackagingTest extends PyEnvTestCase {
|
||||
final Sdk venvSdk = createTempSdk(venvSdkHome, SdkCreationType.EMPTY_SDK);
|
||||
assertNotNull(venvSdk);
|
||||
final PyPackageManager manager = PyPackageManager.getInstance(venvSdk);
|
||||
final List<PyPackage> packages1 = manager.getPackages(false);
|
||||
final List<PyPackage> packages1 = manager.refreshAndGetPackages(false);
|
||||
// TODO: Install Markdown from a local file
|
||||
manager.install(list(PyRequirement.fromLine("Markdown<2.2"),
|
||||
new PyRequirement("httplib2")), Collections.<String>emptyList());
|
||||
final List<PyPackage> packages2 = manager.getPackages(false);
|
||||
final List<PyPackage> packages2 = manager.refreshAndGetPackages(false);
|
||||
final PyPackage markdown2 = findPackage("Markdown", packages2);
|
||||
assertNotNull(markdown2);
|
||||
assertTrue(markdown2.isInstalled());
|
||||
@@ -126,7 +126,7 @@ public class PyPackagingTest extends PyEnvTestCase {
|
||||
assertNotNull(pip1);
|
||||
assertEquals("pip", pip1.getName());
|
||||
manager.uninstall(list(pip1));
|
||||
final List<PyPackage> packages3 = manager.getPackages(false);
|
||||
final List<PyPackage> packages3 = manager.refreshAndGetPackages(false);
|
||||
final PyPackage pip2 = findPackage("pip", packages3);
|
||||
assertNull(pip2);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user