1{ 2 stdenv, 3 lib, 4 replaceVars, 5 fetchFromGitHub, 6 buildPythonPackage, 7 pythonOlder, 8 python, 9 pkg-config, 10 setuptools, 11 cython, 12 ninja, 13 meson-python, 14 15 fontconfig, 16 freetype, 17 libjpeg, 18 libpng, 19 libX11, 20 portmidi, 21 SDL2_classic, 22 SDL2_classic_image, 23 SDL2_classic_mixer, 24 SDL2_classic_ttf, 25 numpy, 26 27 pygame-gui, 28}: 29 30buildPythonPackage rec { 31 pname = "pygame-ce"; 32 version = "2.5.3"; 33 pyproject = true; 34 35 disabled = pythonOlder "3.8"; 36 37 src = fetchFromGitHub { 38 owner = "pygame-community"; 39 repo = "pygame-ce"; 40 tag = version; 41 hash = "sha256-Vl9UwCknbMHdsB1wwo/JqybWz3UbAMegIcO0GpiCxig="; 42 # Unicode files cause different checksums on HFS+ vs. other filesystems 43 postFetch = "rm -rf $out/docs/reST"; 44 }; 45 46 patches = [ 47 (replaceVars ./fix-dependency-finding.patch { 48 buildinputs_include = builtins.toJSON ( 49 builtins.concatMap (dep: [ 50 "${lib.getDev dep}/" 51 "${lib.getDev dep}/include" 52 "${lib.getDev dep}/include/SDL2" 53 ]) buildInputs 54 ); 55 buildinputs_lib = builtins.toJSON ( 56 builtins.concatMap (dep: [ 57 "${lib.getLib dep}/" 58 "${lib.getLib dep}/lib" 59 ]) buildInputs 60 ); 61 }) 62 ]; 63 64 postPatch = 65 '' 66 # cython was pinned to fix windows build hangs (pygame-community/pygame-ce/pull/3015) 67 substituteInPlace pyproject.toml \ 68 --replace-fail '"meson<=1.7.0",' '"meson",' \ 69 --replace-fail '"meson-python<=0.17.1",' '"meson-python",' \ 70 --replace-fail '"ninja<=1.12.1",' "" \ 71 --replace-fail '"cython<=3.0.11",' '"cython",' \ 72 --replace-fail '"sphinx<=8.1.3",' "" \ 73 --replace-fail '"sphinx-autoapi<=3.3.2",' "" 74 substituteInPlace buildconfig/config_{unix,darwin}.py \ 75 --replace-fail 'from distutils' 'from setuptools._distutils' 76 substituteInPlace src_py/sysfont.py \ 77 --replace-fail 'path="fc-list"' 'path="${fontconfig}/bin/fc-list"' \ 78 --replace-fail /usr/X11/bin/fc-list ${fontconfig}/bin/fc-list 79 '' 80 + lib.optionalString stdenv.hostPlatform.isDarwin '' 81 # flaky 82 rm test/system_test.py 83 substituteInPlace test/meson.build \ 84 --replace-fail "'system_test.py'," "" 85 ''; 86 87 nativeBuildInputs = [ 88 pkg-config 89 cython 90 setuptools 91 ninja 92 meson-python 93 ]; 94 95 buildInputs = [ 96 freetype 97 libX11 98 libjpeg 99 libpng 100 portmidi 101 SDL2_classic 102 (SDL2_classic_image.override { enableSTB = false; }) 103 SDL2_classic_mixer 104 SDL2_classic_ttf 105 ]; 106 107 nativeCheckInputs = [ 108 numpy 109 ]; 110 111 preConfigure = '' 112 ${python.pythonOnBuildForHost.interpreter} -m buildconfig.config 113 ''; 114 115 env = 116 { 117 SDL_CONFIG = lib.getExe' (lib.getDev SDL2_classic) "sdl2-config"; 118 } 119 // lib.optionalAttrs stdenv.cc.isClang { 120 NIX_CFLAGS_COMPILE = "-Wno-error=incompatible-function-pointer-types"; 121 }; 122 123 preCheck = '' 124 export HOME=$(mktemp -d) 125 # No audio or video device in test environment 126 export SDL_VIDEODRIVER=dummy 127 export SDL_AUDIODRIVER=disk 128 # traceback for segfaults 129 export PYTHONFAULTHANDLER=1 130 ''; 131 132 checkPhase = '' 133 runHook preCheck 134 ${python.interpreter} -m pygame.tests -v --exclude opengl,timing --time_out 300 135 runHook postCheck 136 ''; 137 138 pythonImportsCheck = [ 139 "pygame" 140 "pygame.camera" 141 "pygame.colordict" 142 "pygame.cursors" 143 "pygame.freetype" 144 "pygame.ftfont" 145 "pygame.locals" 146 "pygame.midi" 147 "pygame.pkgdata" 148 "pygame.sndarray" # requires numpy 149 "pygame.sprite" 150 "pygame.surfarray" 151 "pygame.sysfont" 152 "pygame.version" 153 ]; 154 155 passthru.tests = { 156 inherit pygame-gui; 157 }; 158 159 meta = { 160 description = "Pygame Community Edition (CE) - library for multimedia application built on SDL"; 161 homepage = "https://pyga.me/"; 162 changelog = "https://github.com/pygame-community/pygame-ce/releases/tag/${src.tag}"; 163 license = lib.licenses.lgpl21Plus; 164 maintainers = [ lib.maintainers.pbsds ]; 165 platforms = lib.platforms.unix; 166 }; 167}