nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at python-updates 151 lines 3.9 kB view raw
1{ 2 lib, 3 stdenv, 4 buildPythonPackage, 5 fetchFromGitHub, 6 7 # build-system 8 hatchling, 9 10 # preBuild 11 wgpu-native, 12 13 # dependencies 14 cffi, 15 rubicon-objc, 16 sniffio, 17 18 # optional dependency 19 glfw, 20 21 # docs 22 sphinx-rtd-theme, 23 sphinxHook, 24 25 # tests 26 anyio, 27 imageio, 28 numpy, 29 psutil, 30 pypng, 31 pytest, 32 rendercanvas, 33 ruff, 34 trio, 35 36 # passthru 37 testers, 38 wgpu-py, 39}: 40buildPythonPackage rec { 41 pname = "wgpu-py"; 42 version = "0.29.0"; 43 pyproject = true; 44 45 src = fetchFromGitHub { 46 owner = "pygfx"; 47 repo = "wgpu-py"; 48 tag = "v${version}"; 49 hash = "sha256-drXO3NHIuK34tbOZjxOCz1lnlcrfx6mADZ2WlEc9vDU="; 50 }; 51 52 postPatch = 53 # `requests` is only used to fetch a copy of `wgpu-native` via `tools/hatch_build.py`. 54 # As we retrieve `wgpu-native` from nixpkgs instead, none of this is needed, and 55 # remove an extra dependency. 56 '' 57 substituteInPlace pyproject.toml \ 58 --replace-fail 'requires = ["requests", "hatchling"]' 'requires = ["hatchling"]' \ 59 --replace-fail '[tool.hatch.build.targets.wheel.hooks.custom]' "" \ 60 --replace-fail 'path = "tools/hatch_build.py"' "" 61 '' 62 # Skip the compute_textures example during testing, as it uses `imageio` to 63 # retrieve an image of an astronaut, which touches the network. 64 # Additionally skip the imgui_backend_sea and imgui_basic_example examples during testing, 65 # as they depend on imgui_bundle which has not been packaged for nixpkgs. 66 + '' 67 substituteInPlace examples/{compute_textures.py,imgui_backend_sea.py,imgui_basic_example.py} \ 68 --replace-fail 'import wgpu' 'import wgpu # run_example = false' 69 ''; 70 71 # wgpu-py expects to have an appropriately named wgpu-native library in wgpu/resources 72 preBuild = '' 73 ln -s ${wgpu-native}/lib/libwgpu_native${stdenv.hostPlatform.extensions.library} \ 74 wgpu/resources/libwgpu_native-release${stdenv.hostPlatform.extensions.library} 75 ''; 76 77 build-system = [ hatchling ]; 78 79 dependencies = 80 # Runtime dependencies 81 [ 82 cffi 83 sniffio 84 # https://github.com/pygfx/wgpu-py/blob/ff8db1772f7f94bf2a3e82989f5d296d2ddbb923/pyproject.toml#L16 85 (rendercanvas.overrideAttrs { doInstallCheck = false; }) 86 ] 87 # Required only on darwin 88 ++ lib.optionals stdenv.hostPlatform.isDarwin [ 89 rubicon-objc 90 ]; 91 92 optional-dependencies = { 93 # jupyter = [ jupyter_rfb ] not in nixpkgs 94 glfw = [ glfw ]; 95 # imgui = ["imgui-bundle>=1.2.1"] not in nixpkgs 96 97 docs = [ 98 sphinxHook 99 sphinx-rtd-theme 100 ]; 101 }; 102 103 pythonRemoveDeps = [ "requests" ]; 104 105 pythonImportsCheck = [ "wgpu" ]; 106 107 nativeCheckInputs = [ 108 anyio 109 imageio 110 numpy 111 psutil 112 pypng 113 pytest 114 # break circular dependency cycle 115 (rendercanvas.overrideAttrs { doInstallCheck = false; }) 116 ruff 117 trio 118 ]; 119 120 # Tests break in Linux CI due to wgpu being unable to find any adapters. 121 # Ordinarily, this would be fixed in an approach similar to `pkgs/by-name/wg/wgpu-native/examples.nix`'s 122 # usage of `runtimeInputs` and `makeWrapperArgs`. 123 # Unfortunately, as this is a Python module without a `mainProgram`, `makeWrapperArgs` will not apply here, 124 # as there is no "script" to wrap. 125 doCheck = stdenv.hostPlatform.isDarwin; 126 127 installCheckPhase = '' 128 runHook preInstallCheck 129 130 pytest tests -k "not test_render_timestamps_inside_encoder" 131 pytest examples 132 pytest tests_mem 133 134 runHook postInstallCheck 135 ''; 136 137 passthru.tests.version = testers.testVersion { 138 package = wgpu-py; 139 command = "python3 -c 'import wgpu; print(wgpu.__version__)'"; 140 }; 141 142 meta = { 143 description = "WebGPU for Python"; 144 homepage = "https://github.com/pygfx/wgpu-py"; 145 changelog = "https://github.com/pygfx/wgpu-py/blob/${src.tag}/CHANGELOG.md"; 146 147 platforms = lib.platforms.all; 148 license = lib.licenses.bsd2; 149 maintainers = [ lib.maintainers.bengsparks ]; 150 }; 151}