1{ stdenv
2, buildPythonPackage
3, fetchPypi
4, libGL
5, libGLU
6, xorg
7, future
8, pytest
9, glibc
10, gtk2-x11
11, gdk-pixbuf
12, fontconfig
13, freetype
14}:
15
16buildPythonPackage rec {
17 version = "1.4.2";
18 pname = "pyglet";
19
20 src = fetchPypi {
21 inherit pname version;
22 sha256 = "1dxxrl4nc7xh3aai1clgzvk48bvd35r7ksirsddz0mwhx7jmm8px";
23 };
24
25 # find_library doesn't reliably work with nix (https://github.com/NixOS/nixpkgs/issues/7307).
26 # Even naively searching `LD_LIBRARY_PATH` won't work since `libc.so` is a linker script and
27 # ctypes.cdll.LoadLibrary cannot deal with those. Therefore, just hardcode the paths to the
28 # necessary libraries.
29 postPatch = let
30 ext = stdenv.hostPlatform.extensions.sharedLibrary;
31 in ''
32 cat > pyglet/lib.py <<EOF
33 import ctypes
34 def load_library(*names, **kwargs):
35 for name in names:
36 path = None
37 if name == 'GL':
38 path = '${libGL}/lib/libGL${ext}'
39 elif name == 'GLU':
40 path = '${libGLU}/lib/libGLU${ext}'
41 elif name == 'c':
42 path = '${glibc}/lib/libc${ext}.6'
43 elif name == 'X11':
44 path = '${xorg.libX11}/lib/libX11${ext}'
45 elif name == 'gdk-x11-2.0':
46 path = '${gtk2-x11}/lib/libgdk-x11-2.0${ext}'
47 elif name == 'gdk_pixbuf-2.0':
48 path = '${gdk-pixbuf}/lib/libgdk_pixbuf-2.0${ext}'
49 elif name == 'Xext':
50 path = '${xorg.libXext}/lib/libXext${ext}'
51 elif name == 'fontconfig':
52 path = '${fontconfig.lib}/lib/libfontconfig${ext}'
53 elif name == 'freetype':
54 path = '${freetype}/lib/libfreetype${ext}'
55 if path is not None:
56 return ctypes.cdll.LoadLibrary(path)
57 raise Exception("Could not load library {}".format(names))
58 EOF
59 '';
60
61 propagatedBuildInputs = [ future ];
62
63 # needs an X server. Keep an eye on
64 # https://bitbucket.org/pyglet/pyglet/issues/219/egl-support-headless-rendering
65 doCheck = false;
66
67 checkInputs = [
68 pytest
69 ];
70
71 checkPhase = ''
72 py.test tests/unit tests/integration
73 '';
74
75 meta = with stdenv.lib; {
76 homepage = "http://www.pyglet.org/";
77 description = "A cross-platform windowing and multimedia library";
78 license = licenses.bsd3;
79 platforms = platforms.mesaPlatforms;
80 };
81}