Search in sources :

Example 1 with PyFrameworkProjectGenerator

use of com.jetbrains.python.newProject.PyFrameworkProjectGenerator 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 2 with PyFrameworkProjectGenerator

use of com.jetbrains.python.newProject.PyFrameworkProjectGenerator in project intellij-community by JetBrains.

the class ProjectSpecificSettingsStep method createInterpreterCombo.

@NotNull
private LabeledComponent<PythonSdkChooserCombo> createInterpreterCombo() {
    final Project project = ProjectManager.getInstance().getDefaultProject();
    final List<Sdk> sdks = PyConfigurableInterpreterList.getInstance(project).getAllPythonSdks();
    VirtualEnvProjectFilter.removeAllAssociated(sdks);
    Sdk compatibleSdk = sdks.isEmpty() ? null : sdks.iterator().next();
    DirectoryProjectGenerator generator = getProjectGenerator();
    if (generator instanceof PyFrameworkProjectGenerator && !((PyFrameworkProjectGenerator) generator).supportsPython3()) {
        if (compatibleSdk != null && PythonSdkType.getLanguageLevelForSdk(compatibleSdk).isPy3K()) {
            Sdk python2Sdk = PythonSdkType.findPython2Sdk(sdks);
            if (python2Sdk != null) {
                compatibleSdk = python2Sdk;
            }
        }
    }
    final Sdk preferred = compatibleSdk;
    mySdkCombo = new PythonSdkChooserCombo(project, sdks, sdk -> sdk == preferred);
    if (SystemInfo.isMac && !UIUtil.isUnderDarcula()) {
        mySdkCombo.putClientProperty("JButton.buttonType", null);
    }
    mySdkCombo.setButtonIcon(PythonIcons.Python.InterpreterGear);
    return LabeledComponent.create(mySdkCombo, "Interpreter", BorderLayout.WEST);
}
Also used : UIUtil(com.intellij.util.ui.UIUtil) PySdkUtil(com.jetbrains.python.sdk.PySdkUtil) ActionListener(java.awt.event.ActionListener) PyFrameworkProjectGenerator(com.jetbrains.python.newProject.PyFrameworkProjectGenerator) PythonRemoteInterpreterManager(com.jetbrains.python.remote.PythonRemoteInterpreterManager) ExecutionException(com.intellij.execution.ExecutionException) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) UiNotifyConnector(com.intellij.util.ui.update.UiNotifyConnector) PyProjectSynchronizer(com.jetbrains.python.remote.PyProjectSynchronizer) ProjectManager(com.intellij.openapi.project.ProjectManager) PyPackageManager(com.jetbrains.python.packaging.PyPackageManager) Project(com.intellij.openapi.project.Project) PythonIcons(icons.PythonIcons) PythonSdkType(com.jetbrains.python.sdk.PythonSdkType) WebProjectTemplate(com.intellij.ide.util.projectWizard.WebProjectTemplate) Logger(com.intellij.openapi.diagnostic.Logger) DumbAware(com.intellij.openapi.project.DumbAware) DocumentEvent(javax.swing.event.DocumentEvent) HideableDecorator(com.intellij.ui.HideableDecorator) ProgressManager(com.intellij.openapi.progress.ProgressManager) ItemEvent(java.awt.event.ItemEvent) PyConfigurableInterpreterList(com.jetbrains.python.configuration.PyConfigurableInterpreterList) PythonProjectGenerator(com.jetbrains.python.newProject.PythonProjectGenerator) PyPackageUtil(com.jetbrains.python.packaging.PyPackageUtil) StringUtil(com.intellij.openapi.util.text.StringUtil) ValidationResult(com.intellij.facet.ui.ValidationResult) DirectoryProjectGenerator(com.intellij.platform.DirectoryProjectGenerator) PyPackage(com.jetbrains.python.packaging.PyPackage) TextAccessor(com.intellij.ui.TextAccessor) ActionEvent(java.awt.event.ActionEvent) Sdk(com.intellij.openapi.projectRoots.Sdk) SystemInfo(com.intellij.openapi.util.SystemInfo) File(java.io.File) java.awt(java.awt) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) com.intellij.openapi.ui(com.intellij.openapi.ui) NullableConsumer(com.intellij.util.NullableConsumer) ProjectSettingsStepBase(com.intellij.ide.util.projectWizard.ProjectSettingsStepBase) JBPopupFactory(com.intellij.openapi.ui.popup.JBPopupFactory) Pair(com.intellij.openapi.util.Pair) ApplicationManager(com.intellij.openapi.application.ApplicationManager) PathUtil(com.intellij.util.PathUtil) VirtualEnvProjectFilter(com.jetbrains.python.configuration.VirtualEnvProjectFilter) NotNull(org.jetbrains.annotations.NotNull) DocumentAdapter(com.intellij.ui.DocumentAdapter) javax.swing(javax.swing) Project(com.intellij.openapi.project.Project) PyFrameworkProjectGenerator(com.jetbrains.python.newProject.PyFrameworkProjectGenerator) DirectoryProjectGenerator(com.intellij.platform.DirectoryProjectGenerator) Sdk(com.intellij.openapi.projectRoots.Sdk) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ValidationResult (com.intellij.facet.ui.ValidationResult)2 Sdk (com.intellij.openapi.projectRoots.Sdk)2 PyFrameworkProjectGenerator (com.jetbrains.python.newProject.PyFrameworkProjectGenerator)2 PythonProjectGenerator (com.jetbrains.python.newProject.PythonProjectGenerator)2 PyPackage (com.jetbrains.python.packaging.PyPackage)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 ExecutionException (com.intellij.execution.ExecutionException)1 ProjectSettingsStepBase (com.intellij.ide.util.projectWizard.ProjectSettingsStepBase)1 WebProjectTemplate (com.intellij.ide.util.projectWizard.WebProjectTemplate)1 ApplicationManager (com.intellij.openapi.application.ApplicationManager)1 Logger (com.intellij.openapi.diagnostic.Logger)1 ProgressManager (com.intellij.openapi.progress.ProgressManager)1 DumbAware (com.intellij.openapi.project.DumbAware)1 Project (com.intellij.openapi.project.Project)1 ProjectManager (com.intellij.openapi.project.ProjectManager)1 com.intellij.openapi.ui (com.intellij.openapi.ui)1 JBPopupFactory (com.intellij.openapi.ui.popup.JBPopupFactory)1 Pair (com.intellij.openapi.util.Pair)1 SystemInfo (com.intellij.openapi.util.SystemInfo)1