nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 stdenv,
3 lib,
4 replaceVars,
5 fetchFromGitHub,
6 buildPythonPackage,
7 python,
8 pkg-config,
9 setuptools,
10 cython,
11 ninja,
12 meson-python,
13 pyproject-metadata,
14 nix-update-script,
15
16 fontconfig,
17 freetype,
18 libjpeg,
19 libpng,
20 libx11,
21 portmidi,
22 SDL2,
23 SDL2_image,
24 SDL2_mixer,
25 SDL2_ttf,
26 numpy,
27 astroid,
28
29 pygame-gui,
30}:
31
32buildPythonPackage rec {
33 pname = "pygame-ce";
34 version = "2.5.6";
35 pyproject = true;
36
37 src = fetchFromGitHub {
38 owner = "pygame-community";
39 repo = "pygame-ce";
40 tag = version;
41 hash = "sha256-0DNvAs1E6OhN6wTvbMCDt9YAEFoBZp1r7hI4GSnJUl8=";
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 # https://github.com/pygame-community/pygame-ce/pull/3680#issuecomment-3796052119
64 ./skip-failing-tests.patch
65 ];
66
67 postPatch = ''
68 # "pyproject-metadata!=0.9.1" was pinned due to https://github.com/pygame-community/pygame-ce/pull/3395
69 # cython was pinned to fix windows build hangs (pygame-community/pygame-ce/pull/3015)
70 substituteInPlace pyproject.toml \
71 --replace-fail '"pyproject-metadata!=0.9.1",' '"pyproject-metadata",' \
72 --replace-fail '"meson<=1.9.1",' '"meson",' \
73 --replace-fail '"meson-python<=0.18.0",' '"meson-python",' \
74 --replace-fail '"ninja<=1.13.0",' "" \
75 --replace-fail '"astroid<4.0.0",' "" \
76 --replace-fail '"cython<=3.1.4",' '"cython",' \
77 --replace-fail '"sphinx<=8.2.3",' "" \
78 --replace-fail '"sphinx-autoapi<=3.6.0",' ""
79 substituteInPlace buildconfig/config_{unix,darwin}.py \
80 --replace-fail 'from distutils' 'from setuptools._distutils'
81 substituteInPlace src_py/sysfont.py \
82 --replace-fail 'path="fc-list"' 'path="${fontconfig}/bin/fc-list"' \
83 --replace-fail /usr/X11/bin/fc-list ${fontconfig}/bin/fc-list
84 ''
85 + lib.optionalString stdenv.hostPlatform.isDarwin ''
86 # flaky
87 rm test/system_test.py
88 substituteInPlace test/meson.build \
89 --replace-fail "'system_test.py'," ""
90 '';
91
92 nativeBuildInputs = [
93 pkg-config
94 cython
95 setuptools
96 ninja
97 meson-python
98 pyproject-metadata
99 ];
100
101 buildInputs = [
102 freetype
103 libx11
104 libjpeg
105 libpng
106 portmidi
107 SDL2
108 (SDL2_image.override { enableSTB = false; })
109 SDL2_mixer
110 SDL2_ttf
111 astroid
112 ];
113
114 nativeCheckInputs = [
115 numpy
116 ];
117
118 preConfigure = ''
119 ${python.pythonOnBuildForHost.interpreter} -m buildconfig.config
120 '';
121
122 env = {
123 SDL_CONFIG = lib.getExe' (lib.getDev SDL2) "sdl2-config";
124 }
125 // lib.optionalAttrs stdenv.cc.isClang {
126 NIX_CFLAGS_COMPILE = "-Wno-error=incompatible-function-pointer-types";
127 };
128
129 preCheck = ''
130 export HOME=$(mktemp -d)
131 # No audio or video device in test environment
132 export SDL_VIDEODRIVER=dummy
133 export SDL_AUDIODRIVER=disk
134 # traceback for segfaults
135 export PYTHONFAULTHANDLER=1
136 '';
137
138 checkPhase = ''
139 runHook preCheck
140 ${python.interpreter} -m pygame.tests -v --exclude opengl,timing --time_out 300
141 runHook postCheck
142 '';
143
144 pythonImportsCheck = [
145 "pygame"
146 "pygame.camera"
147 "pygame.colordict"
148 "pygame.cursors"
149 "pygame.freetype"
150 "pygame.ftfont"
151 "pygame.locals"
152 "pygame.midi"
153 "pygame.pkgdata"
154 "pygame.sndarray" # requires numpy
155 "pygame.sprite"
156 "pygame.surfarray"
157 "pygame.sysfont"
158 "pygame.version"
159 ];
160
161 passthru.updateScript = nix-update-script { };
162
163 passthru.tests = {
164 inherit pygame-gui;
165 };
166
167 meta = {
168 description = "Pygame Community Edition (CE) - library for multimedia application built on SDL";
169 homepage = "https://pyga.me/";
170 changelog = "https://github.com/pygame-community/pygame-ce/releases/tag/${src.tag}";
171 license = lib.licenses.lgpl21Plus;
172 maintainers = [ lib.maintainers.pbsds ];
173 platforms = lib.platforms.unix;
174 };
175}