1{
2 stdenv,
3 lib,
4 substituteAll,
5 fetchpatch,
6 fetchFromGitHub,
7 buildPythonPackage,
8 pythonOlder,
9
10 # build-system
11 cython,
12 setuptools,
13 pkg-config,
14
15 # native dependencies
16 AppKit,
17 fontconfig,
18 freetype,
19 libjpeg,
20 libpng,
21 libX11,
22 portmidi,
23 SDL2,
24 SDL2_image,
25 SDL2_mixer,
26 SDL2_ttf,
27
28 # tests
29 python,
30}:
31
32buildPythonPackage rec {
33 pname = "pygame";
34 version = "2.5.2";
35 pyproject = true;
36
37 disabled = pythonOlder "3.6";
38
39 src = fetchFromGitHub {
40 owner = pname;
41 repo = pname;
42 rev = "refs/tags/${version}";
43 # Unicode file names lead to different checksums on HFS+ vs. other
44 # filesystems because of unicode normalisation. The documentation
45 # has such files and will be removed.
46 hash = "sha256-+gRv3Rim+2aL2uhPPGfVD0QDgB013lTf6wPx8rOwgXg=";
47 postFetch = "rm -rf $out/docs/reST";
48 };
49
50 patches = [
51 # Patch pygame's dependency resolution to let it find build inputs
52 (substituteAll {
53 src = ./fix-dependency-finding.patch;
54 buildinputs_include = builtins.toJSON (
55 builtins.concatMap (dep: [
56 "${lib.getDev dep}/"
57 "${lib.getDev dep}/include"
58 "${lib.getDev dep}/include/SDL2"
59 ]) buildInputs
60 );
61 buildinputs_lib = builtins.toJSON (
62 builtins.concatMap (dep: [
63 "${lib.getLib dep}/"
64 "${lib.getLib dep}/lib"
65 ]) buildInputs
66 );
67 })
68 # Skip tests that should be disabled without video driver
69 ./skip-surface-tests.patch
70
71 # removes distutils unbreaking py312, part of https://github.com/pygame/pygame/pull/4211
72 (fetchpatch {
73 name = "remove-distutils.patch";
74 url = "https://github.com/pygame/pygame/commit/6038e7d6583a7a25fcc6e15387cf6240e427e5a7.patch";
75 hash = "sha256-HxcYjjhsu/Y9HiK9xDvY4X5dgWPP4XFLxdYGXC6tdWM=";
76 })
77 ];
78
79 postPatch = ''
80 substituteInPlace src_py/sysfont.py \
81 --replace-fail 'path="fc-list"' 'path="${fontconfig}/bin/fc-list"' \
82 --replace-fail /usr/X11/bin/fc-list ${fontconfig}/bin/fc-list
83 '';
84
85 nativeBuildInputs = [
86 cython
87 pkg-config
88 SDL2
89 setuptools
90 ];
91
92 buildInputs = [
93 freetype
94 libjpeg
95 libpng
96 libX11
97 portmidi
98 SDL2
99 SDL2_image
100 SDL2_mixer
101 SDL2_ttf
102 ] ++ lib.optionals stdenv.isDarwin [ AppKit ];
103
104 preConfigure = ''
105 ${python.pythonOnBuildForHost.interpreter} buildconfig/config.py
106 '';
107
108 env = lib.optionalAttrs stdenv.cc.isClang {
109 NIX_CFLAGS_COMPILE = "-Wno-error=incompatible-function-pointer-types";
110 };
111
112 checkPhase = ''
113 runHook preCheck
114
115 # No audio or video device in test environment
116 export SDL_VIDEODRIVER=dummy
117 export SDL_AUDIODRIVER=disk
118
119 ${python.interpreter} -m pygame.tests -v --exclude opengl,timing --time_out 300
120
121 runHook postCheck
122 '';
123 pythonImportsCheck = [ "pygame" ];
124
125 meta = with lib; {
126 description = "Python library for games";
127 homepage = "https://www.pygame.org/";
128 license = licenses.lgpl21Plus;
129 maintainers = with maintainers; [ emilytrau ];
130 platforms = platforms.unix;
131 };
132}