public void checkConfiguration()

in src/org/jetbrains/plugins/ipnb/run/IpnbRunConfiguration.java [90:141]


  public void checkConfiguration() throws RuntimeConfigurationException {
    super.checkConfiguration();
    final Module module = getConfigurationModule().getModule();
    if (module == null) {
      throw new RuntimeConfigurationError("Please select Python module");
    }
    if (StringUtil.isEmptyOrSpaces(getHost())) {
      throw new RuntimeConfigurationError("Please select valid host");
    }
    if (StringUtil.isEmptyOrSpaces(getPort())) {
      throw new RuntimeConfigurationError("Please select valid port");
    }
    final Sdk sdk = getSdk();
    if (sdk == null) return;
    if (RemoteSdkCredentialsHolder.isRemoteSdk(sdk.getHomePath())) {
      throw new RuntimeConfigurationError("Please select local python interpreter");
    }
    final PyPackageManager packageManager = PyPackageManager.getInstance(sdk);
    final List<PyPackage> packages = packageManager.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) {
      throw new RuntimeConfigurationError("Install Jupyter Notebook to the interpreter of the current project.",
                                          () -> ProgressManager.getInstance().run(new Task.Backgroundable(getProject(),
                                                                                                          "Installing Jupyter", false) {
                                            @Override
                                            public void run(@NotNull ProgressIndicator indicator) {
                                              try {
                                                final String version = sdk.getVersionString();
                                                if (version != null) {
                                                  final LanguageLevel level = LanguageLevel.fromPythonVersion(version);
                                                  if (level.isAtLeast(LanguageLevel.PYTHON33)) {
                                                    packageManager.install("jupyter");
                                                  }
                                                  else {
                                                    packageManager.install(
                                                      Arrays.asList(
                                                        pyRequirement("ipython", PyRequirementRelation.EQ, "5"),
                                                        pyRequirement("jupyter")
                                                      ),
                                                      Collections.emptyList()
                                                    );
                                                  }
                                                }
                                              }
                                              catch (ExecutionException ignored) { }
                                            }
                                          }));
    }
  }