Skip to content

Commit

Permalink
feat(kernelArgs): add extraKernelSpc for extending the spc
Browse files Browse the repository at this point in the history
solve #483, and enable the debugger by default
  • Loading branch information
GTrunSec committed Nov 4, 2023
1 parent 33528df commit 254b281
Show file tree
Hide file tree
Showing 14 changed files with 243 additions and 143 deletions.
2 changes: 2 additions & 0 deletions examples/python/science/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ in {
ps.ipykernel
ps.scipy
ps.matplotlib
# required for debugging mode
ps.debugpy
]);
# extraPackages = ps: [
# ps.numpy
Expand Down
74 changes: 63 additions & 11 deletions examples/python/science/test.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"id": "d13cad64-62c0-4b87-b8ef-0242658baa0f",
"metadata": {},
"outputs": [],
Expand All @@ -14,39 +14,63 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"id": "16f8a525-ab66-407d-b978-78af1ee27a4d",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[0 1 2 3 4]\n"
]
}
],
"source": [
"x = np.arange(5)\n",
"print(x)"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"id": "97728667-fbc5-4e71-a3b7-52f174309b92",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[ 0.5 2.5 6.5 12.5]\n"
]
}
],
"source": [
"y_new = sp.interpolate.interp1d(x, x ** 2)(x[:-1] + 0.5)\n",
"print(y_new)"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"id": "d03e077a-add4-472f-afba-0c1f17e0159a",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(0.122312, 0.633153, 0.530398, 1.0)\n"
]
}
],
"source": [
"print(mpl.colormaps['viridis'].resampled(8)(0.56))"
]
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 5,
"id": "8c6a4d24-3349-425e-9983-f9b691fd570b",
"metadata": {},
"outputs": [],
Expand All @@ -56,13 +80,41 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"id": "89975008-53c5-457d-a67f-7554f9ef037e",
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"<Popen: returncode: None args: ['ls']>"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"default.nix\n",
"test.ipynb\n",
"test.py\n"
]
}
],
"source": [
"subprocess.Popen(['ls'],shell=True])"
"subprocess.Popen(['ls'],shell=True)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "73f92448-4134-492d-97c2-1a2f8947d28b",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
13 changes: 13 additions & 0 deletions modules/kernel.nix
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@ in {
internal = true;
};

extraKernelSpc = lib.mkOption {
default = {
metadata = {
debugger = true;
};
};
type = types.attrs;
description = lib.mdDoc ''
Extra kernel spec attributes.
'';
};

build = lib.mkOption {
type = types.package;
internal = true;
Expand All @@ -79,6 +91,7 @@ in {
displayName
requiredRuntimePackages
runtimePackages
extraKernelSpc
;
pkgs = config.nixpkgs;
};
Expand Down
23 changes: 13 additions & 10 deletions modules/kernels/go/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
requiredRuntimePackages ? with pkgs; [go],
runtimePackages ? [],
gophernotes ? pkgs.gophernotes,
extraKernelSpc,
}: let
inherit (pkgs) lib stdenv writeScriptBin;

Expand All @@ -50,16 +51,18 @@
--set PATH "${pkgs.lib.makeSearchPath "bin" allRuntimePackages}"
done
'';
in {
inherit name displayName;
language = "go";
argv = [
"${wrappedEnv}/bin/gophernotes"
"{connection_file}"
];
codemirrorMode = "go";
logo64 = ./logo-64x64.png;
};
in
{
inherit name displayName;
language = "go";
argv = [
"${wrappedEnv}/bin/gophernotes"
"{connection_file}"
];
codemirrorMode = "go";
logo64 = ./logo-64x64.png;
}
// extraKernelSpc;
in {
options =
{}
Expand Down
19 changes: 11 additions & 8 deletions modules/kernels/haskell/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
haskellCompiler,
extraHaskellFlags ? "-M3g -N2",
extraHaskellPackages ? (_: []),
extraKernelSpc,
}: let
allRuntimePackages = requiredRuntimePackages ++ runtimePackages;

Expand Down Expand Up @@ -58,14 +59,16 @@
env.ihaskellKernelFileFunc
wrappedEnv
extraHaskellFlags;
in {
inherit name displayName;
language = "haskell";
# See https://github.com/IHaskell/IHaskell/pull/1191
argv = kernelspec.argv ++ ["--codemirror" "Haskell"];
codemirrorMode = "Haskell";
logo64 = ./logo-64x64.png;
};
in
{
inherit name displayName;
language = "haskell";
# See https://github.com/IHaskell/IHaskell/pull/1191
argv = kernelspec.argv ++ ["--codemirror" "Haskell"];
codemirrorMode = "Haskell";
logo64 = ./logo-64x64.png;
}
// extraKernelSpc;
in {
options =
{
Expand Down
23 changes: 13 additions & 10 deletions modules/kernels/javascript/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
displayName ? "Javascript",
requiredRuntimePackages ? [],
runtimePackages ? [],
extraKernelSpc,
ijavascript ? pkgs.nodePackages.ijavascript,
}: let
inherit (pkgs) lib stdenv writeScriptBin;
Expand Down Expand Up @@ -56,16 +57,18 @@
--set PATH "${pkgs.lib.makeSearchPath "bin" allRuntimePackages}"
done
'';
in {
inherit name displayName;
language = "javascript";
argv = [
"${wrappedEnv}/bin/ijavascript"
"{connection_file}"
];
codemirrorMode = "javascript";
logo64 = ./logo-64x64.png;
};
in
{
inherit name displayName;
language = "javascript";
argv = [
"${wrappedEnv}/bin/ijavascript"
"{connection_file}"
];
codemirrorMode = "javascript";
logo64 = ./logo-64x64.png;
}
// extraKernelSpc;
in {
options =
{}
Expand Down
31 changes: 17 additions & 14 deletions modules/kernels/julia/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
ijuliaRev ? "Vo51o",
extraJuliaPackages ? [],
override ? {},
extraKernelSpc,
}: let
inherit (pkgs) writeText;
inherit (pkgs.lib) optionalString;
Expand All @@ -52,20 +53,22 @@
--set PATH "${pkgs.lib.makeSearchPath "bin" allRuntimePackages}"
done
'';
in {
inherit name displayName;
language = "julia";
argv = [
"${wrappedEnv}/bin/julia"
"-i"
"--startup-file=yes"
"--color=yes"
"${env.projectAndDepot}/depot/packages/IJulia/${ijuliaRev}/src/kernel.jl"
"{connection_file}"
];
codemirrorMode = "julia";
logo64 = ./logo-64x64.png;
};
in
{
inherit name displayName;
language = "julia";
argv = [
"${wrappedEnv}/bin/julia"
"-i"
"--startup-file=yes"
"--color=yes"
"${env.projectAndDepot}/depot/packages/IJulia/${ijuliaRev}/src/kernel.jl"
"{connection_file}"
];
codemirrorMode = "julia";
logo64 = ./logo-64x64.png;
}
// extraKernelSpc;
in {
options =
{
Expand Down
29 changes: 16 additions & 13 deletions modules/kernels/nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
displayName ? "Nix",
requiredRuntimePackages ? [],
runtimePackages ? [],
extraKernelSpc,
nix ? pkgs.nix,
}: let
allRuntimePackages =
Expand All @@ -49,19 +50,21 @@
--set NIX_PATH "nixpkgs=${pkgs.path}"
done
'';
in {
inherit name displayName;
language = "nix";
argv = [
"${wrappedEnv}/bin/python"
"-m"
"nix-kernel"
"-f"
"{connection_file}"
];
codemirrorMode = "nix";
logo64 = ./logo-64x64.png;
};
in
{
inherit name displayName;
language = "nix";
argv = [
"${wrappedEnv}/bin/python"
"-m"
"nix-kernel"
"-f"
"{connection_file}"
];
codemirrorMode = "nix";
logo64 = ./logo-64x64.png;
}
// extraKernelSpc;
in {
options =
{
Expand Down
Loading

0 comments on commit 254b281

Please sign in to comment.