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