Search in sources :

Example 6 with PyPackage

use of com.jetbrains.python.packaging.PyPackage in project intellij-community by JetBrains.

the class SphinxRunConfiguration method createConfigurationEditor.

@Override
protected SettingsEditor<? extends RunConfiguration> createConfigurationEditor() {
    final SphinxTasksModel model = new SphinxTasksModel();
    if (!model.contains("pdf") && getSdk() != null) {
        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");
            }
        }
    }
    RestConfigurationEditor editor = new RestConfigurationEditor(getProject(), this, model);
    editor.setConfigurationName("Sphinx task");
    editor.setOpenInBrowserVisible(false);
    editor.setInputDescriptor(FileChooserDescriptorFactory.createSingleFolderDescriptor());
    editor.setOutputDescriptor(FileChooserDescriptorFactory.createSingleFolderDescriptor());
    return editor;
}
Also used : RestConfigurationEditor(com.jetbrains.rest.run.RestConfigurationEditor) PyPackage(com.jetbrains.python.packaging.PyPackage)

Example 7 with PyPackage

use of com.jetbrains.python.packaging.PyPackage in project intellij-community by JetBrains.

the class ProjectSpecificSettingsStep method checkValid.

@Override
public boolean checkValid() {
    myInstallFramework = false;
    if (!super.checkValid()) {
        return false;
    }
    if (myProjectGenerator instanceof PythonProjectGenerator) {
        final Sdk sdk = getSdk();
        if (sdk == null) {
            if (!((PythonProjectGenerator) myProjectGenerator).hideInterpreter()) {
                setErrorText("No Python interpreter selected");
                return false;
            }
            return true;
        }
        if (PythonSdkType.isInvalid(sdk)) {
            setErrorText("Choose valid python interpreter");
            return false;
        }
        final List<String> warningList = new ArrayList<>();
        final boolean isPy3k = PythonSdkType.getLanguageLevelForSdk(sdk).isPy3K();
        try {
            acceptsSdk(myProjectGenerator, sdk, new File(myLocationField.getText()));
        } catch (final PythonProjectGenerator.PyNoProjectAllowedOnSdkException e) {
            setErrorText(e.getMessage());
            return false;
        }
        if (myRemotePathRequired && StringUtil.isEmpty(myRemotePathField.getTextField().getText())) {
            setErrorText("Remote path not provided");
            return false;
        }
        if (myProjectGenerator instanceof PyFrameworkProjectGenerator) {
            PyFrameworkProjectGenerator frameworkProjectGenerator = (PyFrameworkProjectGenerator) myProjectGenerator;
            String frameworkName = frameworkProjectGenerator.getFrameworkTitle();
            if (!isFrameworkInstalled(sdk)) {
                if (PyPackageUtil.packageManagementEnabled(sdk)) {
                    myInstallFramework = true;
                    final List<PyPackage> packages = PyPackageUtil.refreshAndGetPackagesModally(sdk);
                    if (packages == null) {
                        warningList.add(frameworkName + " will be installed on the selected interpreter");
                        return false;
                    }
                    if (!PyPackageUtil.hasManagement(packages)) {
                        warningList.add("Python packaging tools and " + frameworkName + " will be installed on the selected interpreter");
                    } else {
                        warningList.add(frameworkName + " will be installed on the selected interpreter");
                    }
                } else {
                    warningList.add(frameworkName + " is not installed on the selected interpreter");
                }
            }
            final ValidationResult warningResult = ((PythonProjectGenerator) myProjectGenerator).warningValidation(sdk);
            if (!warningResult.isOk()) {
                warningList.add(warningResult.getErrorMessage());
            }
            if (!warningList.isEmpty()) {
                final String warning = StringUtil.join(warningList, "<br/>");
                setWarningText(warning);
            }
            if (isPy3k && !((PyFrameworkProjectGenerator) myProjectGenerator).supportsPython3()) {
                setErrorText(frameworkName + " is not supported for the selected interpreter");
                return false;
            }
        }
    }
    return true;
}
Also used : PyPackage(com.jetbrains.python.packaging.PyPackage) PythonProjectGenerator(com.jetbrains.python.newProject.PythonProjectGenerator) PyFrameworkProjectGenerator(com.jetbrains.python.newProject.PyFrameworkProjectGenerator) ArrayList(java.util.ArrayList) Sdk(com.intellij.openapi.projectRoots.Sdk) ValidationResult(com.intellij.facet.ui.ValidationResult) File(java.io.File)

Example 8 with PyPackage

use of com.jetbrains.python.packaging.PyPackage in project intellij-community by JetBrains.

the class IpnbConnectionManager method connectToIpythonServer.

private boolean connectToIpythonServer(@NotNull final IpnbCodePanel codePanel, @NotNull final IpnbFileEditor fileEditor, @NotNull final String path, @NotNull final String url) {
    final IpnbSettings ipnbSettings = IpnbSettings.getInstance(myProject);
    final boolean isRemote = ipnbSettings.isRemote();
    if (!isRemote) {
        if (myToken != null)
            return startConnection(codePanel, path, url, true);
        final Module module = ProjectFileIndex.SERVICE.getInstance(myProject).getModuleForFile(fileEditor.getVirtualFile());
        if (module != null) {
            final Sdk sdk = PythonSdkType.findPythonSdk(module);
            if (sdk != null) {
                final List<PyPackage> packages = PyPackageManager.getInstance(sdk).getPackages();
                if (packages != null) {
                    final PyPackage notebookPackage = PyPackageUtil.findPackage(packages, "notebook");
                    if (notebookPackage != null && VersionComparatorUtil.compare(notebookPackage.getVersion(), "4.3.0") >= 0) {
                        ApplicationManager.getApplication().invokeAndWait(() -> myToken = askForToken(url));
                        if (myToken == null)
                            return false;
                    }
                }
            }
        }
    }
    return startConnection(codePanel, path, url, isRemote);
}
Also used : PyPackage(com.jetbrains.python.packaging.PyPackage) Sdk(com.intellij.openapi.projectRoots.Sdk) Module(com.intellij.openapi.module.Module)

Aggregations

PyPackage (com.jetbrains.python.packaging.PyPackage)8 Sdk (com.intellij.openapi.projectRoots.Sdk)5 Module (com.intellij.openapi.module.Module)4 Project (com.intellij.openapi.project.Project)2 NotNull (org.jetbrains.annotations.NotNull)2 ExecutionException (com.intellij.execution.ExecutionException)1 RunContentExecutor (com.intellij.execution.RunContentExecutor)1 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)1 UrlFilter (com.intellij.execution.filters.UrlFilter)1 KillableColoredProcessHandler (com.intellij.execution.process.KillableColoredProcessHandler)1 ValidationResult (com.intellij.facet.ui.ValidationResult)1 Presentation (com.intellij.openapi.actionSystem.Presentation)1 Key (com.intellij.openapi.util.Key)1 PyFrameworkProjectGenerator (com.jetbrains.python.newProject.PyFrameworkProjectGenerator)1 PythonProjectGenerator (com.jetbrains.python.newProject.PythonProjectGenerator)1 PyPackageManager (com.jetbrains.python.packaging.PyPackageManager)1 PyClass (com.jetbrains.python.psi.PyClass)1 PyFunction (com.jetbrains.python.psi.PyFunction)1 RestConfigurationEditor (com.jetbrains.rest.run.RestConfigurationEditor)1 File (java.io.File)1