1{ stdenv, lib, substituteAll, fetchFromGitHub, buildPythonPackage, python, pkg-config, libX11
2, SDL2, SDL2_image, SDL2_mixer, SDL2_ttf, libpng, libjpeg, portmidi, freetype, fontconfig
3, AppKit
4, pythonOlder
5}:
6
7buildPythonPackage rec {
8 pname = "pygame";
9 version = "2.5.1";
10
11 disabled = pythonOlder "3.6";
12
13 format = "setuptools";
14
15 src = fetchFromGitHub {
16 owner = pname;
17 repo = pname;
18 rev = "refs/tags/${version}";
19 # Unicode file names lead to different checksums on HFS+ vs. other
20 # filesystems because of unicode normalisation. The documentation
21 # has such files and will be removed.
22 hash = "sha256-0mVbjfNYTfuo8uyd7NFKlneUZMt78mcitQ5nCgPxmFs=";
23 postFetch = "rm -rf $out/docs/reST";
24 };
25
26 patches = [
27 # Patch pygame's dependency resolution to let it find build inputs
28 (substituteAll {
29 src = ./fix-dependency-finding.patch;
30 buildinputs_include = builtins.toJSON (builtins.concatMap (dep: [
31 "${lib.getDev dep}/"
32 "${lib.getDev dep}/include"
33 "${lib.getDev dep}/include/SDL2"
34 ]) buildInputs);
35 buildinputs_lib = builtins.toJSON (builtins.concatMap (dep: [
36 "${lib.getLib dep}/"
37 "${lib.getLib dep}/lib"
38 ]) buildInputs);
39 })
40 ];
41
42 postPatch = ''
43 substituteInPlace src_py/sysfont.py \
44 --replace 'path="fc-list"' 'path="${fontconfig}/bin/fc-list"' \
45 --replace /usr/X11/bin/fc-list ${fontconfig}/bin/fc-list
46 '';
47
48 nativeBuildInputs = [
49 pkg-config SDL2
50 ];
51
52 buildInputs = [
53 SDL2 SDL2_image SDL2_mixer SDL2_ttf libpng libjpeg
54 portmidi libX11 freetype
55 ] ++ lib.optionals stdenv.isDarwin [
56 AppKit
57 ];
58
59 preConfigure = ''
60 ${python.pythonOnBuildForHost.interpreter} buildconfig/config.py
61 '';
62
63 env = lib.optionalAttrs stdenv.cc.isClang {
64 NIX_CFLAGS_COMPILE = "-Wno-error=incompatible-function-pointer-types";
65 };
66
67 checkPhase = ''
68 runHook preCheck
69
70 # No audio or video device in test environment
71 export SDL_VIDEODRIVER=dummy
72 export SDL_AUDIODRIVER=disk
73 export SDL_DISKAUDIOFILE=/dev/null
74
75 ${python.interpreter} -m pygame.tests -v --exclude opengl,timing --time_out 300
76
77 runHook postCheck
78 '';
79 pythonImportsCheck = [ "pygame" ];
80
81 meta = with lib; {
82 description = "Python library for games";
83 homepage = "https://www.pygame.org/";
84 license = licenses.lgpl21Plus;
85 maintainers = with maintainers; [ emilytrau ];
86 platforms = platforms.unix;
87 };
88}