From 5bcc970cf96d85ec8c3c7d2eabd32cce9f3ef604 Mon Sep 17 00:00:00 2001 From: Peder Bergebakken Sundt Date: Tue, 16 Apr 2024 09:02:08 +0200 Subject: [PATCH] python311Packages.pygame-ce: init at 2.4.1 fixes #250417 --- .../python-modules/pygame-ce/default.nix | 123 ++++++++++++++++++ .../pygame-ce/fix-dependency-finding.patch | 41 ++++++ .../pygame-ce/skip-surface-tests.patch | 26 ++++ pkgs/top-level/python-packages.nix | 6 + 4 files changed, 196 insertions(+) create mode 100644 pkgs/development/python-modules/pygame-ce/default.nix create mode 100644 pkgs/development/python-modules/pygame-ce/fix-dependency-finding.patch create mode 100644 pkgs/development/python-modules/pygame-ce/skip-surface-tests.patch diff --git a/pkgs/development/python-modules/pygame-ce/default.nix b/pkgs/development/python-modules/pygame-ce/default.nix new file mode 100644 index 0000000000000..a476ecd58b850 --- /dev/null +++ b/pkgs/development/python-modules/pygame-ce/default.nix @@ -0,0 +1,123 @@ +{ stdenv +, lib +, substituteAll +, fetchFromGitHub +, buildPythonPackage +, pythonOlder +, python +, pkg-config +, setuptools +, cython + +, AppKit +, fontconfig +, freetype +, libjpeg +, libpng +, libX11 +, portmidi +, SDL2 +, SDL2_image +, SDL2_mixer +, SDL2_ttf +}: + +buildPythonPackage rec { + pname = "pygame-ce"; + version = "2.4.1"; + pyproject = true; + + disabled = pythonOlder "3.6"; + + src = fetchFromGitHub { + owner = "pygame-community"; + repo = "pygame-ce"; + rev = "refs/tags/${version}"; + hash = "sha256-4Ky+QEUsQ0odcwEETk0yGECs7CcJQthhavboOnMDvF8="; + # Unicode file cause different checksums on HFS+ vs. other filesystems + postFetch = "rm -rf $out/docs/reST"; + }; + + patches = [ + (substituteAll { + src = ./fix-dependency-finding.patch; + buildinputs_include = builtins.toJSON (builtins.concatMap (dep: [ + "${lib.getDev dep}/" + "${lib.getDev dep}/include" + "${lib.getDev dep}/include/SDL2" + ]) buildInputs); + buildinputs_lib = builtins.toJSON (builtins.concatMap (dep: [ + "${lib.getLib dep}/" + "${lib.getLib dep}/lib" + ]) buildInputs); + }) + # Skip tests that should be disabled without video driver + ./skip-surface-tests.patch + ]; + + postPatch = '' + substituteInPlace buildconfig/config_{unix,darwin}.py \ + --replace-fail 'from distutils' 'from setuptools._distutils' + substituteInPlace src_py/sysfont.py \ + --replace-fail 'path="fc-list"' 'path="${fontconfig}/bin/fc-list"' \ + --replace-fail /usr/X11/bin/fc-list ${fontconfig}/bin/fc-list + '' + lib.optionalString stdenv.isDarwin '' + # flaky + rm test/system_test.py + ''; + + nativeBuildInputs = [ + pkg-config + cython + setuptools + ]; + + buildInputs = [ + freetype + libX11 + libjpeg + libpng + portmidi + SDL2 + SDL2_image + SDL2_mixer + SDL2_ttf + ] ++ lib.optionals stdenv.isDarwin [ + AppKit + ]; + + preConfigure = '' + ${python.pythonOnBuildForHost.interpreter} buildconfig/config.py + ''; + + env = { + SDL_CONFIG = "${SDL2.dev}/bin/sdl2-config"; + } // lib.optionalAttrs stdenv.cc.isClang { + NIX_CFLAGS_COMPILE = "-Wno-error=incompatible-function-pointer-types"; + }; + + preCheck = '' + export HOME=$(mktemp -d) + # No audio or video device in test environment + export SDL_VIDEODRIVER=dummy + export SDL_AUDIODRIVER=disk + ''; + + checkPhase = '' + runHook preCheck + ${python.interpreter} -m pygame.tests -v --exclude opengl,timing --time_out 300 + runHook postCheck + ''; + + pythonImportsCheck = [ + "pygame" + ]; + + meta = with lib; { + description = "Pygame Community Edition (CE) - library for multimedia application built on SDL"; + homepage = "https://pyga.me/"; + license = licenses.lgpl21Plus; + maintainers = with maintainers; [ pbsds ]; + platforms = platforms.unix; + }; +} diff --git a/pkgs/development/python-modules/pygame-ce/fix-dependency-finding.patch b/pkgs/development/python-modules/pygame-ce/fix-dependency-finding.patch new file mode 100644 index 0000000000000..5e39dff135752 --- /dev/null +++ b/pkgs/development/python-modules/pygame-ce/fix-dependency-finding.patch @@ -0,0 +1,41 @@ +diff --git a/buildconfig/config_darwin.py b/buildconfig/config_darwin.py +index 9503ea70..d0d3ab6e 100644 +--- a/buildconfig/config_darwin.py ++++ b/buildconfig/config_darwin.py +@@ -140,16 +140,8 @@ def main(auto_config=False): + ]) + + print('Hunting dependencies...') +- incdirs = ['/usr/local/include', '/opt/homebrew/include'] +- incdirs.extend(['/usr/local/include/SDL2', '/opt/homebrew/include/SDL2', '/opt/local/include/SDL2']) +- +- incdirs.extend([ +- #'/usr/X11/include', +- '/opt/local/include', +- '/opt/local/include/freetype2/freetype'] +- ) +- #libdirs = ['/usr/local/lib', '/usr/X11/lib', '/opt/local/lib'] +- libdirs = ['/usr/local/lib', '/opt/local/lib', '/opt/homebrew/lib'] ++ incdirs = @buildinputs_include@ ++ libdirs = @buildinputs_lib@ + + for d in DEPS: + if isinstance(d, (list, tuple)): +diff --git a/buildconfig/config_unix.py b/buildconfig/config_unix.py +index 3eba5b5c..53cc6233 100644 +--- a/buildconfig/config_unix.py ++++ b/buildconfig/config_unix.py +@@ -240,11 +240,8 @@ def main(auto_config=False): + if not DEPS[0].found: + raise RuntimeError('Unable to run "sdl-config". Please make sure a development version of SDL is installed.') + +- incdirs = [] +- libdirs = [] +- for extrabase in extrabases: +- incdirs += [extrabase + d for d in origincdirs] +- libdirs += [extrabase + d for d in origlibdirs] ++ incdirs = @buildinputs_include@ ++ libdirs = @buildinputs_lib@ + + for arg in DEPS[0].cflags.split(): + if arg[:2] == '-I': diff --git a/pkgs/development/python-modules/pygame-ce/skip-surface-tests.patch b/pkgs/development/python-modules/pygame-ce/skip-surface-tests.patch new file mode 100644 index 0000000000000..21d9c9060f3b8 --- /dev/null +++ b/pkgs/development/python-modules/pygame-ce/skip-surface-tests.patch @@ -0,0 +1,26 @@ +diff --git a/test/surface_test.py b/test/surface_test.py +index 5ce78b6e..8b8f7ed5 100644 +--- a/test/surface_test.py ++++ b/test/surface_test.py +@@ -1091,6 +1091,10 @@ class GeneralSurfaceTests(unittest.TestCase): + finally: + pygame.display.quit() + ++ @unittest.skipIf( ++ os.environ.get("SDL_VIDEODRIVER") == "dummy", ++ 'requires a non-"dummy" SDL_VIDEODRIVER', ++ ) + def test_convert_init(self): + """Ensure initialization exceptions are raised + for surf.convert().""" +@@ -1118,6 +1122,10 @@ class GeneralSurfaceTests(unittest.TestCase): + finally: + pygame.display.quit() + ++ @unittest.skipIf( ++ os.environ.get("SDL_VIDEODRIVER") == "dummy", ++ 'requires a non-"dummy" SDL_VIDEODRIVER', ++ ) + def test_convert_alpha_init(self): + """Ensure initialization exceptions are raised + for surf.convert_alpha().""" diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix index 8ba934720ea54..133f2c61afb7e 100644 --- a/pkgs/top-level/python-packages.nix +++ b/pkgs/top-level/python-packages.nix @@ -10978,6 +10978,12 @@ self: super: with self; { SDL2_image = pkgs.SDL2_image_2_0; }; + pygame-ce = callPackage ../development/python-modules/pygame-ce { + inherit (pkgs.darwin.apple_sdk.frameworks) AppKit; + SDL2_image = pkgs.SDL2_image_2_0; + SDL2_mixer = pkgs.SDL2_mixer_2_0; + }; + pygame-sdl2 = callPackage ../development/python-modules/pygame-sdl2 { }; pygame-gui = callPackage ../development/python-modules/pygame-gui { };