1{ stdenv
2, buildPythonPackage
3, fetchPypi
4, libGLU_combined
5, xorg
6, future
7, pytest
8, glibc
9, gtk2-x11
10, gdk-pixbuf
11}:
12
13buildPythonPackage rec {
14 version = "1.4.2";
15 pname = "pyglet";
16
17 src = fetchPypi {
18 inherit pname version;
19 sha256 = "1dxxrl4nc7xh3aai1clgzvk48bvd35r7ksirsddz0mwhx7jmm8px";
20 };
21
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.
26 postPatch = let
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 '';
51
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
56 doCheck = false;
57
58 checkInputs = [
59 pytest
60 ];
61
62 checkPhase = ''
63 py.test tests/unit tests/integration
64 '';
65
66 meta = with stdenv.lib; {
67 homepage = "http://www.pyglet.org/";
68 description = "A cross-platform windowing and multimedia library";
69 license = licenses.bsd3;
70 platforms = platforms.mesaPlatforms;
71 };
72}