repl: Factor out ReplStore
(#14970)
This PR factors a `ReplStore` out of the `RuntimePanel`. Since we're planning to remove the `RuntimePanel` and replace it with an ephemeral tab that can be opened, we need the kernel specifications and sessions to have somewhere long-lived that they can reside in. Release Notes: - N/A
This commit is contained in:
parent
2e23527e09
commit
28baa56e3d
6 changed files with 264 additions and 185 deletions
|
@ -29,7 +29,7 @@ pub struct KernelSpecification {
|
|||
|
||||
impl KernelSpecification {
|
||||
#[must_use]
|
||||
fn command(&self, connection_path: &PathBuf) -> anyhow::Result<Command> {
|
||||
fn command(&self, connection_path: &PathBuf) -> Result<Command> {
|
||||
let argv = &self.kernelspec.argv;
|
||||
|
||||
anyhow::ensure!(!argv.is_empty(), "Empty argv in kernelspec {}", self.name);
|
||||
|
@ -60,7 +60,7 @@ impl KernelSpecification {
|
|||
|
||||
// Find a set of open ports. This creates a listener with port set to 0. The listener will be closed at the end when it goes out of scope.
|
||||
// There's a race condition between closing the ports and usage by a kernel, but it's inherent to the Jupyter protocol.
|
||||
async fn peek_ports(ip: IpAddr) -> anyhow::Result<[u16; 5]> {
|
||||
async fn peek_ports(ip: IpAddr) -> Result<[u16; 5]> {
|
||||
let mut addr_zeroport: SocketAddr = SocketAddr::new(ip, 0);
|
||||
addr_zeroport.set_port(0);
|
||||
let mut ports: [u16; 5] = [0; 5];
|
||||
|
@ -166,10 +166,10 @@ impl Kernel {
|
|||
|
||||
pub struct RunningKernel {
|
||||
pub process: smol::process::Child,
|
||||
_shell_task: Task<anyhow::Result<()>>,
|
||||
_iopub_task: Task<anyhow::Result<()>>,
|
||||
_control_task: Task<anyhow::Result<()>>,
|
||||
_routing_task: Task<anyhow::Result<()>>,
|
||||
_shell_task: Task<Result<()>>,
|
||||
_iopub_task: Task<Result<()>>,
|
||||
_control_task: Task<Result<()>>,
|
||||
_routing_task: Task<Result<()>>,
|
||||
connection_path: PathBuf,
|
||||
pub working_directory: PathBuf,
|
||||
pub request_tx: mpsc::Sender<JupyterMessage>,
|
||||
|
@ -194,7 +194,7 @@ impl RunningKernel {
|
|||
working_directory: PathBuf,
|
||||
fs: Arc<dyn Fs>,
|
||||
cx: &mut AppContext,
|
||||
) -> Task<anyhow::Result<(Self, JupyterMessageChannel)>> {
|
||||
) -> Task<Result<(Self, JupyterMessageChannel)>> {
|
||||
cx.spawn(|cx| async move {
|
||||
let ip = IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1));
|
||||
let ports = peek_ports(ip).await?;
|
||||
|
@ -332,7 +332,7 @@ async fn read_kernelspec_at(
|
|||
// /usr/local/share/jupyter/kernels/python3
|
||||
kernel_dir: PathBuf,
|
||||
fs: &dyn Fs,
|
||||
) -> anyhow::Result<KernelSpecification> {
|
||||
) -> Result<KernelSpecification> {
|
||||
let path = kernel_dir;
|
||||
let kernel_name = if let Some(kernel_name) = path.file_name() {
|
||||
kernel_name.to_string_lossy().to_string()
|
||||
|
@ -356,7 +356,7 @@ async fn read_kernelspec_at(
|
|||
}
|
||||
|
||||
/// Read a directory of kernelspec directories
|
||||
async fn read_kernels_dir(path: PathBuf, fs: &dyn Fs) -> anyhow::Result<Vec<KernelSpecification>> {
|
||||
async fn read_kernels_dir(path: PathBuf, fs: &dyn Fs) -> Result<Vec<KernelSpecification>> {
|
||||
let mut kernelspec_dirs = fs.read_dir(&path).await?;
|
||||
|
||||
let mut valid_kernelspecs = Vec::new();
|
||||
|
@ -376,7 +376,7 @@ async fn read_kernels_dir(path: PathBuf, fs: &dyn Fs) -> anyhow::Result<Vec<Kern
|
|||
Ok(valid_kernelspecs)
|
||||
}
|
||||
|
||||
pub async fn kernel_specifications(fs: Arc<dyn Fs>) -> anyhow::Result<Vec<KernelSpecification>> {
|
||||
pub async fn kernel_specifications(fs: Arc<dyn Fs>) -> Result<Vec<KernelSpecification>> {
|
||||
let data_dirs = dirs::data_dirs();
|
||||
let kernel_dirs = data_dirs
|
||||
.iter()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue