diff mbox series

[bug#50505,v3,03/12] gnu: Add python-glcontext.

Message ID 20220101235155.5754-4-daniel.meissner-i4k@ruhr-uni-bochum.de
State New
Headers show
Series Add python-manim and its missing dependencies | expand

Commit Message

Daniel Meißner Jan. 1, 2022, 11:51 p.m. UTC
* gnu/packages/python-xyz.scm (python-glcontext): New variable.
---
 gnu/packages/python-xyz.scm | 53 +++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)

Comments

Liliana Marie Prikler Jan. 2, 2022, 12:31 a.m. UTC | #1
Am Sonntag, dem 02.01.2022 um 00:51 +0100 schrieb Daniel Meißner:
> * gnu/packages/python-xyz.scm (python-glcontext): New variable.
> ---
>  gnu/packages/python-xyz.scm | 53 +++++++++++++++++++++++++++++++++++++
>  1 file changed, 53 insertions(+)
> 
> diff --git a/gnu/packages/python-xyz.scm b/gnu/packages/python-xyz.scm
> index deff85e797..d8e6fa070e 100644
> --- a/gnu/packages/python-xyz.scm
> +++ b/gnu/packages/python-xyz.scm
> @@ -19555,6 +19555,59 @@ (define-public python-pyopengl-accelerate
>      (description
>       "This is the Cython-coded accelerator module for PyOpenGL.")))
>  
> +(define-public python-glcontext
> +  (package
> +   (name "python-glcontext")
> +   (version "2.3.4")
> +   (source
> +    (origin
> +     (method git-fetch)
> +     (uri (git-reference
> +           (url "https://github.com/moderngl/glcontext")
> +           (commit version)))
> +     (file-name (git-file-name name version))
> +     (sha256
> +      (base32
> +       "1m2zkl696vqmgrd5k1c5kl0krk6qgjgsz88qhahwva0l40bswvhp"))))
> +   (build-system python-build-system)
> +   (arguments
> +    '(#:phases
> +      (modify-phases %standard-phases
> +        (add-before 'build 'fix-lib-paths
> +          (lambda* (#:key inputs outputs #:allow-other-keys)
> +            (let ((mesa (assoc-ref inputs "mesa"))
> +                  (libx11 (assoc-ref inputs "libx11")))
> +              (substitute* '("glcontext/x11.cpp" "glcontext/egl.cpp")
> +                (("\"libGL.so\"")
> +                 (string-append "\"" mesa  "/lib/libGL.so\""))
> +                (("\"libEGL.so\"")
> +                 (string-append "\"" mesa "/lib/libEGL.so\""))
> +                (("\"libX11.so\"")
> +                 (string-append "\"" libx11 "/lib/libX11.so\"")))
> +              (substitute* '("glcontext/__init__.py")
> +                (("find_library\\('GL'\\)")
> +                 (string-append "'" mesa "/lib/libGL.so'"))
> +                (("find_library\\('EGL'\\)")
> +                 (string-append "'" mesa "/lib/libEGL.so'"))
> +                (("find_library\\(\"X11\"\\)")
> +                 (string-append "'" libx11 "/lib/libX11.so'"))))))
Use of (assoc-ref inputs input) in new code is discouraged in favour of
this-package-input or search-input-file.  Leo Famulari started a thread
on which of the two to prefer over in guix-devel [1].  My personal
opinion is that search-input-file ought to be fine here.

[1] https://lists.gnu.org/archive/html/guix-devel/2021-12/msg00240.html
diff mbox series

Patch

diff --git a/gnu/packages/python-xyz.scm b/gnu/packages/python-xyz.scm
index deff85e797..d8e6fa070e 100644
--- a/gnu/packages/python-xyz.scm
+++ b/gnu/packages/python-xyz.scm
@@ -19555,6 +19555,59 @@  (define-public python-pyopengl-accelerate
     (description
      "This is the Cython-coded accelerator module for PyOpenGL.")))
 
+(define-public python-glcontext
+  (package
+   (name "python-glcontext")
+   (version "2.3.4")
+   (source
+    (origin
+     (method git-fetch)
+     (uri (git-reference
+           (url "https://github.com/moderngl/glcontext")
+           (commit version)))
+     (file-name (git-file-name name version))
+     (sha256
+      (base32
+       "1m2zkl696vqmgrd5k1c5kl0krk6qgjgsz88qhahwva0l40bswvhp"))))
+   (build-system python-build-system)
+   (arguments
+    '(#:phases
+      (modify-phases %standard-phases
+        (add-before 'build 'fix-lib-paths
+          (lambda* (#:key inputs outputs #:allow-other-keys)
+            (let ((mesa (assoc-ref inputs "mesa"))
+                  (libx11 (assoc-ref inputs "libx11")))
+              (substitute* '("glcontext/x11.cpp" "glcontext/egl.cpp")
+                (("\"libGL.so\"")
+                 (string-append "\"" mesa  "/lib/libGL.so\""))
+                (("\"libEGL.so\"")
+                 (string-append "\"" mesa "/lib/libEGL.so\""))
+                (("\"libX11.so\"")
+                 (string-append "\"" libx11 "/lib/libX11.so\"")))
+              (substitute* '("glcontext/__init__.py")
+                (("find_library\\('GL'\\)")
+                 (string-append "'" mesa "/lib/libGL.so'"))
+                (("find_library\\('EGL'\\)")
+                 (string-append "'" mesa "/lib/libEGL.so'"))
+                (("find_library\\(\"X11\"\\)")
+                 (string-append "'" libx11 "/lib/libX11.so'"))))))
+        (replace 'check
+          (lambda* (#:key inputs outputs tests? #:allow-other-keys)
+            (when tests?
+              (system "Xvfb :1 &")
+              (setenv "DISPLAY" ":1")
+              (add-installed-pythonpath inputs outputs)
+              (invoke "pytest" "tests")))))))
+   (inputs
+    (list libx11 mesa))
+   (native-inputs
+    (list xorg-server-for-tests python-pytest python-psutil))
+   (home-page "https://github.com/moderngl/glcontext")
+   (synopsis "Portable OpenGL Context for ModernGL")
+   (description "Python-glcontext is a library providing an OpenGL
+implementation for ModernGL on multiple platforms.")
+   (license license:expat)))
+
 (define-public python-rencode
   (package
    (name "python-rencode")