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