@@ -1,5 +1,14 @@
1−{ stdenv, buildPythonPackage, fetchPypi
2−, libGLU_combined, xorg, freetype, fontconfig, future}:
1+{ stdenv
2+, buildPythonPackage
3+, fetchPypi
4+, libGLU_combined
5+, xorg
6+, future
7+, pytest
8+, glibc
9+, gtk2-x11
10+, gdk_pixbuf
11+}:
312
413buildPythonPackage rec {
514 version = "1.3.2";
@@ -10,14 +19,49 @@ buildPythonPackage rec {
1019 sha256 = "b00570e7cdf6971af8953b6ece50d83d13272afa5d1f1197c58c0f478dd17743";
1120 };
1221
22+ # find_library doesn't reliably work with nix (https://github.com/NixOS/nixpkgs/issues/7307).
23+ # Even naively searching `LD_LIBRARY_PATH` won't work since `libc.so` is a linker script and
24+ # ctypes.cdll.LoadLibrary cannot deal with those. Therefore, just hardcode the paths to the
25+ # necessary libraries.
1326 postPatch = let
14− libs = [ libGLU_combined xorg.libX11 freetype fontconfig ];
15− paths = builtins.concatStringsSep "," (map (l: "\"${l}/lib\"") libs);
16− in "sed -i -e 's|directories\.extend.*lib[^]]*|&,${paths}|' pyglet/lib.py";
27+ ext = stdenv.hostPlatform.extensions.sharedLibrary;
28+ in ''
29+ cat > pyglet/lib.py <<EOF
30+ import ctypes
31+ def load_library(*names, **kwargs):
32+ for name in names:
33+ path = None
34+ if name == 'GL':
35+ path = '${libGLU_combined}/lib/libGL${ext}'
36+ elif name == 'GLU':
37+ path = '${libGLU_combined}/lib/libGLU${ext}'
38+ elif name == 'c':
39+ path = '${glibc}/lib/libc${ext}.6'
40+ elif name == 'X11':
41+ path = '${xorg.libX11}/lib/libX11${ext}'
42+ elif name == 'gdk-x11-2.0':
43+ path = '${gtk2-x11}/lib/libgdk-x11-2.0${ext}'
44+ elif name == 'gdk_pixbuf-2.0':
45+ path = '${gdk_pixbuf}/lib/libgdk_pixbuf-2.0${ext}'
46+ if path is not None:
47+ return ctypes.cdll.LoadLibrary(path)
48+ raise Exception("Could not load library {}".format(names))
49+ EOF
50+ '';
1751
52+ propagatedBuildInputs = [ future ];
53+
54+ # needs an X server. Keep an eye on
55+ # https://bitbucket.org/pyglet/pyglet/issues/219/egl-support-headless-rendering
1856 doCheck = false;
1957
20− propagatedBuildInputs = [ future ];
58+ checkInputs = [
59+ pytest
60+ ];
61+
62+ checkPhase = ''
63+ py.test tests/unit tests/integration
64+ '';
2165
2266 meta = with stdenv.lib; {
2367 homepage = "http://www.pyglet.org/";