Subject: [bug#35598] [PATCH v2] gnu: Add python-mesa.

From: [email-masked]
Date: Sun, 28 May 2023 23:21:02 +0200

From: Calvin Pritchard <[email-masked]>

* gnu/packages/python-xyz.scm (python-mesa). New variable.

Co-authored-by: Jelle Licht <[email-masked]>

---

Changes in v2:
- Drop all dependency patches, as those packages now exist
- Use pyproject-build-system
- Reworked to modern packaging standards
- Update mesage package version to 1.2.1.

 gnu/packages/python-xyz.scm | 63 +++++++++++++++++++++++++++++++++++++
 1 file changed, 63 insertions(+)

diff --git a/gnu/packages/python-xyz.scm b/gnu/packages/python-xyz.scm
index f7e3f6f538..be89df2fa1 100644
--- a/gnu/packages/python-xyz.scm
+++ b/gnu/packages/python-xyz.scm
@@ -2305,6 +2305,69 @@ (define-public python-license-expression
 conventions and aliases in the same expression.")
     (license license:gpl2+)))
 
+(define-public python-mesa
+  (package
+    (name "python-mesa")
+    (version "1.2.1")
+    (source (origin
+              (method url-fetch)
+              (uri (pypi-uri "Mesa" version))
+              (sha256
+               (base32
+                "01504d2bgfwsg92942k34fi7adq5n9r1fw4sn5kx0sm70jwq1628"))))
+    (build-system pyproject-build-system)
+    (arguments
+     (list
+      #:modules '((guix build pyproject-build-system)
+                  (guix build utils)
+                  (ice-9 match)
+                  (srfi srfi-1))
+      #:phases
+      #~(modify-phases %standard-phases
+          (add-after 'unpack 'patch-cookiecutter
+            (lambda* (#:key inputs #:allow-other-keys)
+              (substitute* "mesa/main.py"
+                (("\"cookiecutter\"")
+                 (string-append "\""
+                                (search-input-file inputs "/bin/cookiecutter")
+                                "\"")))))
+          (add-after 'build 'set-HOME
+            ;;  Some tests write to $HOME.
+            (lambda _ (setenv "HOME" "/tmp")))
+          (replace 'compile-bytecode
+            (lambda* (#:key inputs outputs #:allow-other-keys)
+              (let* ((site-dir (site-packages inputs outputs))
+                     (python (assoc-ref inputs "python"))
+                     (major-minor (map string->number
+                                       (take (string-split (python-version python)
+                                                           #\.)
+                                             2)))
+                     (<3.7? (match major-minor
+                              ((major minor)
+                               (or (< major 3)
+                                   (and (= major 3)
+                                        (< minor 7)))))))
+                (unless <3.7?
+                  ;; The cookiecutter-mesa directory contains project templates that
+                  ;; should not be compiled.
+                  (invoke "python" "-m" "compileall"
+                          "-x" "cookiecutter-mesa"
+                          "--invalidation-mode=unchecked-hash" site-dir))))))))
+    (propagated-inputs (list python-click
+                             python-networkx
+                             python-numpy
+                             python-pandas
+                             python-tornado
+                             python-tqdm))
+    (inputs (list python-cookiecutter))
+    (native-inputs (list python-coverage python-pytest python-pytest-cov))
+    (home-page "https://github.com/projectmesa/mesa")
+    (synopsis "Agent-based modeling (ABM) in Python")
+    (description "Mesa is an agent-based modeling framework in Python.  It contains
+core components to implement spatial models, schedule agents and visualize model
+runs.")
+    (license license:asl2.0)))
+
 (define-public python-wand
   (package
     (name "python-wand")

base-commit: 9845e408e533f5834a13f294ca1ddc1dc7e248fd
-- 
2.40.1