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