Subject: [PATCH] * gnu/packages/web.scm (brython): New variable.

From: jgart <[email-masked]>
Date: Mon, 5 Jul 2021 15:48:14 -0400

From: LibreMiami <[email-masked]>

Co-authored-by: Andrea Pierré <[email-masked]>
Co-authored-by: jgart <[email-masked]>
Co-authored-by: Léo Le Bouter <[email-masked]>
Co-authored-by: Ryan Prior <[email-masked]>
---
 gnu/packages/python-web.scm | 48 +++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)

diff --git a/gnu/packages/python-web.scm b/gnu/packages/python-web.scm
index e4d1326fb8..9b692c2ade 100644
--- a/gnu/packages/python-web.scm
+++ b/gnu/packages/python-web.scm
@@ -329,6 +329,54 @@ communicate with each other, and positioned as an asynchronous successor to
 WSGI.  This package includes libraries for implementing ASGI servers.")
     (license license:bsd-3)))
 
+(define-public brython
+  (package
+    (name "brython")
+    (version "3.9.5")
+    (source
+      (origin
+        (method git-fetch)
+        (uri (git-reference
+              (url "https://github.com/brython-dev/brython")
+              (commit version)))
+        (file-name (git-file-name name version))
+        (sha256
+          (base32
+            "0ikxhvgy1zdg8zrdx2bajp1v7r9dhk6v9jan20i05ahvm9s8gfd6"))))
+    (build-system python-build-system)
+    (native-inputs
+     `(("python" ,python)))
+    (arguments
+     `(#:tests? #f ; tests require npm packages
+       #:phases
+       (modify-phases %standard-phases
+         (replace 'build
+           (lambda* (#:key outputs #:allow-other-keys)
+             ;; Write access is required for minifying javascript files.
+             (for-each make-file-writable
+                (find-files "." "\\.js$"))
+
+             ;; Patch build scripts to reference source directory properly.
+             (substitute* (find-files "scripts" "\\.py$")
+               (("os\\.path\\.dirname\\(os\\.getcwd\\(\\)\\)")
+                (string-append "\"" (getcwd) "\"")))
+
+             (invoke "python3" "scripts/make_dist.py")
+             #t))
+         (replace 'install
+           (lambda args
+             ;; setup.py is within 'setup' subdirectory
+             (with-directory-excursion "setup"
+               (invoke "python3" "setup.py" "sdist")
+               (apply (assoc-ref %standard-phases 'install) args))
+             #t)))))
+    (home-page "http://brython.info")
+    (synopsis "Run python code in a web browser")
+    (description
+"@code{Brython} is a compliant implementation of Python 3 that allows
+writing end-user applications in Python that run in the browser.")
+    (license license:bsd-3)))
+
 (define-public python-css-html-js-minify
   (package
     (name "python-css-html-js-minify")
-- 
2.31.1