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;
}
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);
}
}
};
}
Aggregations