Subject: Re: [bug#37714] Add renpy package

From: Leo Prikler <[email-masked]>
Date: Sun, 20 Oct 2019 14:09:54 +0200

Am Samstag, den 19.10.2019, 22:59 +0200 schrieb Leo Prikler:
> - 0003 splits renpy into the python package python2-renpy and the
> program itself. This makes the build rules a little easier to read,
> even if they themselves did not change much.
Now also with a package description for python2-renpy.
> - 0004 fixes the launcher (mostly). One can now set a project
> directory, create projects, launch created projects and open project
> directories in the default file explorer. However, setting the editor
> (and hence launching one) still does not work.
Adjusted accordingly.
- 0005 uses pre-install renpy to compile the games. I've also updated
the comments on #:tests? that are inaccurate as of 0002.

Regards,

Leo
From 21170c387d4d1363123f86dcd1a0891ae226c9ab Mon Sep 17 00:00:00 2001
From: Comrade Yuri <yuri@nijino>
Date: Sat, 19 Oct 2019 18:34:18 +0200
Subject: [PATCH 3/5] gnu: split renpy into library and program

gnu/packages/game-development: (python2-renpy): New variable.
(renpy): Split off python module into python2-renpy.
Adjust inputs accordingly.
---
 gnu/packages/game-development.scm | 79 +++++++++++++++++--------------
 1 file changed, 44 insertions(+), 35 deletions(-)

diff --git a/gnu/packages/game-development.scm b/gnu/packages/game-development.scm
index ebebe96328..2110518f0b 100644
--- a/gnu/packages/game-development.scm
+++ b/gnu/packages/game-development.scm
@@ -1021,9 +1021,9 @@ While it aims to be used as a drop-in replacement, it appears to be
 developed mainly for Ren'py.")
       (license (list license:lgpl2.1 license:zlib)))))
 
-(define-public renpy
+(define-public python2-renpy
   (package
-    (name "renpy")
+    (name "python2-renpy")
     (version "7.3.5")
     (source
      (origin
@@ -1033,10 +1033,7 @@ developed mainly for Ren'py.")
        (sha256 (base32 "1anr5cfbvbsbik4v4rvrkdkciwhg700k4lydfbs4n85raimz9mw4"))))
     (build-system python-build-system)
     (arguments
-     `(;; TODO: We currently can't run renpy inside the guixbuilder and
-       ;; hence can't test it or use it inside the build.
-       ;; Perhaps we should set up an X server.
-       #:tests? #f
+     `(#:tests? #f ; non-trivial tests require a more complete Ren'py
        #:python ,python-2
        #:phases
        (modify-phases %standard-phases
@@ -1063,7 +1060,6 @@ developed mainly for Ren'py.")
                 (invoke "python" "-m" "compileall" "renpy"))
               (getcwd) args)
              #t))
-         ;; TODO: Here we might use a post-build phase to compile the games.
 
          (replace 'install
            (lambda args
@@ -1083,14 +1079,43 @@ developed mainly for Ren'py.")
                   (copy-recursively "renpy"
                                     (string-append out site "/renpy"))))
               (getcwd) args)
-             #t))
+             #t)))))
+    (inputs
+     `(("ffmpeg" ,ffmpeg)
+       ("freetype" ,freetype)
+       ("glew" ,glew)
+       ("libpng" ,libpng)
+       ("python2-pygame" ,python2-pygame-sdl2)
+       ("sdl-union"
+        ,(sdl-union (list sdl2 sdl2-image sdl2-mixer sdl2-ttf)))))
+    (native-inputs
+     `(("python2-cython" ,python2-cython)))
+    (home-page "http://www.renpy.org/")
+    (synopsis "Ren'py python module")
+    (description "This package contains the shared libraries and Python modules
+of renpy.")
+    (license license:expat)))
 
-         (add-after 'install 'install-renpy
+(define-public renpy
+  (package
+    (inherit python2-renpy)
+    (name "renpy")
+    (version "7.3.5")
+    (build-system python-build-system)
+    (arguments
+     `(;; TODO: We currently can't run renpy inside the guixbuilder.
+       ;; Perhaps we should set up an X server.
+       #:tests? #f
+       #:python ,python-2
+       #:phases
+       (modify-phases %standard-phases
+         ;; TODO: Here we would use ren'py to compile the games.
+         (delete 'build)
+         (replace 'install
            (lambda* (#:key inputs outputs #:allow-other-keys)
              ;; Here we install our custom renpy program.
              ;; After finishing this step, "out" will have the following:
              ;; |-- bin/renpy
-             ;; |-- lib/pythonX.Y/site-packages/renpy
              ;; `-- share/renpy ; i.e. path_to_renpy_base()
              ;;     `-- common
              ;;
@@ -1112,12 +1137,7 @@ developed mainly for Ren'py.")
              ;;     |-- renpy     ; Ren'py python code (source + compiled)
              ;;     |-- Super Awesome Game.py
              ;;     `-- Super Awesome Game.sh
-             (let* ((pygame (assoc-ref inputs "python2-pygame"))
-                    (site (string-append "/lib/python"
-                                         ,(version-major+minor
-                                           (package-version python-2))
-                                         "/site-packages"))
-                    (out (assoc-ref outputs "out"))
+             (let* ((out (assoc-ref outputs "out"))
                     (bin/renpy (string-append out "/bin/renpy")))
                (mkdir-p (string-append out "/bin"))
                (copy-recursively "renpy/common"
@@ -1178,14 +1198,7 @@ if __name__ == \"__main__\":
     main()
 "
                            (string-append out "/share/renpy"))))
-
-               ;; Since we already have all variables available here, let's
-               ;; also wrap the program.
                (chmod bin/renpy #o755)
-               (wrap-program bin/renpy
-                             `("PYTHONPATH" prefix
-                               (,(string-append out site)
-                                ,(string-append pygame site))))
                #t)))
 
          (add-after 'install 'install-games
@@ -1219,21 +1232,17 @@ if __name__ == \"__main__\":
              (install-renpy-game #:output (assoc-ref outputs "tutorial")
                                  #:game "tutorial")
              #t))
-         ;; We already do our own wrapping during 'install-renpy, therefore we
-         ;; no longer need a wrap phase.
-         (delete 'wrap))))
+         (replace 'wrap
+           (lambda* (#:key inputs outputs #:allow-other-keys)
+             (wrap-program (string-append (assoc-ref outputs "out")
+                                          "/bin/renpy")
+               `("PYTHONPATH" = (,(getenv "PYTHONPATH"))))
+             #t)))))
     (inputs
-     `(("ffmpeg" ,ffmpeg)
-       ("freetype" ,freetype)
-       ("glew" ,glew)
-       ("libpng" ,libpng)
-       ("python2-pygame" ,python2-pygame-sdl2)
-       ("sdl-union"
-        ,(sdl-union (list sdl2 sdl2-image sdl2-mixer sdl2-ttf)))))
+     `(("python2-pygame" ,python2-pygame-sdl2)
+       ("python2-renpy" ,python2-renpy)))
     (outputs
      (list "out" "launcher" "tutorial" "the-question"))
-    (native-inputs
-     `(("python2-cython" ,python2-cython)))
     (home-page "http://www.renpy.org/")
     (synopsis "Visual Novel Engine")
     (description "Ren'Py is a visual novel engine -- used by thousands of
-- 
2.23.0

From d72b88651d66d0cdfe2a0bd94fde810b8ac7c73a Mon Sep 17 00:00:00 2001
From: Comrade Yuri <yuri@nijino>
Date: Sat, 19 Oct 2019 20:50:41 +0200
Subject: [PATCH 4/5] gnu: fix renpy-launcher

* /gnu/packages/game-development: (python2-renpy): Patch xdg-open.
(renpy): Merge "out" and "launcher". Patch python, renpy binary and xdg-open.
---
 gnu/packages/game-development.scm | 52 +++++++++++++++++++++++++------
 1 file changed, 42 insertions(+), 10 deletions(-)

diff --git a/gnu/packages/game-development.scm b/gnu/packages/game-development.scm
index 2110518f0b..a57cddfbcb 100644
--- a/gnu/packages/game-development.scm
+++ b/gnu/packages/game-development.scm
@@ -1037,6 +1037,12 @@ developed mainly for Ren'py.")
        #:python ,python-2
        #:phases
        (modify-phases %standard-phases
+         (add-after 'unpack 'fix-commands
+           (lambda _
+             (substitute* "renpy/editor.py"
+               (("xdg-open")
+                (which "xdg-open")))
+             #t))
          (add-after 'set-paths 'set-build-vars
            (lambda* (#:key inputs #:allow-other-keys)
              (setenv "RENPY_CYTHON"
@@ -1089,7 +1095,8 @@ developed mainly for Ren'py.")
        ("sdl-union"
         ,(sdl-union (list sdl2 sdl2-image sdl2-mixer sdl2-ttf)))))
     (native-inputs
-     `(("python2-cython" ,python2-cython)))
+     `(("python2-cython" ,python2-cython)
+       ("xdg-utils" ,xdg-utils)))
     (home-page "http://www.renpy.org/")
     (synopsis "Ren'py python module")
     (description "This package contains the shared libraries and Python modules
@@ -1109,6 +1116,28 @@ of renpy.")
        #:python ,python-2
        #:phases
        (modify-phases %standard-phases
+         (add-after 'unpack 'fix-commands
+           (lambda* (#:key outputs #:allow-other-keys)
+             (substitute* "launcher/game/choose_directory.rpy"
+               (("/usr/bin/python") (which "python2")))
+             (substitute* "launcher/game/front_page.rpy"
+               (("xdg-open")
+                (which "xdg-open")))
+             (substitute* "launcher/game/project.rpy"
+               (("cmd = \\[ executable, \"-EO\", sys.argv\\[0\\] \\]")
+                (string-append "cmd = [ \"" (assoc-ref outputs "out")
+                               "/bin/renpy\" ]"))
+               ;; Projects are still created in the usual style, so we need
+               ;; to adjust the path.
+               (("cmd.append\\(self.path\\)")
+                "cmd.append(self.path + \"/game\")"))
+             #t))
+         (add-after 'unpack 'drop-game-from-paths
+           (lambda _
+             (substitute* (list "launcher/game/gui7.rpy"
+                                "launcher/game/gui7/images.py")
+               ((", \"game\",") ","))
+             #t))
          ;; TODO: Here we would use ren'py to compile the games.
          (delete 'build)
          (replace 'install
@@ -1119,10 +1148,10 @@ of renpy.")
              ;; `-- share/renpy ; i.e. path_to_renpy_base()
              ;;     `-- common
              ;;
-             ;; Note that common is also a de facto unused subdirectory of
-             ;; lib/pythonX.Y/site-packages/renpy. On other systems,
-             ;; renpy_base would point to site-packages or even somewhere in
-             ;; /opt. The former approach is not as straightforward as it seems
+             ;; Note that common is also a de facto unused directory in
+             ;; python2-renpy. On other systems, renpy_base would point to
+             ;; site-packages or even somewhere in /opt.
+             ;; The former approach is not as straightforward as it seems
              ;; -- it causes renpy to load files twice for some weird reason --
              ;; and the latter is impossible on Guix. Hence the detour through
              ;; share/renpy and the custom renpy program.
@@ -1142,6 +1171,8 @@ of renpy.")
                (mkdir-p (string-append out "/bin"))
                (copy-recursively "renpy/common"
                                  (string-append out "/share/renpy/common"))
+               (copy-recursively "gui"
+                                 (string-append out "/share/renpy/gui"))
 
                (call-with-output-file bin/renpy
                  (lambda (port)
@@ -1188,8 +1219,8 @@ structure.\"\"\", file=sys.stderr)
 The basedir is the directory, in which .rpy files live -- usually the 'game'
 subdirectory of a game packaged by Ren'py.
 
-If you want the Ren'py launcher, use renpy-launcher from renpy:launcher
-instead.\"\"\", file=sys.stderr)
+If you want the Ren'py launcher, use renpy-launcher instead.\"\"\",
+              file=sys.stderr)
         sys.exit()
 
     renpy.bootstrap.bootstrap(renpy_base)
@@ -1222,7 +1253,7 @@ if __name__ == \"__main__\":
                              share)))
                  (chmod launcher #o755)))
 
-             (install-renpy-game #:output (assoc-ref outputs "launcher")
+             (install-renpy-game #:output (assoc-ref outputs "out")
                                  #:game "launcher")
 
              (install-renpy-game #:output (assoc-ref outputs "the-question")
@@ -1239,10 +1270,11 @@ if __name__ == \"__main__\":
                `("PYTHONPATH" = (,(getenv "PYTHONPATH"))))
              #t)))))
     (inputs
-     `(("python2-pygame" ,python2-pygame-sdl2)
+     `(("python2-tkinter" ,python-2 "tk")
+       ("python2-pygame" ,python2-pygame-sdl2)
        ("python2-renpy" ,python2-renpy)))
     (outputs
-     (list "out" "launcher" "tutorial" "the-question"))
+     (list "out" "tutorial" "the-question"))
     (home-page "http://www.renpy.org/")
     (synopsis "Visual Novel Engine")
     (description "Ren'Py is a visual novel engine -- used by thousands of
-- 
2.23.0

From 9866ea5245979ccb61a0a71499e268b0234d92ff Mon Sep 17 00:00:00 2001
From: Comrade Yuri <yuri@nijino>
Date: Sun, 20 Oct 2019 14:02:19 +0200
Subject: [PATCH 5/5] gnu: compile Ren'py games

* /gnu/packages/game-development: (python2-renpy) [arguments]: Update comment
on #:tests?
(renpy) [arguments]: Ditto.
[start-xserver]: New phase.
[build]: New phase.
[inputs]: Add xorg-server.
---
 gnu/packages/game-development.scm | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/gnu/packages/game-development.scm b/gnu/packages/game-development.scm
index a57cddfbcb..10111ebf1c 100644
--- a/gnu/packages/game-development.scm
+++ b/gnu/packages/game-development.scm
@@ -1033,7 +1033,7 @@ developed mainly for Ren'py.")
        (sha256 (base32 "1anr5cfbvbsbik4v4rvrkdkciwhg700k4lydfbs4n85raimz9mw4"))))
     (build-system python-build-system)
     (arguments
-     `(#:tests? #f ; non-trivial tests require a more complete Ren'py
+     `(#:tests? #f ; Ren'py doesn't seem to package tests
        #:python ,python-2
        #:phases
        (modify-phases %standard-phases
@@ -1066,7 +1066,6 @@ developed mainly for Ren'py.")
                 (invoke "python" "-m" "compileall" "renpy"))
               (getcwd) args)
              #t))
-
          (replace 'install
            (lambda args
              (apply
@@ -1110,9 +1109,7 @@ of renpy.")
     (version "7.3.5")
     (build-system python-build-system)
     (arguments
-     `(;; TODO: We currently can't run renpy inside the guixbuilder.
-       ;; Perhaps we should set up an X server.
-       #:tests? #f
+     `(#:tests? #f ; see python2-renpy
        #:python ,python-2
        #:phases
        (modify-phases %standard-phases
@@ -1138,8 +1135,19 @@ of renpy.")
                                 "launcher/game/gui7/images.py")
                ((", \"game\",") ","))
              #t))
-         ;; TODO: Here we would use ren'py to compile the games.
-         (delete 'build)
+         (add-before 'build 'start-xserver
+           (lambda* (#:key inputs #:allow-other-keys)
+             (let ((xorg-server (assoc-ref inputs "xorg-server")))
+               (setenv "HOME" (getcwd))
+               (system (format #f "~a/bin/Xvfb :1 &" xorg-server))
+               (setenv "DISPLAY" ":1")
+               #t)))
+         (replace 'build
+           (lambda _
+             (invoke "python" "renpy.py" "launcher" "quit")
+             (invoke "python" "renpy.py" "the_question" "quit")
+             (invoke "python" "renpy.py" "tutorial" "quit")
+             #t))
          (replace 'install
            (lambda* (#:key inputs outputs #:allow-other-keys)
              ;; Here we install our custom renpy program.
@@ -1272,7 +1280,8 @@ if __name__ == \"__main__\":
     (inputs
      `(("python2-tkinter" ,python-2 "tk")
        ("python2-pygame" ,python2-pygame-sdl2)
-       ("python2-renpy" ,python2-renpy)))
+       ("python2-renpy" ,python2-renpy)
+       ("xorg-server" ,xorg-server)))
     (outputs
      (list "out" "tutorial" "the-question"))
     (home-page "http://www.renpy.org/")
-- 
2.23.0