UNPKG

@nteract/fs-kernels

Version:

A manager for the filesystem aspects of Juyter kernels

79 lines (78 loc) 3.21 kB
/** * This module contains methods that allow you to launch ("spawn") Jupyter * kernels. You can spawn kernels either by name, by a `kernelSpec` or * by a `kernelSpec` and its connection information. * * Usage example: * ```js * // Spawn a kernel by name * var spawnResults = require('spawnteract').launch('python3'); * * // Print the ip address and port for the shell channel * console.log(spawnResults.config.ip + ':' + spawnResults.config.shell_port); * ``` * * You'll need to close `spawnResults.spawn` yourself as well as delete * `spawnResults.connectionFile` from disk when finished. * */ /// <reference types="node" /> /** * */ import fs from "fs"; import execa, { Options } from "execa"; import { KernelResourceByName, KernelSpec } from "./kernelspecs"; import { Channels } from "@nteract/messaging"; import { JupyterConnectionInfo } from "enchannel-zmq-backend"; export declare function cleanup(connectionFile: fs.PathLike): void; export interface PortFinderOptions { host: string; port: number; } /** * Launch a kernel for a given kernelSpec * @public * @param kernelSpec describes a specific kernel * @param [spawnOptions] `child_process`-like {@link https://github.com/sindresorhus/execa#options options for execa} * use `{ cleanupConnectionFile: false }` to disable automatic connection file cleanup */ export declare function launchSpec(kernelSpec: KernelSpec, spawnOptions?: Options): Promise<LaunchedKernel>; export interface LaunchedKernel { spawn: execa.ExecaChildProcess; connectionFile: string; config: JupyterConnectionInfo; kernelSpec: KernelSpec; channels: Channels; } /** * Launch a kernel for a given kernelSpec and connection info * @public * @param kernelSpec describes a specific kernel, see the npm package * `kernelspecs` * @param config connection config * @param connectionFile path to the config file * @param [spawnOptions] `child_process`-like options for * [execa]{@link https://github.com/sindresorhus/execa#options} * use `{ cleanupConnectionFile: false }` to disable * automatic connection file cleanup * * @return spawnResults * @return spawnResults.spawn spawned process * @return spawnResults.connectionFile connection file path * @return spawnResults.config connection info * */ export declare function launchSpecFromConnectionInfo(kernelSpec: KernelSpec, config: JupyterConnectionInfo, connectionFile: string, spawnOptions?: Options): Promise<LaunchedKernel>; /** * Launch a kernel by name * @public * @param kernelName * @param [specs] array of kernelSpec objects to look through. * See the npm package `kernelspecs` * @param [spawnOptions] `child_process`-like options for * [execa]{@link https://github.com/sindresorhus/execa#options} * use `{ cleanupConnectionFile: false }` to disable * automatic connection file cleanup */ export declare function launch(kernelName: string, spawnOptions?: Options, specs?: KernelResourceByName): Promise<LaunchedKernel>;