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 da28e53
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 22 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
25 changes: 14 additions & 11 deletions modules/poetry.nix
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
self,
system,
kernelModuleDir,
extraKernelSpc,
}: let
allRuntimePackages = requiredRuntimePackages ++ runtimePackages;

Expand All @@ -48,17 +49,19 @@
--set PATH "${pkgs.lib.makeSearchPath "bin" allRuntimePackages}"
done
'';
in {
inherit name codemirrorMode displayName language;
argv = [
"${wrappedEnv}/bin/python"
"-m"
"${argvKernelName}"
"-f"
"{connection_file}"
];
logo64 = kernelModuleDir + "/logo-64x64.png";
};
in
{
inherit name codemirrorMode displayName language;
argv = [
"${wrappedEnv}/bin/python"
"-m"
"${argvKernelName}"
"-f"
"{connection_file}"
];
logo64 = kernelModuleDir + "/logo-64x64.png";
}
// extraKernelSpc;
in {
options =
import ./types/poetry.nix {inherit self lib config argvKernelName codemirrorMode kernelName language;}
Expand Down

0 comments on commit da28e53

Please sign in to comment.