Unverified Commit de26873b authored by OTABI Tomoya's avatar OTABI Tomoya Committed by GitHub
Browse files

Merge pull request #245340 from codedownio/jupyter-console

jupyter-console: expose as a tool for launching kernels
parents e32ca67a 0342a519
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -8,8 +8,11 @@
, imagemagick
}:

# To test:
# $(nix-build --no-out-link -E 'with import <nixpkgs> {}; jupyter.override { definitions = { clojure = clojupyter.definition; }; }')/bin/jupyter-notebook
# Jupyter console:
# nix run --impure --expr 'with import <nixpkgs> {}; jupyter-console.withSingleKernel clojupyter.definition'

# Jupyter notebook:
# nix run --impure --expr 'with import <nixpkgs> {}; jupyter.override { definitions.clojure = clojupyter.definition; }'

let
  cljdeps = import ./deps.nix { inherit pkgs; };
+36 −11
Original line number Diff line number Diff line
@@ -2,16 +2,41 @@
, bundlerApp
}:

bundlerApp {
# Jupyter console:
# nix run --impure --expr 'with import <nixpkgs> {}; jupyter-console.withSingleKernel iruby.definition'

# Jupyter notebook:
# nix run --impure --expr 'with import <nixpkgs> {}; jupyter.override { definitions.iruby = iruby.definition; }'

let
  self = bundlerApp {
    pname = "iruby";
    gemdir = ./.;
    exes = [ "iruby" ];

  meta = with lib; {
    passthru = {
      definition = {
        displayName = "IRuby";
        argv = [
          "${self}/bin/iruby"
          "kernel"
          "{connection_file}"
        ];
        language = "ruby";
        logo32 = null;
        logo64 = null;
      };
    };

    meta = {
      description = "Ruby kernel for Jupyter";
      homepage    = "https://github.com/SciRuby/iruby";
    license     = licenses.mit;
    maintainers = [ maintainers.costrouc ];
    platforms   = platforms.unix;
      license     = lib.licenses.mit;
      maintainers = with lib.maintainers; [ costrouc thomasjm ];
      platforms   = lib.platforms.unix;
    };
  };
}

in

self
+5 −2
Original line number Diff line number Diff line
@@ -7,8 +7,11 @@
, python3
}:

# To test:
# $(nix-build -E 'with import <nixpkgs> {}; jupyter.override { definitions = { octave = octave-kernel.definition; }; }')/bin/jupyter-notebook
# Jupyter console:
# nix run --impure --expr 'with import <nixpkgs> {}; jupyter-console.withSingleKernel octave-kernel.definition'

# Jupyter notebook:
# nix run --impure --expr 'with import <nixpkgs> {}; jupyter.override { definitions.octave = octave-kernel.definition; }'

let
  kernel = callPackage ./kernel.nix {
+6 −2
Original line number Diff line number Diff line
@@ -2,8 +2,12 @@
, wolfram-engine
}:

# To test:
# $(nix-build -E 'with import ./. {}; jupyter.override { definitions = { wolfram = wolfram-for-jupyter-kernel.definition; }; }')/bin/jupyter-notebook
# Jupyter console:
# nix run --impure --expr 'with import <nixpkgs> {}; jupyter-console.withSingleKernel wolfram-for-jupyter-kernel.definition'

# Jupyter notebook:
# nix run --impure --expr 'with import <nixpkgs> {}; jupyter.override { definitions.wolfram = wolfram-for-jupyter-kernel.definition; }'

let kernel = callPackage ./kernel.nix {};
in {
  definition = {
+37 −0
Original line number Diff line number Diff line
{ python3
, jupyter-kernel
, lib
}:

let
  mkConsole = {
    definitions ? jupyter-kernel.default
    , kernel ? null
  }:
    (python3.buildEnv.override {
      extraLibs = [ python3.pkgs.jupyter-console ];
      makeWrapperArgs = [
        "--set JUPYTER_PATH ${jupyter-kernel.create { inherit definitions; }}"
      ] ++ lib.optionals (kernel != null) [
        "--add-flags --kernel"
        "--add-flags ${kernel}"
      ];
    }).overrideAttrs (oldAttrs: {
      # To facilitate running nix run .#jupyter-console
      meta = oldAttrs.meta // { mainProgram = "jupyter-console"; };
    });

in

{
  # Build a console derivation with an arbitrary set of definitions, and an optional kernel to use.
  # If the kernel argument is not supplied, Jupyter console will pick a kernel to run from the ones
  # available on the system.
  inherit mkConsole;

  # An ergonomic way to start a console with a single kernel.
  withSingleKernel = definition: mkConsole {
    definitions = lib.listToAttrs [(lib.nameValuePair definition.language definition)];
    kernel = definition.language;
  };
}
Loading