Subject: [PATCH] gnu: Add python-libtmux
From: Edouard Klein <[email-masked]>
To: [email-masked]
Date: Tue, 12 May 2020 15:51:28 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

---
 gnu/packages/check.scm      | 49 +++++++++++++++++++++++++++++++++++++
 gnu/packages/python-xyz.scm | 46 ++++++++++++++++++++++++++++++++++
 2 files changed, 95 insertions(+)

diff --git a/gnu/packages/check.scm b/gnu/packages/check.scm
index 9971700d2d..2b59a7ec99 100644
--- a/gnu/packages/check.scm
+++ b/gnu/packages/check.scm
@@ -33,6 +33,7 @@
 ;;; Copyright © 2020 Lars-Dominik Braun <[email-masked]>
 ;;; Copyright © 2020 Brice Waegeneire <[email-masked]>
 ;;; Copyright © 2020 Josh Marshall <[email-masked]>
+;;; Copyright © 2020 Edouard Klein <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -68,6 +69,7 @@
   #:use-module (gnu packages python-xyz)
   #:use-module (gnu packages time)
   #:use-module (gnu packages xml)
+  #:use-module (gnu packages version-control)
   #:use-module (guix utils)
   #:use-module ((guix licenses) #:prefix license:)
   #:use-module (guix packages)
@@ -819,6 +821,53 @@ and many external plugins.")
     (license license:expat)
     (properties `((python2-variant . ,(delay python2-pytest))))))
 
+(define-public python-pytest-4
+  (package
+    (name "python-pytest-4")
+    (version "4.5.0")
+    (source
+     (origin
+       (method git-fetch)
+       ;; Pypi source tarball does not include tests
+       (uri (git-reference
+             (url "https://github.com/pytest-dev/pytest.git")
+             (commit version)))
+       (file-name "python-pytest-4")
+       (sha256
+        (base32
+         "0igxfasjqabkzlb81vxqr58pfsdwjx4zzd1nc1b48wn6xnkkllhk"))))
+    (build-system python-build-system)
+    (propagated-inputs
+     `(("python-atomicwrites" ,python-atomicwrites)
+       ("python-attrs" ,python-attrs)
+       ("python-attrs" ,python-attrs)
+       ("python-more-itertools" ,python-more-itertools)
+       ("python-pluggy" ,python-pluggy)
+       ("python-six" ,python-six)
+       ("python-py" ,python-py)
+       ("python-wcwidth" ,python-wcwidth)))
+    (native-inputs
+     `(("python-setuptools-scm" ,python-setuptools-scm)
+       ("git" ,git)))
+    (arguments `(#:phases
+                 (modify-phases %standard-phases
+                   (add-after 'unpack 'git-tag
+                     (lambda _
+                       ;; setuptools-scm needs to know the version
+                       (invoke "git" "init")
+                       (invoke "git" "add" ".")
+                       (invoke "git" "config" "user.name" "John Doe")
+                       (invoke "git" "config" "user.email" "[email-masked]")
+                       (invoke "git" "commit" "-m" "dummy commit")
+                       (invoke "git" "tag" ,version))))))
+    (home-page "https://docs.pytest.org/en/latest/")
+    (synopsis "Python testing library")
+    (description
+     "Pytest is a testing tool that provides auto-discovery of test modules
+and functions, detailed info on failing assert statements, modular fixtures,
+and many external plugins.")
+    (license license:expat)))
+
 ;; Pytest 4.x are the last versions that support Python 2.
 (define-public python2-pytest
   (package
diff --git a/gnu/packages/python-xyz.scm b/gnu/packages/python-xyz.scm
index 29b3305e5b..9ec4658523 100644
--- a/gnu/packages/python-xyz.scm
+++ b/gnu/packages/python-xyz.scm
@@ -77,6 +77,7 @@
 ;;; Copyright © 2020 Lars-Dominik Braun <[email-masked]>
 ;;; Copyright © 2020 Alex ter Weele <[email-masked]>
 ;;; Copyright © 2020 Matthew Kraai <[email-masked]>
+;;; Copyright © 2020 Edouard Klein <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -167,6 +168,7 @@
   #:use-module (gnu packages tcl)
   #:use-module (gnu packages bdw-gc)
   #:use-module (gnu packages serialization)
+  #:use-module (gnu packages tmux)
   #:use-module (guix packages)
   #:use-module (guix download)
   #:use-module (guix git-download)
@@ -19889,3 +19891,47 @@ module.  @code{cmd2} provides a wealth of features on top of @code{cmd} to
 make your life easier and eliminates much of the boilerplate code which would
 be necessary when using @code{cmd}.")
     (license license:expat)))
+
+(define-public python-libtmux
+  (package
+    (name "python-libtmux")
+    (version "0.8.2")
+    (source
+     (origin
+       (method git-fetch)
+       ;; Pypi source tarball does not include tests
+       (uri (git-reference
+             (url "https://github.com/tmux-python/libtmux.git")
+             (commit (string-append "v" version))))
+       (file-name "python-libtmux")
+       (sha256
+        (base32
+         "1akjv6aqpc690c4l2cjh0fxbpxxg63sfjggapfjjjaqmcl38g1dz"))))
+    (build-system python-build-system)
+    (propagated-inputs
+     `(("python-pytest-4" ,python-pytest-4)
+       ("tmux" ,tmux)
+       ("procps" ,procps)))  ;; Tests need top
+    (arguments
+     `(#:phases
+       (modify-phases %standard-phases
+         (replace 'check
+           (lambda _
+             ;; Extend PYTHONPATH so the built package will be found.
+             (setenv "PYTHONPATH"
+                     (string-append (getcwd) "/build/lib:"
+                                    (getenv "PYTHONPATH")))
+             ;; Skip tests that I suspect fail because of a change
+             ;; in behavior in tmux 3 from tmux 2
+             ;; https://github.com/tmux-python/libtmux/issues/281
+             (invoke "pytest" "-vv" "-k"
+                     (string-append "not test_show_option_unknown "
+                                    "and not test_show_window_option_unknown"))
+             #t)))))
+    (home-page
+     "https://github.com/tmux-python/libtmux")
+    (synopsis "Scripting library / orm for tmux")
+    (description "Libtmux is the tool behind tmuxp, a tmux workspace manager in python.
+It builds upon tmux's target and formats to create an object mapping to traverse,
+ inspect and interact with live tmux sessions.")
+    (license license:expat)))
-- 
2.26.2