Search in sources :

Example 1 with PySkeletonRefresher

use of com.jetbrains.python.sdk.skeletons.PySkeletonRefresher in project intellij-community by JetBrains.

the class GenerateBinaryStubsFix method generateSkeletonsForList.

private boolean generateSkeletonsForList(@NotNull final PySkeletonRefresher refresher, ProgressIndicator indicator, @Nullable final String currentBinaryFilesPath) throws InvalidSdkException {
    final PySkeletonGenerator generator = new PySkeletonGenerator(refresher.getSkeletonsPath(), mySdk, currentBinaryFilesPath);
    indicator.setIndeterminate(false);
    final String homePath = mySdk.getHomePath();
    if (homePath == null)
        return false;
    GeneralCommandLine cmd = PythonHelper.EXTRA_SYSPATH.newCommandLine(homePath, Lists.newArrayList(myQualifiedName));
    final ProcessOutput runResult = PySdkUtil.getProcessOutput(cmd, new File(homePath).getParent(), PythonSdkType.getVirtualEnvExtraEnv(homePath), 5000);
    if (runResult.getExitCode() == 0 && !runResult.isTimeout()) {
        final String extraPath = runResult.getStdout();
        final PySkeletonGenerator.ListBinariesResult binaries = generator.listBinaries(mySdk, extraPath);
        final List<String> names = Lists.newArrayList(binaries.modules.keySet());
        Collections.sort(names);
        final int size = names.size();
        for (int i = 0; i != size; ++i) {
            final String name = names.get(i);
            indicator.setFraction((double) i / size);
            if (needBinaryList(name)) {
                indicator.setText2(name);
                final PySkeletonRefresher.PyBinaryItem item = binaries.modules.get(name);
                final String modulePath = item != null ? item.getPath() : "";
                //noinspection unchecked
                refresher.generateSkeleton(name, modulePath, new ArrayList<>(), Consumer.EMPTY_CONSUMER);
            }
        }
    }
    return true;
}
Also used : PySkeletonRefresher(com.jetbrains.python.sdk.skeletons.PySkeletonRefresher) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) ProcessOutput(com.intellij.execution.process.ProcessOutput) PySkeletonGenerator(com.jetbrains.python.sdk.skeletons.PySkeletonGenerator) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) File(java.io.File)

Example 2 with PySkeletonRefresher

use of com.jetbrains.python.sdk.skeletons.PySkeletonRefresher in project intellij-community by JetBrains.

the class GenerateBinaryStubsFix method getFixTask.

/**
   * Returns fix task that is used to generate stubs
   *
   * @param fileToRunTaskIn file where task should run
   * @return task itself
   */
@NotNull
public Backgroundable getFixTask(@NotNull final PsiFile fileToRunTaskIn) {
    final Project project = fileToRunTaskIn.getProject();
    final String folder = fileToRunTaskIn.getContainingDirectory().getVirtualFile().getCanonicalPath();
    return new Task.Backgroundable(project, "Generating skeletons for binary module", false) {

        @Override
        public void run(@NotNull ProgressIndicator indicator) {
            indicator.setIndeterminate(true);
            final List<String> assemblyRefs = new ReadAction<List<String>>() {

                @Override
                protected void run(@NotNull Result<List<String>> result) throws Throwable {
                    result.setResult(collectAssemblyReferences(fileToRunTaskIn));
                }
            }.execute().getResultObject();
            try {
                final PySkeletonRefresher refresher = new PySkeletonRefresher(project, null, mySdk, null, null, folder);
                if (needBinaryList(myQualifiedName)) {
                    if (!generateSkeletonsForList(refresher, indicator, folder))
                        return;
                } else {
                    //noinspection unchecked
                    refresher.generateSkeleton(myQualifiedName, "", assemblyRefs, Consumer.EMPTY_CONSUMER);
                }
                final VirtualFile skeletonDir;
                skeletonDir = LocalFileSystem.getInstance().findFileByPath(refresher.getSkeletonsPath());
                if (skeletonDir != null) {
                    skeletonDir.refresh(true, true);
                }
            } catch (InvalidSdkException e) {
                LOG.error(e);
            }
        }
    };
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) PySkeletonRefresher(com.jetbrains.python.sdk.skeletons.PySkeletonRefresher) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ReadAction(com.intellij.openapi.application.ReadAction) Backgroundable(com.intellij.openapi.progress.Task.Backgroundable) InvalidSdkException(com.jetbrains.python.sdk.InvalidSdkException) NotNull(org.jetbrains.annotations.NotNull) Result(com.intellij.openapi.application.Result) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 PySkeletonRefresher (com.jetbrains.python.sdk.skeletons.PySkeletonRefresher)2 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)1 ProcessOutput (com.intellij.execution.process.ProcessOutput)1 ReadAction (com.intellij.openapi.application.ReadAction)1 Result (com.intellij.openapi.application.Result)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 Backgroundable (com.intellij.openapi.progress.Task.Backgroundable)1 Project (com.intellij.openapi.project.Project)1 PsiFile (com.intellij.psi.PsiFile)1 InvalidSdkException (com.jetbrains.python.sdk.InvalidSdkException)1 PySkeletonGenerator (com.jetbrains.python.sdk.skeletons.PySkeletonGenerator)1 File (java.io.File)1 NotNull (org.jetbrains.annotations.NotNull)1