1{
2 stdenv,
3 lib,
4 substituteAll,
5 fetchFromGitHub,
6 buildPythonPackage,
7 pythonOlder,
8 python,
9 pkg-config,
10 setuptools,
11 cython,
12
13 AppKit,
14 fontconfig,
15 freetype,
16 libjpeg,
17 libpng,
18 libX11,
19 portmidi,
20 SDL2,
21 SDL2_image,
22 SDL2_mixer,
23 SDL2_ttf,
24}:
25
26buildPythonPackage rec {
27 pname = "pygame-ce";
28 version = "2.4.1";
29 pyproject = true;
30
31 disabled = pythonOlder "3.6";
32
33 src = fetchFromGitHub {
34 owner = "pygame-community";
35 repo = "pygame-ce";
36 rev = "refs/tags/${version}";
37 hash = "sha256-4Ky+QEUsQ0odcwEETk0yGECs7CcJQthhavboOnMDvF8=";
38 # Unicode file cause different checksums on HFS+ vs. other filesystems
39 postFetch = "rm -rf $out/docs/reST";
40 };
41
42 patches = [
43 (substituteAll {
44 src = ./fix-dependency-finding.patch;
45 buildinputs_include = builtins.toJSON (
46 builtins.concatMap (dep: [
47 "${lib.getDev dep}/"
48 "${lib.getDev dep}/include"
49 "${lib.getDev dep}/include/SDL2"
50 ]) buildInputs
51 );
52 buildinputs_lib = builtins.toJSON (
53 builtins.concatMap (dep: [
54 "${lib.getLib dep}/"
55 "${lib.getLib dep}/lib"
56 ]) buildInputs
57 );
58 })
59 # Skip tests that should be disabled without video driver
60 ./skip-surface-tests.patch
61 ];
62
63 postPatch =
64 ''
65 substituteInPlace buildconfig/config_{unix,darwin}.py \
66 --replace-fail 'from distutils' 'from setuptools._distutils'
67 substituteInPlace src_py/sysfont.py \
68 --replace-fail 'path="fc-list"' 'path="${fontconfig}/bin/fc-list"' \
69 --replace-fail /usr/X11/bin/fc-list ${fontconfig}/bin/fc-list
70 ''
71 + lib.optionalString stdenv.isDarwin ''
72 # flaky
73 rm test/system_test.py
74 '';
75
76 nativeBuildInputs = [
77 pkg-config
78 cython
79 setuptools
80 ];
81
82 buildInputs = [
83 freetype
84 libX11
85 libjpeg
86 libpng
87 portmidi
88 SDL2
89 SDL2_image
90 SDL2_mixer
91 SDL2_ttf
92 ] ++ lib.optionals stdenv.isDarwin [ AppKit ];
93
94 preConfigure = ''
95 ${python.pythonOnBuildForHost.interpreter} buildconfig/config.py
96 '';
97
98 env =
99 {
100 SDL_CONFIG = "${SDL2.dev}/bin/sdl2-config";
101 }
102 // lib.optionalAttrs stdenv.cc.isClang {
103 NIX_CFLAGS_COMPILE = "-Wno-error=incompatible-function-pointer-types";
104 };
105
106 preCheck = ''
107 export HOME=$(mktemp -d)
108 # No audio or video device in test environment
109 export SDL_VIDEODRIVER=dummy
110 export SDL_AUDIODRIVER=disk
111 '';
112
113 checkPhase = ''
114 runHook preCheck
115 ${python.interpreter} -m pygame.tests -v --exclude opengl,timing --time_out 300
116 runHook postCheck
117 '';
118
119 pythonImportsCheck = [ "pygame" ];
120
121 meta = with lib; {
122 description = "Pygame Community Edition (CE) - library for multimedia application built on SDL";
123 homepage = "https://pyga.me/";
124 license = licenses.lgpl21Plus;
125 maintainers = with maintainers; [ pbsds ];
126 platforms = platforms.unix;
127 };
128}