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