1{
2 lib,
3 buildPythonPackage,
4 pythonOlder,
5 fetchFromGitHub,
6 fetchpatch,
7 setuptools,
8 freetype-py,
9 imageio,
10 networkx,
11 numpy,
12 pillow,
13 pyglet,
14 pyopengl,
15 scipy,
16 six,
17 trimesh,
18 pytestCheckHook,
19}:
20
21buildPythonPackage rec {
22 pname = "pyrender";
23 version = "0.1.45";
24 pyproject = true;
25
26 disabled = pythonOlder "3.5";
27
28 src = fetchFromGitHub {
29 owner = "mmatl";
30 repo = "pyrender";
31 tag = version;
32 hash = "sha256-V2G8QWXMxFDQpT4XDOJhIFI2V9VhDQCaXYBb/QVLxgM=";
33 };
34
35 patches = [
36 (fetchpatch {
37 # yet to be tagged
38 name = "relax-pyopengl.patch";
39 url = "https://github.com/mmatl/pyrender/commit/7c613e8aed7142df9ff40767a8f10b7a19b6255c.patch";
40 hash = "sha256-SXRV9RC3PfQGjjIQ+n97HZrSDPae3rAHnTBiHXSFLaY=";
41 })
42 # fix on numpy 2.0 (np.infty -> np.inf)
43 # https://github.com/mmatl/pyrender/pull/292
44 (fetchpatch {
45 name = "fix-numpy2.patch";
46 url = "https://github.com/mmatl/pyrender/commit/5408c7b45261473511d2399ab625efe11f0b6991.patch";
47 hash = "sha256-RIv6lMpxMmops5Tb1itzYdT7GkhPScVWslBXITR3IBM=";
48 })
49 ];
50
51 # trimesh too new
52 # issue: https://github.com/mmatl/pyrender/issues/203
53 # mega pr: https://github.com/mmatl/pyrender/pull/216
54 # relevant pr commit: https://github.com/mmatl/pyrender/pull/216/commits/5069aeb957addff8919f05dc9be4040f55bff329
55 # the commit does not apply as a patch when cherry picked, hence the substituteInPlace
56 postPatch = ''
57 substituteInPlace tests/unit/test_meshes.py \
58 --replace-fail \
59 "bm = trimesh.load('tests/data/WaterBottle.glb').dump()[0]" \
60 'bm = trimesh.load("tests/data/WaterBottle.glb").geometry["WaterBottle"]'
61 '';
62
63 nativeBuildInputs = [ setuptools ];
64
65 dependencies = [
66 freetype-py
67 imageio
68 networkx
69 numpy
70 pillow
71 pyglet
72 pyopengl
73 scipy
74 six
75 trimesh
76 ];
77
78 env.PYOPENGL_PLATFORM = "egl"; # enables headless rendering during check
79
80 nativeCheckInputs = [ pytestCheckHook ];
81
82 disabledTestPaths = [
83 # does not work inside sandbox, no GPU
84 "tests/unit/test_offscreen.py"
85 ];
86
87 pythonImportsCheck = [ "pyrender" ];
88
89 meta = with lib; {
90 homepage = "https://pyrender.readthedocs.io/en/latest/";
91 description = "Easy-to-use glTF 2.0-compliant OpenGL renderer for visualization of 3D scenes";
92 license = licenses.mit;
93 maintainers = with maintainers; [ pbsds ];
94 };
95}