Skip to content

Commit 12b5490

Browse files
authored
Merge pull request tweag#70 from freuk/master
[feature] adds a "extraJupyterPath" arguments for local python module development.
2 parents 882d056 + 9fc066c commit 12b5490

File tree

2 files changed

+47
-4
lines changed

2 files changed

+47
-4
lines changed

README.md

+40-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,28 @@ let
198198
};
199199
```
200200

201-
Here, the `p` argument corresponds to Nixpkgs checkout being used.
201+
Here, the `p` argument corresponds to Nixpkgs checkout being used. Note that
202+
this can easily be made to use packages from outside `jupyterWith`'s scope, by
203+
providing a function that ignores its argument:
204+
205+
```nix
206+
extraPackages = _ : [ pkgs.pandoc ];
207+
```
208+
209+
You may also bring all inputs from a package in scope using the
210+
"extraInputsFrom" argument:
211+
212+
``` nix
213+
let
214+
jupyter = import (builtins.fetchGit {
215+
url = https://github.com/tweag/jupyterWith;
216+
rev = "";
217+
}) {};
218+
219+
jupyterEnvironment = jupyter.jupyterlabWith {
220+
extraInputsFrom = p: [p.pythonPackages.numpy];
221+
};
222+
```
202223

203224
## Using as an overlay
204225

@@ -224,6 +245,24 @@ in
224245
pkgs.jupyterWith;
225246
```
226247

248+
## Importing local python packages
249+
250+
You may use the `extraJupyterPath` arguments to add local
251+
python packages in scope:
252+
253+
```
254+
let
255+
jupyter = import (builtins.fetchGit {
256+
url = https://github.com/tweag/jupyterWith;
257+
rev = "";
258+
}) {};
259+
260+
jupyterEnvironment = jupyter.jupyterlabWith {
261+
extraJupyterPath = "${builtins.toPath ./.}/local_module/";
262+
};
263+
```
264+
265+
227266
## Contributing
228267

229268
### Kernels

default.nix

+7-3
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,15 @@ let
1818
defaultDirectory = "${python3.jupyterlab}/share/jupyter/lab";
1919
defaultKernels = [ (kernels.iPythonWith {}) ];
2020
defaultExtraPackages = p: [];
21+
defaultExtraInputsFrom = p: [];
2122

2223
# JupyterLab with the appropriate kernel and directory setup.
2324
jupyterlabWith = {
2425
directory ? defaultDirectory,
2526
kernels ? defaultKernels,
26-
extraPackages ? defaultExtraPackages
27+
extraPackages ? defaultExtraPackages,
28+
extraInputsFrom ? defaultExtraInputsFrom,
29+
extraJupyterPath ? ""
2730
}:
2831
let
2932
# PYTHONPATH setup for JupyterLab
@@ -39,15 +42,16 @@ let
3942
python3.jupyterlab.overridePythonAttrs (oldAttrs: {
4043
makeWrapperArgs = [
4144
"--set JUPYTERLAB_DIR ${directory}"
42-
"--set JUPYTER_PATH ${kernelsString kernels}"
43-
"--set PYTHONPATH ${pythonPath}"
45+
"--set JUPYTER_PATH ${extraJupyterPath}:${kernelsString kernels}"
46+
"--set PYTHONPATH ${extraJupyterPath}:${pythonPath}"
4447
];
4548
})
4649
);
4750

4851
# Shell with the appropriate JupyterLab, launching it at startup.
4952
env = pkgs.mkShell {
5053
name = "jupyterlab-shell";
54+
inputsFrom = extraInputsFrom pkgs;
5155
buildInputs =
5256
[ jupyterlab generateDirectory pkgs.nodejs ] ++
5357
(map (k: k.runtimePackages) kernels) ++

0 commit comments

Comments
 (0)