Subject: [PATCH]: Clean up gnu/packages/tryton.scm
From: Maxime Devos <[email-masked]>
To: [email-masked]
Cc: Adriano Peluso <[email-masked]>, Vinicius Monego <[email-masked]>
Date: Mon, 24 May 2021 22:53:48 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

CC'ing two people who are listed in the copyright lines.

Patch #1: factor out code the 'check' phase of tryton modules
  in a procedure, as they are almost all exactly the same except
  for the module name.

  This one does not cause any change in derivation (no rebuilds).

Patch #2: Use 'inputs' argument to the 'check' phase instead of
  %build-inputs.

  I tried building some tryton modules and it seemed to work well.
  No failures, but I didn't try all.

Patch #3: Respect tests?, allow --without-tests.

  I tested building a single tryton module.

Greetings,
Maxime.
From 94fef963a6f5c0d8b0c60a5b2279ade8d686d4ec Mon Sep 17 00:00:00 2001
From: Maxime Devos <[email-masked]>
Date: Mon, 24 May 2021 22:36:06 +0200
Subject: [PATCH 3/3] gnu: tryton: Allow disabling the test suite.

* gnu/packages/tryton.scm
  (tryton-phases): Respect 'tests?' in the 'check' phase.
---
 gnu/packages/tryton.scm | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/gnu/packages/tryton.scm b/gnu/packages/tryton.scm
index 107d5b4a7c..5fbbeb53be 100644
--- a/gnu/packages/tryton.scm
+++ b/gnu/packages/tryton.scm
@@ -150,15 +150,16 @@ and security.")
 If present, pass EXTRA-ARGUMENTS to runtest as well."
   `(modify-phases %standard-phases
      (replace 'check
-       (lambda* (#:key inputs outputs #:allow-other-keys)
+       (lambda* (#:key inputs outputs tests? #:allow-other-keys)
          (let ((runtest
                 (string-append
                  (assoc-ref inputs "trytond")
                  "/lib/python"
                  ,(version-major+minor (package-version python))
                  "/site-packages/trytond/tests/run-tests.py")))
-           (add-installed-pythonpath inputs outputs)
-           (invoke "python" runtest "-m" ,module ,@extra-arguments))))))
+           (when tests?
+             (add-installed-pythonpath inputs outputs)
+             (invoke "python" runtest "-m" ,module ,@extra-arguments)))))))
 
 (define (tryton-arguments module . extra-arguments)
   "Like ’tryton-phases’, but directly return all arguments for
-- 
2.31.1

From 3c05280e51e2b8bd7c03e460975169eee512cbf0 Mon Sep 17 00:00:00 2001
From: Maxime Devos <[email-masked]>
Date: Mon, 24 May 2021 22:17:09 +0200
Subject: [PATCH 2/3] gnu: tryton: Use local 'inputs' instead of global
 '%build-inputs'.

The former is preferred above the latter.

* gnu/packages/tryton.scm (tryton-phases): Look up "trytond" in the
  'inputs' argument instead of in '%build-inputs'.
---
 gnu/packages/tryton.scm | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/gnu/packages/tryton.scm b/gnu/packages/tryton.scm
index 800e19d827..107d5b4a7c 100644
--- a/gnu/packages/tryton.scm
+++ b/gnu/packages/tryton.scm
@@ -150,13 +150,13 @@ and security.")
 If present, pass EXTRA-ARGUMENTS to runtest as well."
   `(modify-phases %standard-phases
      (replace 'check
-       (let ((runtest
-              (string-append
-               (assoc-ref %build-inputs "trytond")
-               "/lib/python"
-               ,(version-major+minor (package-version python))
-               "/site-packages/trytond/tests/run-tests.py")))
-         (lambda* (#:key inputs outputs #:allow-other-keys)
+       (lambda* (#:key inputs outputs #:allow-other-keys)
+         (let ((runtest
+                (string-append
+                 (assoc-ref inputs "trytond")
+                 "/lib/python"
+                 ,(version-major+minor (package-version python))
+                 "/site-packages/trytond/tests/run-tests.py")))
            (add-installed-pythonpath inputs outputs)
            (invoke "python" runtest "-m" ,module ,@extra-arguments))))))
 
-- 
2.31.1

From aa0f2aabf11a45d47b8b8d287aa95d85ee35181c Mon Sep 17 00:00:00 2001
From: Maxime Devos <[email-masked]>
Date: Mon, 24 May 2021 21:07:15 +0200
Subject: [PATCH 1/3] =?UTF-8?q?gnu:=20tryton:=20Factor=20out=20custom=20?=
 =?UTF-8?q?=E2=80=98check=E2=80=99=20phase.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* gnu/packages/tryton.scm
  (tryton-phases): New procedure.
  (tryton-arguments): New procedure.
  (python-trytond-account)[arguments]: Use 'tryton-phases'.
  (python-trytond-account-invoice)[arguments]: Likewise.
  (python-trytond-account-invoice-stock)[arguments]: Likewise.
  (python-trytond-account-product)[arguments]: Likewise.
  (python-trytond-analytic-account)[arguments]: Likewise.
  (python-trytond-company)[arguments]: Likewise.
  (python-trytond-country)[arguments]: Likewise.
  (python-trytond-currency)[arguments]: Likewise.
  (python-trytond-party)[arguments]: Likewise.
  (python-trytond-product)[arguments]: Likewise.
  (python-trytond-purchase)[arguments]: Likewise.
  (python-trytond-purchase-request)[arguments]: Likewise.
  (python-trytond-stock)[arguments]: Likewise.
  (python-trytond-stock-lot)[arguments]: Likewise.
---
 gnu/packages/tryton.scm | 238 +++++++---------------------------------
 1 file changed, 39 insertions(+), 199 deletions(-)

diff --git a/gnu/packages/tryton.scm b/gnu/packages/tryton.scm
index e9484aa487..800e19d827 100644
--- a/gnu/packages/tryton.scm
+++ b/gnu/packages/tryton.scm
@@ -1,6 +1,7 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2017 Adriano Peluso <[email-masked]>
 ;;; Copyright © 2020 Vinicius Monego <[email-masked]>
+;;; Copyright © 2021 Maxime Devos <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -144,6 +145,26 @@ and security.")
      "This package provides a library to access Tryton server as a client.")
     (license license:lgpl3+)))
 
+(define (tryton-phases module . extra-arguments)
+  "Return the phases for building and testing a Tryton module named MODULE.
+If present, pass EXTRA-ARGUMENTS to runtest as well."
+  `(modify-phases %standard-phases
+     (replace 'check
+       (let ((runtest
+              (string-append
+               (assoc-ref %build-inputs "trytond")
+               "/lib/python"
+               ,(version-major+minor (package-version python))
+               "/site-packages/trytond/tests/run-tests.py")))
+         (lambda* (#:key inputs outputs #:allow-other-keys)
+           (add-installed-pythonpath inputs outputs)
+           (invoke "python" runtest "-m" ,module ,@extra-arguments))))))
+
+(define (tryton-arguments module . extra-arguments)
+  "Like ’tryton-phases’, but directly return all arguments for
+the build system."
+  `(#:phases ,(apply tryton-phases module extra-arguments)))
+
 ;;;
 ;;;  Tryton modules - please sort alphabetically
 ;;;
@@ -159,19 +180,7 @@ and security.")
        (sha256
         (base32 "16ny67vcnxk9ngcxd56cfixm441vs9jxv3apmb16xsi47yk2xd7w"))))
     (build-system python-build-system)
-    (arguments
-     `(#:phases
-       (modify-phases %standard-phases
-         (replace 'check
-           (let ((runtest
-                  (string-append
-                   (assoc-ref %build-inputs "trytond")
-                   "/lib/python"
-                   ,(version-major+minor (package-version python))
-                   "/site-packages/trytond/tests/run-tests.py")))
-             (lambda* (#:key inputs outputs #:allow-other-keys)
-               (add-installed-pythonpath inputs outputs)
-               (invoke "python" runtest "-m" "account")))))))
+    (arguments (tryton-arguments "account"))
     (native-inputs
      `(("python-genshi" ,python-genshi)
        ("python-lxml" ,python-lxml)
@@ -210,19 +219,7 @@ most of accounting needs.")
        (sha256
         (base32 "0drccambg6855p7ai8654c7f9v85jzwicwpxmagyrr09qz6qzgcz"))))
     (build-system python-build-system)
-    (arguments
-     `(#:phases
-       (modify-phases %standard-phases
-         (replace 'check
-           (let ((runtest
-                  (string-append
-                   (assoc-ref %build-inputs "trytond")
-                   "/lib/python"
-                   ,(version-major+minor (package-version python))
-                   "/site-packages/trytond/tests/run-tests.py")))
-             (lambda* (#:key inputs outputs #:allow-other-keys)
-               (add-installed-pythonpath inputs outputs)
-               (invoke "python" runtest "-m" "account_invoice")))))))
+    (arguments (tryton-arguments "account_invoice"))
     (native-inputs
      `(("python-genshi" ,python-genshi)
        ("python-lxml" ,python-lxml)
@@ -268,19 +265,7 @@ term.")
        (sha256
         (base32 "02m6ikcc38ac41ddzg5xp5l9jz0k6j7j1g2xa62ki4v093yn4z5v"))))
     (build-system python-build-system)
-    (arguments
-     `(#:phases
-       (modify-phases %standard-phases
-         (replace 'check
-           (let ((runtest
-                  (string-append
-                   (assoc-ref %build-inputs "trytond")
-                   "/lib/python"
-                   ,(version-major+minor (package-version python))
-                   "/site-packages/trytond/tests/run-tests.py")))
-             (lambda* (#:key inputs outputs #:allow-other-keys)
-               (add-installed-pythonpath inputs outputs)
-               (invoke "python" runtest "-m" "account_invoice_stock")))))))
+    (arguments (tryton-arguments "account_invoice_stock"))
     (native-inputs
      `(("python-dateutil" ,python-dateutil)
        ("python-genshi" ,python-genshi)
@@ -319,19 +304,7 @@ average price of the posted invoice lines that are linked to it.")
        (sha256
         (base32 "10bpbkkmllbh9lm5ajydmc5nvqm9bbdn9rmm03jqgik23s5kyx2z"))))
     (build-system python-build-system)
-    (arguments
-     `(#:phases
-       (modify-phases %standard-phases
-         (replace 'check
-           (let ((runtest
-                  (string-append
-                   (assoc-ref %build-inputs "trytond")
-                   "/lib/python"
-                   ,(version-major+minor (package-version python))
-                   "/site-packages/trytond/tests/run-tests.py")))
-             (lambda* (#:key inputs outputs #:allow-other-keys)
-               (add-installed-pythonpath inputs outputs)
-               (invoke "python" runtest "-m" "account_product")))))))
+    (arguments (tryton-arguments "account_product"))
     (native-inputs
      `(("python-dateutil" ,python-dateutil)
        ("python-genshi" ,python-genshi)
@@ -372,19 +345,7 @@ and category.")
        (sha256
         (base32 "10rn2rf1ji7d1gxmgca368yvabql1ahklqg7p8sh5bl79vn5qx5x"))))
     (build-system python-build-system)
-    (arguments
-     `(#:phases
-       (modify-phases %standard-phases
-         (replace 'check
-           (let ((runtest
-                  (string-append
-                   (assoc-ref %build-inputs "trytond")
-                   "/lib/python"
-                   ,(version-major+minor (package-version python))
-                   "/site-packages/trytond/tests/run-tests.py")))
-             (lambda* (#:key inputs outputs #:allow-other-keys)
-               (add-installed-pythonpath inputs outputs)
-               (invoke "python" runtest "-m" "analytic_account")))))))
+    (arguments (tryton-arguments "analytic_account"))
     (native-inputs
      `(("python-dateutil" ,python-dateutil)
        ("python-genshi" ,python-genshi)
@@ -424,19 +385,7 @@ required to analyse accounting using multiple different axes.")
        (sha256
         (base32 "1bwy2rkgfw32cwhq5fh3rpy7bx425h44ap10i9kjx5ak86bfnpz9"))))
     (build-system python-build-system)
-    (arguments
-     `(#:phases
-       (modify-phases %standard-phases
-         (replace 'check
-           (let ((runtest
-                  (string-append
-                   (assoc-ref %build-inputs "trytond")
-                   "/lib/python"
-                   ,(version-major+minor (package-version python))
-                   "/site-packages/trytond/tests/run-tests.py")))
-             (lambda* (#:key inputs outputs #:allow-other-keys)
-               (add-installed-pythonpath inputs outputs)
-               (invoke "python" runtest "-m" "company")))))))
+    (arguments (tryton-arguments "company"))
     (native-inputs
      `(("python-dateutil" ,python-dateutil)
        ("python-genshi" ,python-genshi)
@@ -472,20 +421,8 @@ company and employee and extend the user model.")
        (sha256
         (base32 "1lkspk5w5pb0gg2h27zb7vwcj993gkm1f84qdxmqlpkc8raqvicj"))))
     (build-system python-build-system)
-    (arguments
-     `(#:phases
-       (modify-phases %standard-phases
-         (replace 'check
-           (let ((runtest
-                  (string-append
-                   (assoc-ref %build-inputs "trytond")
-                   "/lib/python"
-                   ,(version-major+minor (package-version python))
-                   "/site-packages/trytond/tests/run-tests.py")))
-             (lambda* (#:key inputs outputs #:allow-other-keys)
-               (add-installed-pythonpath inputs outputs)
-               ;; Doctest contains one test that requires internet access.
-               (invoke "python" runtest "-m" "country" "--no-doctest")))))))
+    ;; Doctest contains one test that requires internet access.
+    (arguments (tryton-arguments "country" "--no-doctest"))
     (native-inputs
      `(("python-dateutil" ,python-dateutil)
        ("python-genshi" ,python-genshi)
@@ -518,19 +455,7 @@ company and employee and extend the user model.")
        (sha256
         (base32 "0b5p7ibil7nlsv7f31j69rka4xj5za798262algx7xa88a6h7mmx"))))
     (build-system python-build-system)
-    (arguments
-     `(#:phases
-       (modify-phases %standard-phases
-         (replace 'check
-           (let ((runtest
-                  (string-append
-                   (assoc-ref %build-inputs "trytond")
-                   "/lib/python"
-                   ,(version-major+minor (package-version python))
-                   "/site-packages/trytond/tests/run-tests.py")))
-             (lambda* (#:key inputs outputs #:allow-other-keys)
-               (add-installed-pythonpath inputs outputs)
-               (invoke "python" runtest "-m" "currency")))))))
+    (arguments (tryton-arguments "currency"))
     (native-inputs
      `(("python-dateutil" ,python-dateutil)
        ("python-genshi" ,python-genshi)
@@ -565,20 +490,8 @@ currency and rate.")
        (sha256
         (base32 "1hapfq7ip99s4qp9xra1m40q4n379p9pmfnz2x4ggd79ss76bghc"))))
     (build-system python-build-system)
-    (arguments
-     `(#:phases
-       (modify-phases %standard-phases
-         (replace 'check
-           (let ((runtest
-                  (string-append
-                   (assoc-ref %build-inputs "trytond")
-                   "/lib/python"
-                   ,(version-major+minor (package-version python))
-                   "/site-packages/trytond/tests/run-tests.py")))
-             (lambda* (#:key inputs outputs #:allow-other-keys)
-               (add-installed-pythonpath inputs outputs)
-               ;; Doctest 'scenario_party_phone_number.rst' fails.
-               (invoke "python" runtest "-m" "party" "--no-doctest")))))))
+    ;; Doctest 'scenario_party_phone_number.rst' fails.
+    (arguments (tryton-arguments "party" "--no-doctest"))
     (native-inputs
      `(("python-dateutil" ,python-dateutil)
        ("python-genshi" ,python-genshi)
@@ -613,19 +526,7 @@ addresses.")
        (sha256
         (base32 "0x18ngpjyrdwjwg17bz98jph4jv5gcv0qc0p2kxpam4lqsy34ic2"))))
     (build-system python-build-system)
-    (arguments
-     `(#:phases
-       (modify-phases %standard-phases
-         (replace 'check
-           (let ((runtest
-                  (string-append
-                   (assoc-ref %build-inputs "trytond")
-                   "/lib/python"
-                   ,(version-major+minor (package-version python))
-                   "/site-packages/trytond/tests/run-tests.py")))
-             (lambda* (#:key inputs outputs #:allow-other-keys)
-               (add-installed-pythonpath inputs outputs)
-               (invoke "python" runtest "-m" "product")))))))
+    (arguments (tryton-arguments "product"))
     (native-inputs
      `(("python-dateutil" ,python-dateutil)
        ("python-genshi" ,python-genshi)
@@ -661,19 +562,7 @@ Template and Product.")
        (sha256
         (base32 "0na74zijj46b12gypy9si3las02a96rh5ygl503c7razha61g1b0"))))
     (build-system python-build-system)
-    (arguments
-     `(#:phases
-       (modify-phases %standard-phases
-         (replace 'check
-           (let ((runtest
-                  (string-append
-                   (assoc-ref %build-inputs "trytond")
-                   "/lib/python"
-                   ,(version-major+minor (package-version python))
-                   "/site-packages/trytond/tests/run-tests.py")))
-             (lambda* (#:key inputs outputs #:allow-other-keys)
-               (add-installed-pythonpath inputs outputs)
-               (invoke "python" runtest "-m" "purchase")))))))
+    (arguments (tryton-arguments "purchase"))
     (native-inputs
      `(("python-dateutil" ,python-dateutil)
        ("python-genshi" ,python-genshi)
@@ -721,21 +610,8 @@ Template and Product.")
        (sha256
         (base32 "1m92snnvgisnv083nml6cz5qgnfdg539rd5bwg3lqrknm7343w16"))))
     (build-system python-build-system)
-    (arguments
-     `(#:phases
-       (modify-phases %standard-phases
-         (replace 'check
-           (let ((runtest
-                  (string-append
-                   (assoc-ref %build-inputs "trytond")
-                   "/lib/python"
-                   ,(version-major+minor (package-version python))
-                   "/site-packages/trytond/tests/run-tests.py")))
-             (lambda* (#:key inputs outputs #:allow-other-keys)
-               (add-installed-pythonpath inputs outputs)
-               ;; Doctest 'scenario_purchase_request.rst' fails.
-               (invoke "python" runtest
-                       "-m" "purchase_request" "--no-doctest")))))))
+    ;; Doctest 'scenario_purchase_request.rst' fails.
+    (arguments (tryton-arguments "purchase_request" "--no-doctest"))
     (native-inputs
      `(("python-dateutil" ,python-dateutil)
        ("python-genshi" ,python-genshi)
@@ -773,19 +649,7 @@ generated by other process from Tryton.")
        (sha256
         (base32 "0yb8kd3alwqkivrlpx0ni4jxv3x14i37lmwism9yi81xwchyrcjk"))))
     (build-system python-build-system)
-    (arguments
-     `(#:phases
-       (modify-phases %standard-phases
-         (replace 'check
-           (let ((runtest
-                  (string-append
-                   (assoc-ref %build-inputs "trytond")
-                   "/lib/python"
-                   ,(version-major+minor (package-version python))
-                   "/site-packages/trytond/tests/run-tests.py")))
-             (lambda* (#:key inputs outputs #:allow-other-keys)
-               (add-installed-pythonpath inputs outputs)
-               (invoke "python" runtest "-m" "stock")))))))
+    (arguments (tryton-arguments "stock"))
     (native-inputs
      `(("python-genshi" ,python-genshi)
        ("python-lxml" ,python-lxml)
@@ -827,19 +691,7 @@ inventory to control and update stock levels.")
        (sha256
         (base32 "0w2f62cfzm7j8wnw8igmjslpxc1a8s82dkdizyvim5qhjg6mrsym"))))
     (build-system python-build-system)
-    (arguments
-     `(#:phases
-       (modify-phases %standard-phases
-         (replace 'check
-           (let ((runtest
-                  (string-append
-                   (assoc-ref %build-inputs "trytond")
-                   "/lib/python"
-                   ,(version-major+minor (package-version python))
-                   "/site-packages/trytond/tests/run-tests.py")))
-             (lambda* (#:key inputs outputs #:allow-other-keys)
-               (add-installed-pythonpath inputs outputs)
-               (invoke "python" runtest "-m" "stock_lot")))))))
+    (arguments (tryton-arguments "stock_lot"))
     (native-inputs
      `(("python-dateutil" ,python-dateutil)
        ("python-genshi" ,python-genshi)
@@ -874,19 +726,7 @@ inventory to control and update stock levels.")
        (sha256
         (base32 "01cgpxlznldrba79a3xmj4d0csyfc3ccgs66c490j8v8rdnqpbww"))))
     (build-system python-build-system)
-    (arguments
-     `(#:phases
-       (modify-phases %standard-phases
-         (replace 'check
-           (let ((runtest
-                  (string-append
-                   (assoc-ref %build-inputs "trytond")
-                   "/lib/python"
-                   ,(version-major+minor (package-version python))
-                   "/site-packages/trytond/tests/run-tests.py")))
-             (lambda* (#:key inputs outputs #:allow-other-keys)
-               (add-installed-pythonpath inputs outputs)
-               (invoke "python" runtest "-m" "stock_supply")))))))
+    (arguments (tryton-arguments "stock_supply"))
     (native-inputs
      `(("python-dateutil" ,python-dateutil)
        ("python-genshi" ,python-genshi)
-- 
2.31.1