at master 5.1 kB view raw
1{ 2 lib, 3 stdenv, 4 buildPythonPackage, 5 fetchPypi, 6 unzip, 7 pythonOlder, 8 libGL, 9 libGLU, 10 xorg, 11 pytestCheckHook, 12 glibc, 13 gtk2-x11, 14 gdk-pixbuf, 15 fontconfig, 16 freetype, 17 ffmpeg-full, 18 openal, 19 libpulseaudio, 20 harfbuzz, 21 mesa, 22 apple-sdk, 23}: 24 25buildPythonPackage rec { 26 version = "2.0.10"; 27 format = "setuptools"; 28 pname = "pyglet"; 29 disabled = pythonOlder "3.6"; 30 31 src = fetchPypi { 32 inherit pname version; 33 hash = "sha256-JCvrGzvWfFvr3+W6EexWtpathrUMbn8qMX+NeDJWuck="; 34 extension = "zip"; 35 }; 36 37 # find_library doesn't reliably work with nix (https://github.com/NixOS/nixpkgs/issues/7307). 38 # Even naively searching `LD_LIBRARY_PATH` won't work since `libc.so` is a linker script and 39 # ctypes.cdll.LoadLibrary cannot deal with those. Therefore, just hardcode the paths to the 40 # necessary libraries. 41 postPatch = 42 let 43 ext = stdenv.hostPlatform.extensions.sharedLibrary; 44 in 45 lib.optionalString stdenv.isLinux '' 46 cat > pyglet/lib.py <<EOF 47 import ctypes 48 def load_library(*names, **kwargs): 49 for name in names: 50 path = None 51 if name == 'GL': 52 path = '${libGL}/lib/libGL${ext}' 53 elif name == 'EGL': 54 path = '${libGL}/lib/libEGL${ext}' 55 elif name == 'GLU': 56 path = '${libGLU}/lib/libGLU${ext}' 57 elif name == 'c': 58 path = '${glibc}/lib/libc${ext}.6' 59 elif name == 'X11': 60 path = '${xorg.libX11}/lib/libX11${ext}' 61 elif name == 'gdk-x11-2.0': 62 path = '${gtk2-x11}/lib/libgdk-x11-2.0${ext}' 63 elif name == 'gdk_pixbuf-2.0': 64 path = '${gdk-pixbuf}/lib/libgdk_pixbuf-2.0${ext}' 65 elif name == 'Xext': 66 path = '${xorg.libXext}/lib/libXext${ext}' 67 elif name == 'fontconfig': 68 path = '${fontconfig.lib}/lib/libfontconfig${ext}' 69 elif name == 'freetype': 70 path = '${freetype}/lib/libfreetype${ext}' 71 elif name[0:2] == 'av' or name[0:2] == 'sw': 72 path = '${lib.getLib ffmpeg-full}/lib/lib' + name + '${ext}' 73 elif name == 'openal': 74 path = '${openal}/lib/libopenal${ext}' 75 elif name == 'pulse': 76 path = '${libpulseaudio}/lib/libpulse${ext}' 77 elif name == 'Xi': 78 path = '${xorg.libXi}/lib/libXi${ext}' 79 elif name == 'Xinerama': 80 path = '${xorg.libXinerama}/lib/libXinerama${ext}' 81 elif name == 'Xxf86vm': 82 path = '${xorg.libXxf86vm}/lib/libXxf86vm${ext}' 83 elif name == 'harfbuzz': 84 path = '${harfbuzz}/lib/libharfbuzz${ext}' 85 if path is not None: 86 return ctypes.cdll.LoadLibrary(path) 87 raise Exception("Could not load library {}".format(names)) 88 EOF 89 '' 90 + lib.optionalString stdenv.isDarwin '' 91 cat > pyglet/lib.py <<EOF 92 import os 93 import ctypes 94 def load_library(*names, **kwargs): 95 path = None 96 framework = kwargs.get('framework') 97 if framework is not None: 98 path = '${apple-sdk}/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/{framework}.framework/{framework}'.format(framework=framework) 99 else: 100 names = kwargs.get('darwin', names) 101 if not isinstance(names, tuple): 102 names = (names,) 103 for name in names: 104 if name == "libharfbuzz.0.dylib": 105 path = '${harfbuzz}/lib/%s' % name 106 break 107 elif name.startswith('avutil'): 108 path = '${lib.getLib ffmpeg-full}/lib/lib%s.dylib' % name 109 if not os.path.exists(path): 110 path = None 111 else: 112 break 113 if path is not None: 114 return ctypes.cdll.LoadLibrary(path) 115 raise ImportError("Could not load library {}".format(names)) 116 EOF 117 ''; 118 119 nativeBuildInputs = [ unzip ]; 120 121 # needs GL set up which isn't really possible in a build environment even in headless mode. 122 # tests do run and pass in nix-shell, however. 123 doCheck = false; 124 125 nativeCheckInputs = [ pytestCheckHook ]; 126 127 preCheck = # libEGL only available on Linux (despite meta.platforms on libGL) 128 lib.optionalString stdenv.isLinux '' 129 export PYGLET_HEADLESS=True 130 ''; 131 132 # test list taken from .travis.yml 133 disabledTestPaths = [ 134 "tests/base" 135 "tests/interactive" 136 "tests/integration" 137 "tests/unit/text/test_layout.py" 138 ]; 139 140 pythonImportsCheck = [ "pyglet" ]; 141 142 meta = { 143 homepage = "http://www.pyglet.org/"; 144 description = "Cross-platform windowing and multimedia library"; 145 license = lib.licenses.bsd3; 146 # The patch needs adjusting for other platforms. 147 platforms = with lib.platforms; linux ++ darwin; 148 }; 149}