Merge branch 'refactor-package-manager'
authorAndrey Vlasovskikh <andrey.vlasovskikh@jetbrains.com>
Fri, 12 Sep 2014 13:03:52 +0000 (17:03 +0400)
committerAndrey Vlasovskikh <andrey.vlasovskikh@jetbrains.com>
Fri, 12 Sep 2014 13:03:52 +0000 (17:03 +0400)
1  2 
python/ide/src/com/jetbrains/python/newProject/actions/AbstractProjectSettingsStep.java

index 7b1015f01c74b0d6ae00cd2cd10befa113379353,9e214aeb8be3f09cba62dcd24320285a85c263f0..6514741fda4528f840a65ff9034c465aa002b683
@@@ -33,16 -33,10 +33,11 @@@ import com.jetbrains.python.configurati
  import com.jetbrains.python.configuration.VirtualEnvProjectFilter;
  import com.jetbrains.python.newProject.PyFrameworkProjectGenerator;
  import com.jetbrains.python.newProject.PythonProjectGenerator;
- import com.jetbrains.python.packaging.PyExternalProcessException;
- import com.jetbrains.python.packaging.PyPackage;
  import com.jetbrains.python.packaging.PyPackageManager;
- import com.jetbrains.python.packaging.PyPackageManagerImpl;
+ import com.jetbrains.python.sdk.PySdkUtil;
  import com.jetbrains.python.sdk.PythonSdkType;
- import com.jetbrains.python.sdk.flavors.JythonSdkFlavor;
- import com.jetbrains.python.sdk.flavors.PyPySdkFlavor;
- import com.jetbrains.python.sdk.flavors.PythonSdkFlavor;
  import icons.PythonIcons;
 +import org.jetbrains.annotations.NotNull;
  import org.jetbrains.annotations.Nullable;
  
  import javax.swing.*;
@@@ -80,6 -74,22 +75,6 @@@ abstract public class AbstractProjectSe
      myCallback = callback;
      myIsWelcomeScreen = isWelcomeScreen;
      myProjectDirectory = FileUtil.findSequentNonexistentFile(new File(ProjectUtil.getBaseDir()), "untitled", "");
 -    if (myProjectGenerator instanceof WebProjectTemplate) {
 -      ((WebProjectTemplate)myProjectGenerator).getPeer().addSettingsStateListener(new WebProjectGenerator.SettingsStateListener() {
 -        @Override
 -        public void stateChanged(boolean validSettings) {
 -          checkValid();
 -        }
 -      });
 -    }
 -    else if (myProjectGenerator instanceof PythonProjectGenerator) {
 -      ((PythonProjectGenerator)myProjectGenerator).addSettingsStateListener(new PythonProjectGenerator.SettingsListener() {
 -        @Override
 -        public void stateChanged() {
 -          checkValid();
 -        }
 -      });
 -    }
  
      myCreateAction = new AnAction("Create", "Create Project", getIcon()) {
        @Override
  
    @Override
    public JPanel createPanel() {
 +    initGeneratorListeners();
      final JPanel basePanel = createBasePanel();
      final JPanel mainPanel = new JPanel(new BorderLayout());
  
      return mainPanel;
    }
  
 +  private void initGeneratorListeners() {
 +    if (myProjectGenerator instanceof WebProjectTemplate) {
 +      ((WebProjectTemplate)myProjectGenerator).getPeer().addSettingsStateListener(new WebProjectGenerator.SettingsStateListener() {
 +        @Override
 +        public void stateChanged(boolean validSettings) {
 +          checkValid();
 +        }
 +      });
 +    }
 +    else if (myProjectGenerator instanceof PythonProjectGenerator) {
 +      ((PythonProjectGenerator)myProjectGenerator).addSettingsStateListener(new PythonProjectGenerator.SettingsListener() {
 +        @Override
 +        public void stateChanged() {
 +          checkValid();
 +        }
 +      });
 +    }
 +  }
 +
    protected Icon getIcon() {
      return myProjectGenerator.getLogo();
    }
        PyFrameworkProjectGenerator frameworkProjectGenerator = (PyFrameworkProjectGenerator)myProjectGenerator;
        String frameworkName = frameworkProjectGenerator.getFrameworkTitle();
        if (sdk != null && !isFrameworkInstalled(sdk)) {
-         final PyPackageManagerImpl packageManager = (PyPackageManagerImpl)PyPackageManager.getInstance(sdk);
-         final boolean onlyWithCache =
-           PythonSdkFlavor.getFlavor(sdk) instanceof JythonSdkFlavor || PythonSdkFlavor.getFlavor(sdk) instanceof PyPySdkFlavor;
          String warningText = frameworkName + " will be installed on selected interpreter";
-         try {
-           if (onlyWithCache && packageManager.cacheIsNotNull() || !onlyWithCache) {
-             final PyPackage pip = packageManager.findInstalledPackage("pip");
-             myInstallFramework = true;
-             if (pip == null) {
-               warningText = "pip and " + warningText;
-             }
-             setWarningText(warningText);
-           }
-         }
-         catch (PyExternalProcessException ignored) {
-           myInstallFramework = true;
-           warningText = "pip and " + warningText;
-           setWarningText(warningText);
-         }
-         if (!myInstallFramework) {
-           setErrorText("No " + frameworkName + " support installed in selected interpreter");
-           return false;
+         myInstallFramework = true;
+         final PyPackageManager packageManager = PyPackageManager.getInstance(sdk);
+         if (!packageManager.hasManagement(PySdkUtil.isRemote(sdk))) {
+           warningText = "Python packaging tools and " + warningText;
          }
+         setWarningText(warningText);
        }
        if (isPy3k && !((PyFrameworkProjectGenerator)myProjectGenerator).supportsPython3()) {
          setErrorText(frameworkName + " is not supported for the selected interpreter");
      return myLocationField.getText();
    }
  
 +  public void setLocation(@NotNull final String location) {
 +    myLocationField.setText(location);
 +  }
 +
    public boolean installFramework() {
      return myInstallFramework;
    }