1{
2 lib,
3 buildPythonPackage,
4 fetchPypi,
5 flit-core,
6 ipykernel,
7 python,
8 pexpect,
9 bashInteractive,
10 substituteAll,
11}:
12
13buildPythonPackage rec {
14 pname = "bash-kernel";
15 version = "0.9.3";
16 pyproject = true;
17
18 src = fetchPypi {
19 pname = "bash_kernel";
20 inherit version;
21 hash = "sha256-n3oDgRyn2csfv/gIIjfPBFC5cYIlL9C4BYeha2XmbVg=";
22 };
23
24 patches = [
25 (substituteAll {
26 src = ./bash-path.patch;
27 bash = lib.getExe bashInteractive;
28 })
29 ];
30
31 nativeBuildInputs = [ flit-core ];
32
33 propagatedBuildInputs = [
34 ipykernel
35 pexpect
36 ];
37
38 preBuild = ''
39 export HOME=$TMPDIR
40 '';
41
42 postInstall = ''
43 ${python.pythonOnBuildForHost.interpreter} -m bash_kernel.install --prefix $out
44 '';
45
46 checkPhase = ''
47 runHook preCheck
48
49 # Create a JUPYTER_PATH with the kernelspec
50 export JUPYTER_PATH=$(mktemp -d)
51 mkdir -p $JUPYTER_PATH/kernels/bash
52 echo '{ "language": "bash", "argv": [ "${python}/bin/python", "-m", "bash_kernel", "-f", "{connection_file}" ] }' > $JUPYTER_PATH/kernels/bash/kernel.json
53
54 # Evaluate a test notebook with papermill
55 cd $(mktemp -d)
56 ${python.withPackages (ps: [ ps.papermill ])}/bin/papermill --kernel bash ${./test.ipynb} out.ipynb
57
58 runHook postCheck
59 '';
60
61 meta = with lib; {
62 description = "Bash Kernel for Jupyter";
63 homepage = "https://github.com/takluyver/bash_kernel";
64 changelog = "https://github.com/takluyver/bash_kernel/releases/tag/${version}";
65 license = licenses.bsd3;
66 maintainers = with maintainers; [ zimbatm ];
67 };
68}