Subject: [PATCH v2 09/13] gnu: Add python-moderngl-window.

From: Daniel Meißner<[email-masked]>
Date: Wed, 15 Sep 2021 17:25:15 +0200

* gnu/packages/python-xyz.scm (python-moderngl-window): New variable.
---
 gnu/local.mk                                  |  1 +
 .../python-moderngl-window-skip-tests.patch   | 62 +++++++++++++++++++
 gnu/packages/python-xyz.scm                   | 49 +++++++++++++++
 3 files changed, 112 insertions(+)
 create mode 100644 gnu/packages/patches/python-moderngl-window-skip-tests.patch

diff --git a/gnu/local.mk b/gnu/local.mk
index 175e691a63..d738f97ca8 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -1648,6 +1648,7 @@ dist_patch_DATA =						\
   %D%/packages/patches/python-libxml2-utf8.patch		\
   %D%/packages/patches/python-matplotlib-run-under-wayland-gtk3.patch	\
   %D%/packages/patches/python-memcached-syntax-warnings.patch	\
+  %D%/packages/patches/python-moderngl-window-skip-tests.patch  \
   %D%/packages/patches/python-mox3-python3.6-compat.patch	\
   %D%/packages/patches/python-testtools.patch			\
   %D%/packages/patches/python-packaging-test-arch.patch		\
diff --git a/gnu/packages/patches/python-moderngl-window-skip-tests.patch b/gnu/packages/patches/python-moderngl-window-skip-tests.patch
new file mode 100644
index 0000000000..cbfefa6c3a
--- /dev/null
+++ b/gnu/packages/patches/python-moderngl-window-skip-tests.patch
@@ -0,0 +1,62 @@
+Skip tests for optional dependencies
+
+The Python packages pywavefront and trimesh are optional dependencies and not
+yet packaged in Guix but the tests try to load the modules anyway.  Therefore
+skip them.
+
+diff --git a/tests/test_docs.py b/tests/test_docs.py
+index e4a38df..99a2aa0 100644
+--- a/tests/test_docs.py
++++ b/tests/test_docs.py
+@@ -133,20 +133,11 @@ class TestCase(unittest.TestCase):
+ 
+     # --- Loaders : Scene ---
+ 
+-    def test_loaders_wavefront(self):
+-        self.validate('loaders/wavefront.rst', 'moderngl_window.loaders.scene.wavefront', 'Loader')
+-
+     def test_loaders_gltf(self):
+         self.validate('loaders/gltf2.rst', 'moderngl_window.loaders.scene.gltf2', 'Loader')
+ 
+-    def test_loaders_stl(self):
+-        self.validate('loaders/wavefront.rst', 'moderngl_window.loaders.scene.stl', 'Loader')
+-
+     # --- Loaders : Program ---
+ 
+-    def test_loader_single(self):
+-        self.validate('loaders/single.rst', 'moderngl_window.loaders.program.single', 'Loader')
+-
+     def test_loader_separate(self):
+         self.validate('loaders/separate.rst', 'moderngl_window.loaders.program.separate', 'Loader')
+ 
+diff --git a/tests/test_loaders_scene.py b/tests/test_loaders_scene.py
+index c577315..2eef889 100644
+--- a/tests/test_loaders_scene.py
++++ b/tests/test_loaders_scene.py
+@@ -16,16 +16,6 @@ class SceneLoadersTestCase(HeadlessTestCase):
+     window_size = (16, 16)
+     aspect_ratio = 1.0
+ 
+-    def test_wavefront(self):
+-        """Load wavefront file"""
+-        scene = resources.scenes.load(SceneDescription(path='scenes/crate/crate.obj'))
+-        self.assertIsInstance(scene, Scene)
+-
+-    def test_wavefont_not_found(self):
+-        """Ensure ImproperlyConfigured is raised when wavefront is not found"""
+-        with self.assertRaises(ImproperlyConfigured):
+-            resources.scenes.load(SceneDescription(path='scenes/doesnotexist.obj'))
+-
+     def test_gltf(self):
+         """Load standard gltf"""
+         scene = resources.scenes.load(SceneDescription(path='scenes/BoxTextured/glTF/BoxTextured.gltf'))
+@@ -45,7 +35,3 @@ class SceneLoadersTestCase(HeadlessTestCase):
+         """Attempt to load nonexisting gltf"""
+         with self.assertRaises(ImproperlyConfigured):
+             resources.scenes.load(SceneDescription(path='scenes/doesnotexist.gltf'))
+-
+-    def test_stl(self):
+-        scene = resources.scenes.load(SceneDescription(path='scenes/uplink.stl'))
+-        self.assertIsInstance(scene, Scene)
+-- 
+2.33.0
diff --git a/gnu/packages/python-xyz.scm b/gnu/packages/python-xyz.scm
index 3a984eaa68..0d3efe2700 100644
--- a/gnu/packages/python-xyz.scm
+++ b/gnu/packages/python-xyz.scm
@@ -19071,6 +19071,55 @@ Joysticks, OpenGL graphics, loading images and videos, and playing sounds and
 music.  All of this with a friendly Pythonic API that's simple to learn.")
     (license license:bsd-3)))
 
+(define-public python-moderngl-window
+  (package
+   (name "python-moderngl-window")
+   (version "2.4.0")
+   (source (origin
+            (method git-fetch)
+            (uri (git-reference
+                  (url "https://github.com/moderngl/moderngl-window")
+                  (commit version)))
+            (file-name (git-file-name name version))
+            (patches
+             (search-patches "python-moderngl-window-skip-tests.patch"))
+            (sha256
+             (base32
+              "1fvhm6ln3q5kl5m5q3gzfmx1kpyn054fhpcrgpqz8809dxi7pzcv"))))
+   (build-system python-build-system)
+   (arguments
+     '(#:phases
+       (modify-phases %standard-phases
+         (add-before 'check 'prepare-x
+           (lambda _
+             (system "Xvfb :1 &")
+             (setenv "DISPLAY" ":1")))
+         (add-before 'check 'fix-test
+           (lambda _
+             (substitute* '("tests/test_windowconfig.py")
+               (("terrain_Vs.glsl") "terrain_vs.glsl"))))
+         (replace 'check
+           (lambda* (#:key inputs outputs #:allow-other-keys)
+             (add-installed-pythonpath inputs outputs)
+             (invoke "pytest" "tests" ))))))
+   (propagated-inputs
+    `(("python-pillow" ,python-pillow)
+      ("python-pyrr" ,python-pyrr)
+      ("python-numpy" ,python-numpy)
+      ("python-moderngl" ,python-moderngl)
+      ("python-pyglet" ,python-pyglet)))
+   (native-inputs
+    `(("python-pytest" ,python-pytest)
+      ("xorg-server" ,xorg-server-for-tests)))
+   (home-page "https://github.com/moderngl/moderngl-window")
+   (synopsis "Cross-platform utility library for ModernGL")
+   (description "This ModernGL utility library simplifies window creation and
+resource loading.  You can create a window for ModernGL using pyglet, pygame,
+PySide2, GLFW, SDL2, PyQt5 or tkinter.  Events are unified into a single event
+system.  Resource loading includes loading of 2D textures/texture arrays,
+shaders and objects/scenes.")
+   (license license:expat)))
+
 (define-public python-screeninfo
   (package
    (name "python-screeninfo")
-- 
2.33.0