unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
* [bug#55893] [PATCH] gnu: python-xyz: Add python-pysdl2.
@ 2022-06-10 18:09 Jean Pierre De Jesus DIAZ via Guix-patches via
  2022-06-10 22:13 ` Maxime Devos
  0 siblings, 1 reply; 4+ messages in thread
From: Jean Pierre De Jesus DIAZ via Guix-patches via @ 2022-06-10 18:09 UTC (permalink / raw)
  To: 55893

[-- Attachment #1: Type: text/plain, Size: 146 bytes --]

Adds the PySDL2 package published on PyPi.

The package definition sets a fixed path for SDL2 libraries instead of relying on `LD_LIBRARY_PATH`.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-gnu-python-xyz-Add-python-pysdl2.patch --]
[-- Type: text/x-patch; name=0001-gnu-python-xyz-Add-python-pysdl2.patch, Size: 4641 bytes --]

From f983d332d6f541e019aa68eddbc14525c549b948 Mon Sep 17 00:00:00 2001
Message-Id: <f983d332d6f541e019aa68eddbc14525c549b948.1654884220.git.me@jeandudey.tech>
From: Jean-Pierre De Jesus DIAZ <me@jeandudey.tech>
Date: Fri, 10 Jun 2022 19:57:31 +0200
Subject: [PATCH] gnu: python-xyz: Add python-pysdl2.

* gnu/packages/python-xyz.scm (python-pysdl2): Add package.
---
 gnu/packages/python-xyz.scm | 73 +++++++++++++++++++++++++++++++++++++
 1 file changed, 73 insertions(+)

diff --git a/gnu/packages/python-xyz.scm b/gnu/packages/python-xyz.scm
index 92adf74393..062d8ce96b 100644
--- a/gnu/packages/python-xyz.scm
+++ b/gnu/packages/python-xyz.scm
@@ -123,6 +123,7 @@
 ;;; Copyright © 2022 Jai Vetrivelan <jaivetrivelan@gmail.com>
 ;;; Copyright © 2022 Artyom V. Poptsov <poptsov.artyom@gmail.com>
 ;;; Copyright © 2022 Paul A. Patience <paul@apatience.com>
+;;; Copyright © 2022 Jean-Pierre De Jesus DIAZ <me@jeandudey.tech>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -29447,3 +29448,75 @@ (define-public python-musical-scales
 @url{https://en.wikipedia.org/wiki/List_of_musical_scales_and_modes, found on
 Wikipedia}.")
     (license license:expat)))
+
+(define-public python-pysdl2
+  (package
+    (name "python-pysdl2")
+    (version "0.9.11")
+    (source (origin
+              (method url-fetch)
+              (uri (pypi-uri "PySDL2" version))
+              (sha256
+               (base32
+                "19id1qswgcj4v4j5kn49shq1xxx3slhjpm0102w87mczsdbi1rck"))))
+    (build-system python-build-system)
+    (arguments
+      `(#:tests? #f ; Requires /dev/dri, OpenGL module, etc.
+        #:phases
+        (modify-phases %standard-phases
+          (add-after 'unpack 'patch-paths
+            (lambda* (#:key inputs #:allow-other-keys)
+              (substitute* "sdl2/dll.py"
+                ; Disable pysdl2-dll. Not needed.
+                (("prepath = os\\.getenv\\('PYSDL2_DLL_PATH'\\)")
+                 "prepath = \"system\"")
+                (("^import sdl2dll$") "")
+                (("postpath = os\\.getenv\\('PYSDL2_DLL_PATH'\\)")
+                 "postpath = \"system\"")
+                (("DLL\\(.*, os\\.getenv\\(\"PYSDL2_DLL_PATH\"\\)\\)")
+                 (string-append "DLL(\"SDL2\", [\"SDL2\", \"SDL2-2.0\","
+                                "\"SDL2-2.0.0\"], "
+                                "\""
+                                (dirname
+                                  (search-input-file inputs
+                                                     "/lib/libSDL2.so"))
+                                "\""
+                                ")")))
+              (substitute* "sdl2/sdlimage.py"
+                (("os\\.getenv\\(\"PYSDL2_DLL_PATH\"\\)")
+                 (string-append "\""
+                                (dirname
+                                  (search-input-file inputs
+                                                     "/lib/libSDL2_image.so"))
+                                "\"")))
+              (substitute* "sdl2/sdlgfx.py"
+                (("os\\.getenv\\(\"PYSDL2_DLL_PATH\"\\)")
+                 (string-append "\""
+                                (dirname
+                                  (search-input-file inputs
+                                                     "/lib/libSDL2_gfx.so"))
+                                "\"")))
+              (substitute* "sdl2/sdlmixer.py"
+                (("os\\.getenv\\(\"PYSDL2_DLL_PATH\"\\)")
+                 (string-append "\""
+                                (dirname
+                                  (search-input-file inputs
+                                                     "/lib/libSDL2_mixer.so"))
+                                "\"")))
+              (substitute* "sdl2/sdlttf.py"
+                (("os\\.getenv\\(\"PYSDL2_DLL_PATH\"\\)")
+                 (string-append "\""
+                                (dirname
+                                  (search-input-file inputs
+                                                     "/lib/libSDL2_ttf.so"))
+                                "\""))))))))
+    (native-inputs
+      (list sdl2 sdl2-image sdl2-gfx sdl2-mixer sdl2-ttf))
+    (home-page "https://github.com/py-sdl/py-sdl2")
+    (synopsis "Python ctypes wrapper around SDL2")
+    (description "PySDL2 is a pure Python wrapper around the @code{SDL2},
+@code{SDL2_mixer}, @code{SDL2_image}, @code{SDL2_ttf}, and @code{SDL2_gfx}
+libraries. Instead of relying on C code, it uses the built-in ctypes module to
+interface with SDL2, and provides simple Python classes and wrappers for
+common SDL2 functionality.")
+    (license license:cc0)))
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [bug#55893] [PATCH] gnu: python-xyz: Add python-pysdl2.
  2022-06-10 18:09 [bug#55893] [PATCH] gnu: python-xyz: Add python-pysdl2 Jean Pierre De Jesus DIAZ via Guix-patches via
@ 2022-06-10 22:13 ` Maxime Devos
       [not found]   ` <WFbr_G-n9Q7OJKBaVB4sZRY28Zj9_4Hufh4Q9UsdtQoqWBCfY1aaBFPak48wHnrBQYHQx-vR4MvCNwjHy8gEaMqjyUdWgthP-xsEOvvINWI=@jeandudey.tech>
  0 siblings, 1 reply; 4+ messages in thread
From: Maxime Devos @ 2022-06-10 22:13 UTC (permalink / raw)
  To: Jean Pierre De Jesus DIAZ, 55893

[-- Attachment #1: Type: text/plain, Size: 2516 bytes --]

Jean Pierre De Jesus DIAZ via Guix-patches via schreef op vr 10-06-2022
om 18:09 [+0000]:
> +    (native-inputs
> +      (list sdl2 sdl2-image sdl2-gfx sdl2-mixer sdl2-ttf))

These need to be in 'inputs', not native-inputs -- their shared
libraries will actually be executed when python-pysdl2 executed, which
can only work if they are compiled for the same architecture as python-
pysdl2 is compiled for (that's what 'inputs' means; for 'native-
inputs', it would be compiled for the architecture on which python-
pysdl2 is compiled, not the architecture it is compiled for). 

> +    (synopsis "Python ctypes wrapper around SDL2")

ctypes sounds like an implementation detail not relevant to users of
python-pysdl2, maybe: ‘Python bindings around SDL2’?

> +                ; Disable pysdl2-dll. Not needed.

Nitpick: the convention is two ;;, not a single ;.

> +                 (string-append "DLL(\"SDL2\", [\"SDL2\", \"SDL2
2.0\","
> +                                "\"SDL2-2.0.0\"], "
> +                                "\""

Thee strings above can be combined.

> +                                (dirname
> +                                  (search-input-file inputs
> +                                                     "/lib/libSDL2.so"))

Indentations seems a bit wonky -- if this is to not make the line too long,
maybe try putting a line break between the 'string-append' and the "DLL(..."?

> +                                "\""
> +                                ")")))

These strings too.

> +    (arguments
> +      `(#:tests? #f ; Requires /dev/dri, OpenGL module, etc.
> +        #:phases
> +        (modify-phases %standard-phases

Recommended style (considered more readable):

  (list #:tests? #f ; etcetera
        #:phases
        #~(modify-phases [etcetera]))

(Many other packages don't do it like that yet, it has only
be discovered recently -- I would point you at IRC logs but
I'm currently offline.)

Also, don't put the package definition simply at the end, that
leads to merge conflicts.  Instead, try keep packages
alphabetical ... which is difficult here, because it has
historically neglected alphebetical ordening, but maybe right
after python-py would be a good fit?

Otherwise, the package definition LGTM from a distance, though
I only looked at the definition, I didn't check the source code
(for simplifying the substitute*-ions or checking for malware)
or build it.

Greetings,
Maxime.

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 260 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [bug#55893] [PATCH] gnu: python-xyz: Add python-pysdl2.
       [not found]   ` <WFbr_G-n9Q7OJKBaVB4sZRY28Zj9_4Hufh4Q9UsdtQoqWBCfY1aaBFPak48wHnrBQYHQx-vR4MvCNwjHy8gEaMqjyUdWgthP-xsEOvvINWI=@jeandudey.tech>
@ 2022-06-14 23:13     ` Jean Pierre De Jesus DIAZ via Guix-patches via
  2022-06-17 13:35       ` bug#55893: " Ludovic Courtès
  0 siblings, 1 reply; 4+ messages in thread
From: Jean Pierre De Jesus DIAZ via Guix-patches via @ 2022-06-14 23:13 UTC (permalink / raw)
  To: 55893@debbugs.gnu.org

[-- Attachment #1: Type: text/plain, Size: 2730 bytes --]

Applied the suggestions to the code and relocated the definition of the package on the `python-py` packages section.

Thanks for the review.

> ------- Original Message -------
> On Saturday, June 11th, 2022 at 12:13 AM, Maxime Devos maximedevos@telenet.be wrote:
>
>
>
> > Jean Pierre De Jesus DIAZ via Guix-patches via schreef op vr 10-06-2022
> > om 18:09 [+0000]:
> >
> > > + (native-inputs
> > > + (list sdl2 sdl2-image sdl2-gfx sdl2-mixer sdl2-ttf))
> >
> > These need to be in 'inputs', not native-inputs -- their shared
> > libraries will actually be executed when python-pysdl2 executed, which
> > can only work if they are compiled for the same architecture as python-
> > pysdl2 is compiled for (that's what 'inputs' means; for 'native-
> > inputs', it would be compiled for the architecture on which python-
> > pysdl2 is compiled, not the architecture it is compiled for).
> >
> > > + (synopsis "Python ctypes wrapper around SDL2")
> >
> > ctypes sounds like an implementation detail not relevant to users of
> > python-pysdl2, maybe: ‘Python bindings around SDL2’?
> >
> > > + ; Disable pysdl2-dll. Not needed.
> >
> > Nitpick: the convention is two ;;, not a single ;.
> >
> > > + (string-append "DLL(\"SDL2\", [\"SDL2\", \"SDL2
> >
> > 2.0\","
> >
> > > + "\"SDL2-2.0.0\"], "
> > > + "\""
> >
> > Thee strings above can be combined.
> >
> > > + (dirname
> > > + (search-input-file inputs
> > > + "/lib/libSDL2.so"))
> >
> > Indentations seems a bit wonky -- if this is to not make the line too long,
> > maybe try putting a line break between the 'string-append' and the "DLL(..."?
> >
> > > + "\""
> > > + ")")))
> >
> > These strings too.
> >
> > > + (arguments
> > > + `(#:tests? #f ; Requires /dev/dri, OpenGL module, etc.
> > > + #:phases
> > > + (modify-phases %standard-phases
> >
> > Recommended style (considered more readable):
> >
> > (list #:tests? #f ; etcetera
> > #:phases
> > #~(modify-phases [etcetera]))
> >
> > (Many other packages don't do it like that yet, it has only
> > be discovered recently -- I would point you at IRC logs but
> > I'm currently offline.)
> >
> > Also, don't put the package definition simply at the end, that
> > leads to merge conflicts. Instead, try keep packages
> > alphabetical ... which is difficult here, because it has
> > historically neglected alphebetical ordening, but maybe right
> > after python-py would be a good fit?
> >
> > Otherwise, the package definition LGTM from a distance, though
> > I only looked at the definition, I didn't check the source code
> > (for simplifying the substitute*-ions or checking for malware)
> > or build it.
> >
> > Greetings,
> > Maxime.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-gnu-python-xyz-Add-python-pysdl2.patch --]
[-- Type: text/x-patch; name=0001-gnu-python-xyz-Add-python-pysdl2.patch, Size: 4261 bytes --]

From 542a138fa26eec2c25cb7743be612a2d7f4a502d Mon Sep 17 00:00:00 2001
Message-Id: <542a138fa26eec2c25cb7743be612a2d7f4a502d.1655242487.git.me@jeandudey.tech>
From: Jean-Pierre De Jesus DIAZ <me@jeandudey.tech>
Date: Fri, 10 Jun 2022 19:57:31 +0200
Subject: [PATCH] gnu: python-xyz: Add python-pysdl2.

* gnu/packages/python-xyz.scm (python-pysdl2): Add package.
---
 gnu/packages/python-xyz.scm | 66 +++++++++++++++++++++++++++++++++++++
 1 file changed, 66 insertions(+)

diff --git a/gnu/packages/python-xyz.scm b/gnu/packages/python-xyz.scm
index f37ca731d5..dbc662465b 100644
--- a/gnu/packages/python-xyz.scm
+++ b/gnu/packages/python-xyz.scm
@@ -123,6 +123,7 @@
 ;;; Copyright © 2022 Jai Vetrivelan <jaivetrivelan@gmail.com>
 ;;; Copyright © 2022 Artyom V. Poptsov <poptsov.artyom@gmail.com>
 ;;; Copyright © 2022 Paul A. Patience <paul@apatience.com>
+;;; Copyright © 2022 Jean-Pierre De Jesus DIAZ <me@jeandudey.tech>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -3900,6 +3901,71 @@ (define-public python-jinja2-time
 templates.  A format string can be provided to control the output.")
     (license license:expat)))
 
+(define-public python-pysdl2
+  (package
+    (name "python-pysdl2")
+    (version "0.9.11")
+    (source (origin
+              (method url-fetch)
+              (uri (pypi-uri "PySDL2" version))
+              (sha256
+               (base32
+                "19id1qswgcj4v4j5kn49shq1xxx3slhjpm0102w87mczsdbi1rck"))))
+    (build-system python-build-system)
+    (arguments
+      (list #:tests? #f ;; Requires /dev/dri, OpenGL module, etc.
+            #:phases
+            #~(modify-phases %standard-phases
+                (add-after 'unpack 'patch-paths
+                  (lambda* (#:key inputs #:allow-other-keys)
+                    (substitute* "sdl2/dll.py"
+                    ;; Disable pysdl2-dll. It can't be packaged on GNU Guix
+                    ;; as it duplicates an existing package (sdl2).
+                    (("prepath = os\\.getenv\\('PYSDL2_DLL_PATH'\\)")
+                     "prepath = \"system\"")
+                    (("^import sdl2dll$") "")
+                    (("postpath = os\\.getenv\\('PYSDL2_DLL_PATH'\\)")
+                     "postpath = \"system\"")
+                    (("DLL\\(.*, os\\.getenv\\(\"PYSDL2_DLL_PATH\"\\)\\)")
+                     (string-append
+                       "DLL(\"SDL2\", [\"SDL2\", \"SDL2-2.0\", \"SDL2-2.0.0\"], \""
+                       (dirname (search-input-file inputs "/lib/libSDL2.so"))
+                       "\")")))
+              (substitute* "sdl2/sdlimage.py"
+                (("os\\.getenv\\(\"PYSDL2_DLL_PATH\"\\)")
+                 (string-append
+                   "\""
+                   (dirname (search-input-file inputs "/lib/libSDL2_image.so"))
+                   "\"")))
+              (substitute* "sdl2/sdlgfx.py"
+                (("os\\.getenv\\(\"PYSDL2_DLL_PATH\"\\)")
+                 (string-append
+                   "\""
+                   (dirname (search-input-file inputs "/lib/libSDL2_gfx.so"))
+                   "\"")))
+              (substitute* "sdl2/sdlmixer.py"
+                (("os\\.getenv\\(\"PYSDL2_DLL_PATH\"\\)")
+                 (string-append
+                   "\""
+                   (dirname (search-input-file inputs "/lib/libSDL2_mixer.so"))
+                   "\"")))
+              (substitute* "sdl2/sdlttf.py"
+                (("os\\.getenv\\(\"PYSDL2_DLL_PATH\"\\)")
+                 (string-append
+                   "\""
+                   (dirname (search-input-file inputs "/lib/libSDL2_ttf.so"))
+                   "\""))))))))
+    (inputs
+      (list sdl2 sdl2-image sdl2-gfx sdl2-mixer sdl2-ttf))
+    (home-page "https://github.com/py-sdl/py-sdl2")
+    (synopsis "Python bindings around SDL2")
+    (description "PySDL2 is a pure Python wrapper around the @code{SDL2},
+@code{SDL2_mixer}, @code{SDL2_image}, @code{SDL2_ttf}, and @code{SDL2_gfx}
+libraries. Instead of relying on C code, it uses the built-in ctypes module to
+interface with SDL2, and provides simple Python classes and wrappers for
+common SDL2 functionality.")
+    (license license:cc0)))
+
 (define-public python-pystache
   (package
     (name "python-pystache")
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* bug#55893: [PATCH] gnu: python-xyz: Add python-pysdl2.
  2022-06-14 23:13     ` Jean Pierre De Jesus DIAZ via Guix-patches via
@ 2022-06-17 13:35       ` Ludovic Courtès
  0 siblings, 0 replies; 4+ messages in thread
From: Ludovic Courtès @ 2022-06-17 13:35 UTC (permalink / raw)
  To: Jean Pierre De Jesus DIAZ; +Cc: 55893@debbugs.gnu.org

Hi Jean-Pierre,

Jean Pierre De Jesus DIAZ <me@jeandudey.tech> skribis:

> From 542a138fa26eec2c25cb7743be612a2d7f4a502d Mon Sep 17 00:00:00 2001
> Message-Id: <542a138fa26eec2c25cb7743be612a2d7f4a502d.1655242487.git.me@jeandudey.tech>
> From: Jean-Pierre De Jesus DIAZ <me@jeandudey.tech>
> Date: Fri, 10 Jun 2022 19:57:31 +0200
> Subject: [PATCH] gnu: python-xyz: Add python-pysdl2.
>
> * gnu/packages/python-xyz.scm (python-pysdl2): Add package.

Applied, thank you, and thanks Maxime for reviewing!

Ludo’.




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-06-17 13:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-10 18:09 [bug#55893] [PATCH] gnu: python-xyz: Add python-pysdl2 Jean Pierre De Jesus DIAZ via Guix-patches via
2022-06-10 22:13 ` Maxime Devos
     [not found]   ` <WFbr_G-n9Q7OJKBaVB4sZRY28Zj9_4Hufh4Q9UsdtQoqWBCfY1aaBFPak48wHnrBQYHQx-vR4MvCNwjHy8gEaMqjyUdWgthP-xsEOvvINWI=@jeandudey.tech>
2022-06-14 23:13     ` Jean Pierre De Jesus DIAZ via Guix-patches via
2022-06-17 13:35       ` bug#55893: " Ludovic Courtès

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).