Merge: matrix-synapse: 1.122.0 -> 1.123.0 (#378018)
[NixPkgs.git] / pkgs / development / python-modules / pygame / default.nix
blobf4da6a9f001c5f9a341aaa44d4142ff4ff5ae89f
2   lib,
3   stdenv,
4   buildPythonPackage,
5   fetchFromGitHub,
6   substituteAll,
7   fontconfig,
8   python,
10   # build-system
11   cython,
12   setuptools,
14   # nativeBuildInputs
15   SDL2,
16   pkg-config,
18   # buildInputs
19   freetype,
20   libjpeg,
21   libpng,
22   libX11,
23   portmidi,
24   SDL2_image,
25   SDL2_mixer,
26   SDL2_ttf,
29 buildPythonPackage rec {
30   pname = "pygame";
31   version = "2.6.1";
32   pyproject = true;
34   src = fetchFromGitHub {
35     owner = "pygame";
36     repo = "pygame";
37     tag = version;
38     # Unicode file names lead to different checksums on HFS+ vs. other
39     # filesystems because of unicode normalisation. The documentation
40     # has such files and will be removed.
41     hash = "sha256-paSDF0oPogq0g0HSDRagGu0OfsqIku6q4GGAMveGntk=";
42     postFetch = "rm -rf $out/docs/reST";
43   };
45   patches = [
46     # Patch pygame's dependency resolution to let it find build inputs
47     (substituteAll {
48       src = ./fix-dependency-finding.patch;
49       buildinputs_include = builtins.toJSON (
50         builtins.concatMap (dep: [
51           "${lib.getDev dep}/"
52           "${lib.getDev dep}/include"
53           "${lib.getDev dep}/include/SDL2"
54         ]) buildInputs
55       );
56       buildinputs_lib = builtins.toJSON (
57         builtins.concatMap (dep: [
58           "${lib.getLib dep}/"
59           "${lib.getLib dep}/lib"
60         ]) buildInputs
61       );
62     })
64     # mixer queue test returns busy queue when it shouldn't
65     ./skip-mixer-test.patch
66   ];
68   postPatch = ''
69     substituteInPlace src_py/sysfont.py \
70       --replace-fail 'path="fc-list"' 'path="${fontconfig}/bin/fc-list"' \
71       --replace-fail /usr/X11/bin/fc-list ${fontconfig}/bin/fc-list
72   '';
74   build-system = [
75     cython
76     setuptools
77   ];
79   nativeBuildInputs = [
80     SDL2
81     pkg-config
82   ];
84   buildInputs = [
85     freetype
86     libjpeg
87     libpng
88     libX11
89     portmidi
90     SDL2
91     SDL2_image
92     SDL2_mixer
93     SDL2_ttf
94   ];
96   preConfigure = ''
97     ${python.pythonOnBuildForHost.interpreter} buildconfig/config.py
98   '';
100   env = lib.optionalAttrs stdenv.cc.isClang {
101     NIX_CFLAGS_COMPILE = "-Wno-error=incompatible-function-pointer-types";
102   };
104   checkPhase = ''
105     runHook preCheck
107     # No audio or video device in test environment
108     export SDL_VIDEODRIVER=dummy
109     export SDL_AUDIODRIVER=disk
111     ${python.interpreter} -m pygame.tests -v \
112       --exclude opengl,timing \
113       --time_out 300
115     runHook postCheck
116   '';
117   pythonImportsCheck = [ "pygame" ];
119   meta = {
120     description = "Python library for games";
121     homepage = "https://www.pygame.org/";
122     changelog = "https://github.com/pygame/pygame/releases/tag/${src.tag}";
123     license = lib.licenses.lgpl21Plus;
124     maintainers = with lib.maintainers; [ emilytrau ];
125     platforms = lib.platforms.unix;
126   };