-
Notifications
You must be signed in to change notification settings - Fork 5
/
dev.nix
111 lines (87 loc) · 2.77 KB
/
dev.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
{ benchmark ? false }:
let
# pin version
pkgs = import (builtins.fetchTarball {
url = "https://github.com/costrouc/nixpkgs/archive/14775a074cfacc59482d1adf0446801d38c08216.tar.gz";
sha256 = "152dflinv7a0nk267nc1i3ldvrx5fwxm7cf3igxc0qnd92n82phf";
}) { };
pythonPackages = pkgs.python3Packages;
buildInputs = with pythonPackages; [ astunparse ];
docsInputs = with pythonPackages; [ sphinx sphinxcontrib-tikz ];
testInputs = with pythonPackages; [ pytest pytestcov graphviz sly ];
benchmarkInputs = with pythonPackages; [ pytest-benchmark numpy numba pytorch tensorflow ];
in
rec {
python-moa = pythonPackages.buildPythonPackage {
name = "python-moa";
src = builtins.filterSource
(path: _: !builtins.elem (builtins.baseNameOf path) [".git" "result" "docs"])
./.;
propagatedBuildInputs = buildInputs;
checkInputs = if benchmark then testInputs ++ benchmarkInputs else testInputs;
checkPhase = ''
pytest tests ${if benchmark then "benchmarks" else ""} --cov=moa
'';
};
release = pkgs.stdenv.mkDerivation {
name = "python-moa-sdist";
buildInputs = [ python-moa ];
src = builtins.filterSource
(path: _: !builtins.elem (builtins.baseNameOf path) [".git" "result"])
./.;
buildPhase = ''
python setup.py sdist
'';
installPhase = ''
mkdir -p $out
cp dist/* $out
'';
};
docs = pkgs.stdenv.mkDerivation {
name = "python-moa-docs";
src = builtins.filterSource
(path: _: !builtins.elem (builtins.baseNameOf path) [".git" "result"])
./.;
postPatch = ''
# readthedocs makes the default GhostScript
substituteInPlace docs/conf.py \
--replace "'GhostScript'" "'pdf2svg'"
'';
buildInputs = [ python-moa ] ++ docsInputs;
buildPhase = ''
cd docs;
sphinx-apidoc -f -o source/ ../moa
sphinx-build -b doctest . _build/doctest
sphinx-build -b html . _build/html
'';
installPhase = ''
mkdir $out
cp -r _build/html/* $out
'';
};
# docker load < result
docker = pkgs.dockerTools.buildLayeredImage {
name = "python-moa";
tag = "latest";
contents = [
(pythonPackages.python.withPackages (ps: with ps; [ python-moa ipython ]))
];
config.Cmd = [ "ipython" ];
maxLayers = 120;
};
ipython-shell = pkgs.mkShell {
buildInputs = with pythonPackages; [ python-moa ipython ];
shellHook = ''
cd notebooks; ipython
'';
};
jupyter-shell = pkgs.mkShell {
buildInputs = with pythonPackages; [ python-moa jupyterlab graphviz numpy numba];
shellHook = ''
cd notebooks; jupyter lab
'';
};
binder = pkgs.mkShell {
buildInputs = with pythonPackages; [ python-moa jupyterlab graphviz numpy numba];
};
}