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