use of com.jetbrains.python.newProject.PythonProjectGenerator 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;
}
use of com.jetbrains.python.newProject.PythonProjectGenerator in project intellij-community by JetBrains.
the class ProjectSpecificSettingsStep method createAdvancedSettings.
@Override
@Nullable
protected JPanel createAdvancedSettings() {
JComponent advancedSettings = null;
if (myProjectGenerator instanceof PythonProjectGenerator) {
advancedSettings = ((PythonProjectGenerator) myProjectGenerator).getSettingsPanel(myProjectDirectory);
} else if (myProjectGenerator instanceof WebProjectTemplate) {
advancedSettings = ((WebProjectTemplate) myProjectGenerator).getPeer().getComponent();
}
if (advancedSettings != null) {
final JPanel jPanel = new JPanel(new VerticalFlowLayout());
final HideableDecorator deco = new HideableDecorator(jPanel, "Mor&e Settings", false);
boolean isValid = checkValid();
deco.setOn(!isValid);
if (myProjectGenerator instanceof PythonProjectGenerator && !deco.isExpanded()) {
final ValidationResult result = ((PythonProjectGenerator) myProjectGenerator).warningValidation(getSdk());
deco.setOn(!result.isOk());
}
deco.setContentComponent(advancedSettings);
return jPanel;
}
return null;
}
use of com.jetbrains.python.newProject.PythonProjectGenerator in project intellij-community by JetBrains.
the class ProjectSpecificSettingsStep method createBasePanel.
@Override
protected JPanel createBasePanel() {
if (myProjectGenerator instanceof PythonProjectGenerator) {
final BorderLayout layout = new BorderLayout();
final JPanel locationPanel = new JPanel(layout);
final JPanel panel = new JPanel(new VerticalFlowLayout(0, 2));
final LabeledComponent<TextFieldWithBrowseButton> location = createLocationComponent();
locationPanel.add(location, BorderLayout.CENTER);
panel.add(locationPanel);
if (((PythonProjectGenerator) myProjectGenerator).hideInterpreter()) {
addInterpreterButton(locationPanel, location);
} else {
final LabeledComponent<PythonSdkChooserCombo> labeled = createInterpreterCombo();
UIUtil.mergeComponentsWithAnchor(labeled, location);
panel.add(labeled);
}
final PythonRemoteInterpreterManager remoteInterpreterManager = PythonRemoteInterpreterManager.getInstance();
final Sdk sdk = getSdk();
if (remoteInterpreterManager != null && sdk != null) {
createRemotePathField(panel, remoteInterpreterManager);
}
final JPanel basePanelExtension = ((PythonProjectGenerator) myProjectGenerator).extendBasePanel();
if (basePanelExtension != null) {
panel.add(basePanelExtension);
}
return panel;
}
return super.createBasePanel();
}
use of com.jetbrains.python.newProject.PythonProjectGenerator in project intellij-community by JetBrains.
the class ProjectSpecificSettingsStep method registerValidators.
@Override
protected void registerValidators() {
super.registerValidators();
if (myProjectGenerator instanceof PythonProjectGenerator && !((PythonProjectGenerator) myProjectGenerator).hideInterpreter()) {
myLocationField.getTextField().getDocument().addDocumentListener(new DocumentAdapter() {
@Override
protected void textChanged(DocumentEvent e) {
final String path = myLocationField.getText().trim();
((PythonProjectGenerator) myProjectGenerator).locationChanged(PathUtil.getFileName(path));
}
});
mySdkCombo.getComboBox().addItemListener(e -> {
if (e.getStateChange() == ItemEvent.SELECTED) {
final Runnable checkValidOnSwing = () -> ApplicationManager.getApplication().invokeLater(this::checkValid);
ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> {
try {
final Sdk sdk = getSdk();
if (sdk == null) {
return;
}
final boolean noPackages = PyPackageManager.getInstance(sdk).refreshAndGetPackages(true).isEmpty();
if (noPackages) {
LOGGER.warn(String.format("No packages on %s", sdk.getHomePath()));
}
checkValidOnSwing.run();
} catch (final ExecutionException exception) {
LOGGER.warn(exception);
checkValidOnSwing.run();
}
}, "Refreshing List of Packages, Please Wait", false, null);
}
});
UiNotifyConnector.doWhenFirstShown(mySdkCombo, this::checkValid);
}
}
use of com.jetbrains.python.newProject.PythonProjectGenerator in project intellij-community by JetBrains.
the class PythonGenerateProjectCallback method consume.
@Override
public void consume(@Nullable ProjectSettingsStepBase step) {
if (!(step instanceof ProjectSpecificSettingsStep))
return;
final ProjectSpecificSettingsStep settingsStep = (ProjectSpecificSettingsStep) step;
final DirectoryProjectGenerator generator = settingsStep.getProjectGenerator();
Sdk sdk = settingsStep.getSdk();
if (sdk instanceof PyDetectedSdk) {
sdk = addDetectedSdk(settingsStep, sdk);
}
if (generator instanceof PythonProjectGenerator) {
final BooleanFunction<PythonProjectGenerator> beforeProjectGenerated = ((PythonProjectGenerator) generator).beforeProjectGenerated(sdk);
if (beforeProjectGenerated != null) {
final boolean result = beforeProjectGenerated.fun((PythonProjectGenerator) generator);
if (!result) {
Messages.showWarningDialog("Project can not be generated", "Error in Project Generation");
return;
}
}
}
final Project newProject = generateProject(settingsStep);
if (generator instanceof PythonProjectGenerator && sdk == null && newProject != null) {
final PyNewProjectSettings settings = (PyNewProjectSettings) ((PythonProjectGenerator) generator).getProjectSettings();
((PythonProjectGenerator) generator).createAndAddVirtualEnv(newProject, settings);
sdk = settings.getSdk();
}
if (newProject != null && generator instanceof PythonProjectGenerator) {
SdkConfigurationUtil.setDirectoryProjectSdk(newProject, sdk);
final List<Sdk> sdks = PythonSdkType.getAllSdks();
for (Sdk s : sdks) {
final SdkAdditionalData additionalData = s.getSdkAdditionalData();
if (additionalData instanceof PythonSdkAdditionalData) {
((PythonSdkAdditionalData) additionalData).reassociateWithCreatedProject(newProject);
}
}
}
}
Aggregations