1{ lib, stdenv
2, buildPythonPackage
3, fetchPypi
4, pkgs
5, pillow
6}:
7
8buildPythonPackage rec {
9 pname = "pyopengl";
10 version = "3.1.6";
11 format = "setuptools";
12
13 src = fetchPypi {
14 pname = "PyOpenGL";
15 inherit version;
16 hash = "sha256-jqbIdzkn7adAW//G9buTvoFWmnsFyMrFDNlOlp3OXic=";
17 };
18
19 propagatedBuildInputs = [ pillow ];
20
21 patchPhase = let
22 ext = stdenv.hostPlatform.extensions.sharedLibrary; in lib.optionalString (!stdenv.isDarwin) ''
23 # Theses lines are patching the name of dynamic libraries
24 # so pyopengl can find them at runtime.
25 substituteInPlace OpenGL/platform/glx.py \
26 --replace "'GL'" "'${pkgs.libGL}/lib/libGL${ext}'" \
27 --replace "'GLU'" "'${pkgs.libGLU}/lib/libGLU${ext}'" \
28 --replace "'glut'" "'${pkgs.freeglut}/lib/libglut${ext}'" \
29 --replace "'GLESv1_CM'," "'${pkgs.libGL}/lib/libGLESv1_CM${ext}'," \
30 --replace "'GLESv2'," "'${pkgs.libGL}/lib/libGLESv2${ext}',"
31 substituteInPlace OpenGL/platform/egl.py \
32 --replace "('OpenGL','GL')" "('${pkgs.libGL}/lib/libOpenGL${ext}', '${pkgs.libGL}/lib/libGL${ext}')" \
33 --replace "'GLU'," "'${pkgs.libGLU}/lib/libGLU${ext}'," \
34 --replace "'glut'," "'${pkgs.freeglut}/lib/libglut${ext}'," \
35 --replace "'GLESv1_CM'," "'${pkgs.libGL}/lib/libGLESv1_CM${ext}'," \
36 --replace "'GLESv2'," "'${pkgs.libGL}/lib/libGLESv2${ext}'," \
37 --replace "'EGL'," "'${pkgs.libGL}/lib/libEGL${ext}',"
38 substituteInPlace OpenGL/platform/darwin.py \
39 --replace "'OpenGL'," "'${pkgs.libGL}/lib/libGL${ext}'," \
40 --replace "'GLUT'," "'${pkgs.freeglut}/lib/libglut${ext}',"
41 # TODO: patch 'gle' in OpenGL/platform/egl.py
42 '' + ''
43 # https://github.com/NixOS/nixpkgs/issues/76822
44 # pyopengl introduced a new "robust" way of loading libraries in 3.1.4.
45 # The later patch of the filepath does not work anymore because
46 # pyopengl takes the "name" (for us: the path) and tries to add a
47 # few suffix during its loading phase.
48 # The following patch put back the "name" (i.e. the path) in the
49 # list of possible files.
50 substituteInPlace OpenGL/platform/ctypesloader.py \
51 --replace "filenames_to_try = []" "filenames_to_try = [name]"
52 '';
53
54 # Need to fix test runner
55 # Tests have many dependencies
56 # Extension types could not be found.
57 # Should run test suite from $out/${python.sitePackages}
58 doCheck = false; # does not affect pythonImportsCheck
59
60 # OpenGL looks for libraries during import, making this a somewhat decent test of the flaky patching above.
61 pythonImportsCheck = "OpenGL";
62
63 meta = with lib; {
64 homepage = "https://pyopengl.sourceforge.net/";
65 description = "PyOpenGL, the Python OpenGL bindings";
66 longDescription = ''
67 PyOpenGL is the cross platform Python binding to OpenGL and
68 related APIs. The binding is created using the standard (in
69 Python 2.5) ctypes library, and is provided under an extremely
70 liberal BSD-style Open-Source license.
71 '';
72 license = "BSD-style";
73 platforms = platforms.mesaPlatforms;
74 };
75
76
77}