private static @NotNull Future<Void> installFrameworkIfNeeded(final @NotNull Project project,
                                                                final @NotNull String frameworkName,
                                                                final @NotNull String requirement,
                                                                final @Nullable Sdk sdk,
                                                                final boolean forceInstallFramework,
                                                                boolean asBackgroundTask,
                                                                final @Nullable Runnable callback) {

    var future = new CompletableFuture<Void>();
    if (sdk == null) {
      reportPackageInstallationFailure(frameworkName, null);
      future.completeExceptionally(new RuntimeException(("No SDK provided")));
      return future;
    }

    // For remote SDK we are not sure if framework exists or not, so we'll check it anyway
    if (forceInstallFramework || PythonSdkUtil.isRemote(sdk)) {

      if (asBackgroundTask) {
        ProgressManager.getInstance()
          .run(new Task.Backgroundable(project, PyBundle.message("python.install.framework.ensure.installed", frameworkName), false) {
            @Override
            public void run(final @NotNull ProgressIndicator indicator) {
              installPackages(frameworkName, forceInstallFramework, indicator, requirement, sdk);
            }

            @Override
            public void onThrowable(@NotNull Throwable error) {
              future.completeExceptionally(error);
            }

            @Override
            public void onSuccess() {
              future.complete(null);
              // Installed / checked successfully, call callback on AWT
              if (callback != null) {
                callback.run();
              }
            }
          });
      }
      else {
        ProgressManager.getInstance()
          .run(new Task.Modal(project, PyBundle.message("python.install.framework.ensure.installed", frameworkName), false) {
            @Override
            public void run(final @NotNull ProgressIndicator indicator) {
              installPackages(frameworkName, forceInstallFramework, indicator, requirement, sdk);
            }

            @Override
            public void onThrowable(@NotNull Throwable error) {
              future.completeExceptionally(error);
            }

            @Override
            public void onSuccess() {
              future.complete(null);
              // Installed / checked successfully, call callback on AWT
              if (callback != null) {
                callback.run();
              }
            }
          });
      }
    }
    else {
      future.complete(null);
      // No need to install, but still need to call callback on AWT
      if (callback != null) {
        assert SwingUtilities.isEventDispatchThread();
        callback.run();
      }
    }
    return future;
  }
private static @NotNull Future<Void> installFrameworkIfNeeded(final @NotNull Project project,
                                                                final @NotNull String frameworkName,
                                                                final @NotNull String requirement,
                                                                final @Nullable Sdk sdk,
                                                                final boolean forceInstallFramework,
                                                                boolean asBackgroundTask,
                                                                final @Nullable Runnable callback)