in src/org/jetbrains/plugins/ipnb/editor/actions/IpnbConvertToPythonAction.java [79:119]
private static void convertToPythonScript(@NotNull final Project project,
@NotNull final VirtualFile virtualFile) {
Module module = ProjectFileIndex.SERVICE.getInstance(project).getModuleForFile(virtualFile);
if (module == null) return;
final Sdk sdk = PythonSdkType.findPythonSdk(module);
if (sdk == null || PythonSdkType.isInvalid(sdk)) {
return;
}
final String homePath = sdk.getHomePath();
if (homePath == null) {
return;
}
final ArrayList<String> parameters = Lists.newArrayList(homePath);
addJupyterRunner(homePath, parameters);
parameters.add("--to");
parameters.add("script");
parameters.add(virtualFile.getPath());
final String baseDir = virtualFile.getParent().getPath();
final GeneralCommandLine commandLine = new GeneralCommandLine(parameters).withWorkDirectory(baseDir);
try {
final KillableColoredProcessHandler processHandler = new KillableColoredProcessHandler(commandLine);
processHandler.addProcessListener(new ProcessAdapter() {
@Override
public void processTerminated(@NotNull ProcessEvent event) {
VfsUtil.markDirtyAndRefresh(true, false, true, virtualFile.getParent());
}
});
processHandler.setShouldDestroyProcessRecursively(true);
GuiUtils.invokeLaterIfNeeded(() -> {
final RunContentExecutor executor = new RunContentExecutor(project, processHandler);
executor.withActivateToolWindow(false);
executor.run();
}, ModalityState.defaultModalityState());
}
catch (ExecutionException ignored) {
}
}