From ffa9e79f29257b23cfefafb7ff036438b9068e2c Mon Sep 17 00:00:00 2001 From: Philip Taron Date: Wed, 23 Jul 2025 12:05:31 -0700 Subject: [PATCH] python3Packages.imageio: fix build, enable most tests With 624897829bf52e44f4d1277200357e2ae7244a55, the new parenthesization logic exposes a coding defect in `imageio` where they do a string test vs. `"not needs_internet"` instead of something parsed. Instead of fixing that, we can actually enable almost all of the tests in this module with a command-line flag which points to a FOD of https://github.com/imageio/test_images repository. There are a few more tests that need to be disabled as well; I opened a PR against imageio to fix these. I also removed the `libgl-path.patch` in favor of a simple `--replace-fail`. --- .../python-modules/imageio/default.nix | 36 +++++++++++++++---- .../python-modules/imageio/libgl-path.patch | 13 ------- 2 files changed, 30 insertions(+), 19 deletions(-) delete mode 100644 pkgs/development/python-modules/imageio/libgl-path.patch diff --git a/pkgs/development/python-modules/imageio/default.nix b/pkgs/development/python-modules/imageio/default.nix index cdf5a30e332f..8ce623caad31 100644 --- a/pkgs/development/python-modules/imageio/default.nix +++ b/pkgs/development/python-modules/imageio/default.nix @@ -4,7 +4,6 @@ buildPythonPackage, fetchFromGitHub, isPyPy, - replaceVars, # build-system setuptools, @@ -26,9 +25,21 @@ # tests pytestCheckHook, + gitMinimal, fsspec, }: +let + test_images = fetchFromGitHub { + owner = "imageio"; + repo = "test_images"; + rev = "f676c96b1af7e04bb1eed1e4551e058eb2f14acd"; + leaveDotGit = true; + hash = "sha256-Kh8DowuhcCT5C04bE5yJa2C+efilLxP0AM31XjnHRf4="; + }; + libgl = "${libGL.out}/lib/libGL${stdenv.hostPlatform.extensions.sharedLibrary}"; +in + buildPythonPackage rec { pname = "imageio"; version = "2.37.0"; @@ -41,11 +52,10 @@ buildPythonPackage rec { hash = "sha256-/nxJxZrTYX7F2grafIWwx9SyfR47ZXyaUwPHMEOdKkI="; }; - patches = lib.optionals (!stdenv.hostPlatform.isDarwin) [ - (replaceVars ./libgl-path.patch { - libgl = "${libGL.out}/lib/libGL${stdenv.hostPlatform.extensions.sharedLibrary}"; - }) - ]; + postPatch = lib.optionalString (!stdenv.hostPlatform.isDarwin) '' + substituteInPlace tests/test_core.py \ + --replace-fail 'ctypes.util.find_library("GL")' '"${libgl}"' + ''; build-system = [ setuptools ]; @@ -77,14 +87,28 @@ buildPythonPackage rec { nativeCheckInputs = [ fsspec + gitMinimal psutil pytestCheckHook ] ++ fsspec.optional-dependencies.github ++ lib.flatten (builtins.attrValues optional-dependencies); + pytestFlags = [ "--test-images=file://${test_images}" ]; + + # These should have had `needs_internet` mark applied but don't so far. + # See https://github.com/imageio/imageio/pull/1142 + disabledTests = [ + "test_read_stream" + "test_uri_reading" + "test_trim_filter" + ]; + disabledTestMarks = [ "needs_internet" ]; + # These tests require the old and vulnerable freeimage binaries; skip. + disabledTestPaths = [ "tests/test_freeimage.py" ]; + preCheck = '' export IMAGEIO_USERDIR=$(mktemp -d) export HOME=$(mktemp -d) diff --git a/pkgs/development/python-modules/imageio/libgl-path.patch b/pkgs/development/python-modules/imageio/libgl-path.patch deleted file mode 100644 index f2a2bbfa093d..000000000000 --- a/pkgs/development/python-modules/imageio/libgl-path.patch +++ /dev/null @@ -1,13 +0,0 @@ -diff --git a/tests/test_core.py b/tests/test_core.py -index 2cdbb3a..032974c 100644 ---- a/tests/test_core.py -+++ b/tests/test_core.py -@@ -129,7 +129,7 @@ def test_findlib2(): - open(os.path.join(fi_dir, "notalib.test.so"), "wb") - - # Loading libs -- gllib = ctypes.util.find_library("GL") -+ gllib = "@libgl@" - core.load_lib([gllib], []) - # Fail - raises(ValueError, core.load_lib, [], []) # Nothing given