Repository: denoland/deno
File: cli/tools/jupyter/install.rs (Rust)

Code before:
// Copyright 2018-2025 the Deno authors. MIT license.

use std::env::current_exe;
use std::io::Write;
use std::path::Path;
use std::path::PathBuf;

use deno_core::anyhow::bail;
use deno_core::anyhow::Context;
use deno_core::error::AnyError;
use deno_core::serde_json;
use deno_core::serde_json::json;

static TEST_ENV_VAR_NAME: &str = "DENO_TEST_JUPYTER_PATH";

const DENO_ICON_32: &[u8] = include_bytes!("./resources/deno-logo-32x32.png");
const DENO_ICON_64: &[u8] = include_bytes!("./resources/deno-logo-64x64.png");
const DENO_ICON_SVG: &[u8] = include_bytes!("./resources/deno-logo-svg.svg");

pub fn status(maybe_name: Option<&str>) -> Result<(), AnyError> {
  let user_data_dir = if let Ok(env_var) = std::env::var(TEST_ENV_VAR_NAME) {
    PathBuf::from(env_var)
  } else {
    jupyter_runtime::dirs::user_data_dir()?
  };

  let kernel_name = maybe_name.unwrap_or("deno");
  let kernel_spec_dir_path = user_data_dir.join("kernels").join(kernel_name);
  let kernel_spec_path = kernel_spec_dir_path.join("kernel.json");

  if kernel_spec_path.exists() {
    log::info!(
      "✅ Deno kernel already installed at {}",
      kernel_spec_dir_path.display()
    );
    Ok(())
  } else {
    let mut install_cmd = "deno jupyter --install".to_string();
    if let Some(name) = maybe_name {
      install_cmd.push_str(" --name ");
      install_cmd.push_str(name);
    }
    log::warn!(
      "ℹ️ Deno kernel is not yet installed, run `{}` to set it up",
      install_cmd
    );
    Ok(())

Review comment (suggestion):
```suggestion
  let user_data_dir = if let Some(env_var) = std::env::var_os(TEST_ENV_VAR_NAME) {
    PathBuf::from(env_var)
```

Code after:
// Copyright 2018-2025 the Deno authors. MIT license.

use std::env::current_exe;
use std::io::Write;
use std::path::Path;
use std::path::PathBuf;

use deno_core::anyhow::bail;
use deno_core::anyhow::Context;
use deno_core::error::AnyError;
use deno_core::serde_json;
use deno_core::serde_json::json;

static TEST_ENV_VAR_NAME: &str = "DENO_TEST_JUPYTER_PATH";

const DENO_ICON_32: &[u8] = include_bytes!("./resources/deno-logo-32x32.png");
const DENO_ICON_64: &[u8] = include_bytes!("./resources/deno-logo-64x64.png");
const DENO_ICON_SVG: &[u8] = include_bytes!("./resources/deno-logo-svg.svg");

fn get_user_data_dir() -> Result<PathBuf, AnyError> {
  Ok(if let Some(env_var) = std::env::var_os(TEST_ENV_VAR_NAME) {
    PathBuf::from(env_var)
  } else {
    jupyter_runtime::dirs::user_data_dir()?
  })
}

pub fn status(maybe_name: Option<&str>) -> Result<(), AnyError> {
  let user_data_dir = get_user_data_dir()?;

  let kernel_name = maybe_name.unwrap_or("deno");
  let kernel_spec_dir_path = user_data_dir.join("kernels").join(kernel_name);
  let kernel_spec_path = kernel_spec_dir_path.join("kernel.json");

  if kernel_spec_path.exists() {
    log::info!(
      "✅ Deno kernel already installed at {}",
      kernel_spec_dir_path.display()
    );
    Ok(())
  } else {
    let mut install_cmd = "deno jupyter --install".to_string();
    if let Some(name) = maybe_name {
      install_cmd.push_str(" --name ");
      install_cmd.push_str(name);
    }
    log::warn!(