Merge pull request #268619 from tweag/lib-descriptions
[NixPkgs.git] / pkgs / development / python-modules / pyglet / default.nix
blob393ec9f2e4cc9cfe1c856d22fd29e39019ca5792
1 { lib, stdenv
2 , buildPythonPackage
3 , fetchPypi
4 , unzip
5 , pythonOlder
6 , libGL
7 , libGLU
8 , xorg
9 , pytestCheckHook
10 , glibc
11 , gtk2-x11
12 , gdk-pixbuf
13 , fontconfig
14 , freetype
15 , ffmpeg-full
16 , openal
17 , libpulseaudio
20 buildPythonPackage rec {
21   version = "2.0.10";
22   pname = "pyglet";
23   disabled = pythonOlder "3.6";
25   src = fetchPypi {
26     inherit pname version;
27     hash = "sha256-JCvrGzvWfFvr3+W6EexWtpathrUMbn8qMX+NeDJWuck=";
28     extension = "zip";
29   };
31   # find_library doesn't reliably work with nix (https://github.com/NixOS/nixpkgs/issues/7307).
32   # Even naively searching `LD_LIBRARY_PATH` won't work since `libc.so` is a linker script and
33   # ctypes.cdll.LoadLibrary cannot deal with those. Therefore, just hardcode the paths to the
34   # necessary libraries.
35   postPatch = let
36     ext = stdenv.hostPlatform.extensions.sharedLibrary;
37   in ''
38     cat > pyglet/lib.py <<EOF
39     import ctypes
40     def load_library(*names, **kwargs):
41         for name in names:
42             path = None
43             if name == 'GL':
44                 path = '${libGL}/lib/libGL${ext}'
45             elif name == 'EGL':
46                 path = '${libGL}/lib/libEGL${ext}'
47             elif name == 'GLU':
48                 path = '${libGLU}/lib/libGLU${ext}'
49             elif name == 'c':
50                 path = '${glibc}/lib/libc${ext}.6'
51             elif name == 'X11':
52                 path = '${xorg.libX11}/lib/libX11${ext}'
53             elif name == 'gdk-x11-2.0':
54                 path = '${gtk2-x11}/lib/libgdk-x11-2.0${ext}'
55             elif name == 'gdk_pixbuf-2.0':
56                 path = '${gdk-pixbuf}/lib/libgdk_pixbuf-2.0${ext}'
57             elif name == 'Xext':
58                 path = '${xorg.libXext}/lib/libXext${ext}'
59             elif name == 'fontconfig':
60                 path = '${fontconfig.lib}/lib/libfontconfig${ext}'
61             elif name == 'freetype':
62                 path = '${freetype}/lib/libfreetype${ext}'
63             elif name[0:2] == 'av' or name[0:2] == 'sw':
64                 path = '${ffmpeg-full}/lib/lib' + name + '${ext}'
65             elif name == 'openal':
66                 path = '${openal}/lib/libopenal${ext}'
67             elif name == 'pulse':
68                 path = '${libpulseaudio}/lib/libpulse${ext}'
69             elif name == 'Xi':
70                 path = '${xorg.libXi}/lib/libXi${ext}'
71             elif name == 'Xinerama':
72                 path = '${xorg.libXinerama}/lib/libXinerama${ext}'
73             elif name == 'Xxf86vm':
74                 path = '${xorg.libXxf86vm}/lib/libXxf86vm${ext}'
75             if path is not None:
76                 return ctypes.cdll.LoadLibrary(path)
77         raise Exception("Could not load library {}".format(names))
78     EOF
79   '';
81   nativeBuildInputs = [ unzip ];
83   # needs GL set up which isn't really possible in a build environment even in headless mode.
84   # tests do run and pass in nix-shell, however.
85   doCheck = false;
87   nativeCheckInputs = [
88     pytestCheckHook
89   ];
91   preCheck = ''
92     export PYGLET_HEADLESS=True
93   '';
95   # test list taken from .travis.yml
96   disabledTestPaths = [
97     "tests/base"
98     "tests/interactive"
99     "tests/integration"
100     "tests/unit/text/test_layout.py"
101   ];
103   pythonImportsCheck = [ "pyglet" ];
105   meta = with lib; {
106     homepage = "http://www.pyglet.org/";
107     description = "A cross-platform windowing and multimedia library";
108     license = licenses.bsd3;
109     platforms = platforms.mesaPlatforms;
110   };