Subject: [PATCH] Add emacs-elpy

From: Maxim Cournoyer <[email-masked]>
Date: Mon, 27 Aug 2018 01:00:37 -0400

Hello,

This adds emacs-elpy to our collection, a worthy addition to Emacs when
in need of editing some Python.

To get the full experience, you'll want to install the following
(optional) additions, like:

--8<---------------cut here---------------start------------->8---
guix package -i python-jedi python-autopep8 python-yapf python-black python-flake8
--8<---------------cut here---------------end--------------->8---

You can enable Elpy by doing M-x elpy-mode in a Python buffer, and see
which tools are installed using M-x elpy-config.

Enjoy :)

Maxim

From 4eba594f0d99feb24e4320aa8db8252811debc0a Mon Sep 17 00:00:00 2001
From: Maxim Cournoyer <[email-masked]>
Date: Sun, 26 Aug 2018 17:35:46 -0400
Subject: [PATCH 1/9] gnu: python-jedi: Update to 0.12.1.

* gnu/packages/python.scm (python-jedi): Update to 0.12.1.
[propagated-inputs]: Move python-parso here, as it is required at run time.
---
 gnu/packages/python.scm | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/gnu/packages/python.scm b/gnu/packages/python.scm
index 639db19a5..81217f988 100644
--- a/gnu/packages/python.scm
+++ b/gnu/packages/python.scm
@@ -9622,14 +9622,14 @@ characters, mouse support, and auto suggestions.")
 (define-public python-jedi
   (package
     (name "python-jedi")
-    (version "0.12.0")
+    (version "0.12.1")
     (source
      (origin
        (method url-fetch)
        (uri (pypi-uri "jedi" version))
        (sha256
         (base32
-         "1bcr7csx4xil1iwmk03d79jis0bkmgi9k0kir3xa4rmwqsagcwhr"))))
+         "1h8ypnjisn57kiv1zqrkj1im6sbfnhxllqaa8znh39qkd47ys2dl"))))
     (build-system python-build-system)
     (arguments
      `(#:phases
@@ -9638,8 +9638,9 @@ characters, mouse support, and auto suggestions.")
                            (invoke "py.test" "-vv"))))))
     (native-inputs
      `(("python-pytest" ,python-pytest)
-       ("python-parso" ,python-parso)
        ("python-docopt" ,python-docopt)))
+    (propagated-inputs
+     `(("python-parso" ,python-parso)))
     (home-page "https://github.com/davidhalter/jedi")
     (synopsis
      "Autocompletion for Python that can be used for text editors")
-- 
2.18.0

From 54130c8f5bcf683b1681e1a6c6238421bd0c6459 Mon Sep 17 00:00:00 2001
From: Maxim Cournoyer <[email-masked]>
Date: Sun, 26 Aug 2018 23:56:15 -0400
Subject: [PATCH 2/9] gnu: Add python-toml.

* gnu/packages/python.scm (python-toml, python2-toml): New variables.
---
 gnu/packages/python.scm | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/gnu/packages/python.scm b/gnu/packages/python.scm
index 81217f988..fb7f4b35c 100644
--- a/gnu/packages/python.scm
+++ b/gnu/packages/python.scm
@@ -54,6 +54,7 @@
 ;;; Copyright © 2018 Nicolas Goaziou <[email-masked]>
 ;;; Copyright © 2018 Oleg Pykhalov <[email-masked]>
 ;;; Copyright © 2018 Clément Lassieur <[email-masked]>
+;;; Copyright © 2018 Maxim Cournoyer <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -2720,6 +2721,29 @@ which can produce feeds in RSS 2.0, RSS 0.91, and Atom formats.")
 (define-public python2-feedgenerator
   (package-with-python2 python-feedgenerator))
 
+(define-public python-toml
+  (package
+    (name "python-toml")
+    (version "0.9.4")
+    (source
+     (origin
+       (method url-fetch)
+       (uri (pypi-uri "toml" version))
+       (sha256
+        (base32
+         "0bdbpbip67wdm6c7xwc6mmbmskyradj4cdxn1iibj4fcx1nbv1lf"))))
+    (build-system python-build-system)
+    (arguments
+     `(#:tests? #f))                     ;no tests suite in release
+    (home-page "https://github.com/uiri/toml")
+    (synopsis "Library for TOML")
+    (description
+     "@code{toml} is a library for Tom's Obvious, Minimal Language (TOML).")
+    (license license:expat)))
+
+(define-public python2-toml
+  (package-with-python2 python-toml))
+
 (define-public python-blinker
   (package
     (name "python-blinker")
-- 
2.18.0

From c8928304cfa8d8802d97ba68a3220e68f7ad5d32 Mon Sep 17 00:00:00 2001
From: Maxim Cournoyer <[email-masked]>
Date: Sun, 26 Aug 2018 23:58:26 -0400
Subject: [PATCH 3/9] gnu: Add python-black.

* gnu/packages/python.scm (python-black): New variable.
---
 gnu/packages/python.scm | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/gnu/packages/python.scm b/gnu/packages/python.scm
index fb7f4b35c..e0a990491 100644
--- a/gnu/packages/python.scm
+++ b/gnu/packages/python.scm
@@ -2744,6 +2744,41 @@ which can produce feeds in RSS 2.0, RSS 0.91, and Atom formats.")
 (define-public python2-toml
   (package-with-python2 python-toml))
 
+(define-public python-black
+  (package
+    (name "python-black")
+    (version "18.6b4")
+    (source
+     (origin
+       (method url-fetch)
+       (uri (pypi-uri "black" version))
+       (sha256
+        (base32
+         "0i4sfqgz6w15vd50kbhi7g7rifgqlf8yfr8y78rypd56q64qn592"))))
+    (build-system python-build-system)
+    (arguments
+     `(#:phases
+       (modify-phases %standard-phases
+         (add-after 'patch-source-shebangs 'patch-extra-shebangs
+           (lambda _
+             (let ((python3 (which "python3")))
+               (substitute* '("tests/data/fmtonoff.py"
+                              "tests/data/string_prefixes.py"
+                              "tests/data/function.py")
+                 (("#!/usr/bin/env python3(\\.[0-9]+)?" _ minor-version)
+                  (string-append "#!" python3 (if (string? minor-version)
+                                                  minor-version
+                                                  ""))))))))))
+    (propagated-inputs
+     `(("python-click" ,python-click)
+       ("python-attrs" ,python-attrs)
+       ("python-appdirs" ,python-appdirs)
+       ("python-toml" ,python-toml)))
+    (home-page "https://github.com/ambv/black")
+    (synopsis "The uncompromising code formatter")
+    (description "Black is the uncompromising Python code formatter.")
+    (license license:expat)))
+
 (define-public python-blinker
   (package
     (name "python-blinker")
-- 
2.18.0

From 46ccd0d7093f9adbe091ec6e7846719e5ad267bf Mon Sep 17 00:00:00 2001
From: Maxim Cournoyer <[email-masked]>
Date: Mon, 12 Feb 2018 22:08:03 -0500
Subject: [PATCH 4/9] gnu: Add emacs-el-x.

* gnu/packages/emacs.scm (emacs-el-x): New variable.
---
 gnu/packages/emacs.scm | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/gnu/packages/emacs.scm b/gnu/packages/emacs.scm
index 92d02df49..b0199976b 100644
--- a/gnu/packages/emacs.scm
+++ b/gnu/packages/emacs.scm
@@ -4377,6 +4377,39 @@ If you want to mark a folder manually as a project just create an empty
 and RSS, with a user interface inspired by notmuch.")
     (license license:gpl3+)))
 
+(define-public emacs-el-x
+  (package
+    (name "emacs-el-x")
+    (version "0.3.1")
+    (source (origin
+              (method git-fetch)
+              (uri (git-reference
+                    (url "https://github.com/sigma/el-x.git")
+                    (commit (string-append "v" version))))
+              (file-name (string-append name "-" version "-checkout"))
+              (sha256
+               (base32
+                "1i6j44ssxm1xdg0mf91nh1lnprwsaxsx8vsrf720nan7mfr283h5"))))
+    (build-system emacs-build-system)
+    (arguments
+     `(#:phases
+       (modify-phases %standard-phases
+         ;; Move the source files to the top level, which is included in
+         ;; the EMACSLOADPATH.
+         (add-after 'unpack 'move-source-files
+           (lambda _
+             (let ((el-files (find-files "./lisp" ".*\\.el$")))
+               (for-each (lambda (f)
+                           (rename-file f (basename f)))
+                         el-files))
+             #t)))))
+    (home-page "https://github.com/sigma/el-x")
+    (synopsis "Emacs Lisp extensions")
+    (description "Defines the @code{dflet} macro to provide the historic
+behavior of @code{flet}, as well as @code{declare-function} stub for older
+Emacs.")
+    (license license:gpl2+)))
+
 (define-public emacs-rainbow-delimiters
   (package
     (name "emacs-rainbow-delimiters")
-- 
2.18.0

From 2257b2ad0b54bcfd6f1eb0183d7e8c28f76f482e Mon Sep 17 00:00:00 2001
From: Maxim Cournoyer <[email-masked]>
Date: Mon, 12 Feb 2018 22:08:37 -0500
Subject: [PATCH 5/9] gnu: Add emacs-mocker.

* gnu/packages/emacs.scm (emacs-mocker): New variable.
---
 gnu/packages/emacs.scm | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/gnu/packages/emacs.scm b/gnu/packages/emacs.scm
index b0199976b..c6f345c0b 100644
--- a/gnu/packages/emacs.scm
+++ b/gnu/packages/emacs.scm
@@ -4410,6 +4410,34 @@ behavior of @code{flet}, as well as @code{declare-function} stub for older
 Emacs.")
     (license license:gpl2+)))
 
+(define-public emacs-mocker
+  (package
+    (name "emacs-mocker")
+    (version "0.3.1")
+    (source (origin
+              (method git-fetch)
+              (uri (git-reference
+                    (url "https://github.com/sigma/mocker.el.git")
+                    (commit (string-append "v" version))))
+              (file-name (string-append name "-" version "-checkout"))
+              (sha256
+               (base32
+                "1lav7am41v63xgavq8pr88y828jmd1cxd4prjq7jlbxm6nvrwxh2"))))
+    (build-system emacs-build-system)
+    (arguments
+     `(#:tests? #t
+       #:test-command '("ert-runner")))
+    (native-inputs
+     `(("ert-runner" ,ert-runner)))
+    (propagated-inputs
+     `(("emacs-el-x" ,emacs-el-x)))
+    (home-page "https://github.com/sigma/mocker.el")
+    (synopsis "Mocking framework for Emacs Lisp")
+    (description "Mocker.el is a framework for writing tests in Emacs Lisp.
+It uses regular Lisp rather than a domain specific language (DSL), which
+maximizes flexibility (at the expense of conciseness).")
+    (license license:gpl2+)))
+
 (define-public emacs-rainbow-delimiters
   (package
     (name "emacs-rainbow-delimiters")
-- 
2.18.0

From f7b567f86cc49f61a157739e1feebc9dbc749219 Mon Sep 17 00:00:00 2001
From: Maxim Cournoyer <[email-masked]>
Date: Mon, 12 Feb 2018 22:09:12 -0500
Subject: [PATCH 6/9] gnu: Add emacs-find-file-in-project.

* gnu/packages/emacs.scm (emacs-find-file-in-project): New variable.
---
 gnu/packages/emacs.scm | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/gnu/packages/emacs.scm b/gnu/packages/emacs.scm
index c6f345c0b..fbbf55d78 100644
--- a/gnu/packages/emacs.scm
+++ b/gnu/packages/emacs.scm
@@ -4438,6 +4438,38 @@ It uses regular Lisp rather than a domain specific language (DSL), which
 maximizes flexibility (at the expense of conciseness).")
     (license license:gpl2+)))
 
+(define-public emacs-find-file-in-project
+  (package
+    (name "emacs-find-file-in-project")
+    (version "5.4.7")
+    (source (origin
+              (method git-fetch)
+              (uri (git-reference
+                    (url "https://github.com/technomancy/find-file-in-project.git")
+                    (commit version)))
+              (file-name (string-append name "-" version "-checkout"))
+              (sha256
+               (base32
+                "1sdnyqv69mipbgs9yax88m9b6crsa59rjhwrih197pifl4089awr"))))
+    (build-system emacs-build-system)
+    (arguments
+     `(#:phases
+       (modify-phases %standard-phases
+         (add-before 'check 'set-shell
+           ;; Otherwise Emacs shell-file-name is set to "/bin/sh", which doesn't
+           ;; work.
+           (lambda _
+             (setenv "SHELL" (which "sh")))))
+       #:tests? #t
+       #:test-command '("./tests/test.sh")))
+    (home-page "https://github.com/technomancy/find-file-in-project")
+    (synopsis "File/directory finder for Emacs")
+    (description "@code{find-file-in-project} allows to find files or
+directories quickly in the current project.  The project root is detected
+automatically when Git, Subversion or Mercurial are used.  It also provides
+functions to assist in reviewing changes on files.")
+    (license license:gpl3+)))
+
 (define-public emacs-rainbow-delimiters
   (package
     (name "emacs-rainbow-delimiters")
-- 
2.18.0

From e8745e62a459f271f6ef851e33381bd28cf72b5a Mon Sep 17 00:00:00 2001
From: Maxim Cournoyer <[email-masked]>
Date: Mon, 12 Feb 2018 22:09:43 -0500
Subject: [PATCH 7/9] gnu: Add emacs-pyvenv.

* gnu/packages/emacs.scm (emacs-pyvenv): New variable.
---
 gnu/packages/emacs.scm | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/gnu/packages/emacs.scm b/gnu/packages/emacs.scm
index fbbf55d78..3467fdbc8 100644
--- a/gnu/packages/emacs.scm
+++ b/gnu/packages/emacs.scm
@@ -4470,6 +4470,37 @@ automatically when Git, Subversion or Mercurial are used.  It also provides
 functions to assist in reviewing changes on files.")
     (license license:gpl3+)))
 
+(define-public emacs-pyvenv
+  (package
+    (name "emacs-pyvenv")
+    (version "1.11")
+    (source (origin
+              (method git-fetch)
+              (uri (git-reference
+                    (url "https://github.com/jorgenschaefer/pyvenv.git")
+                    (commit (string-append "v" version))))
+              (file-name (string-append name "-" version "-checkout"))
+              (sha256
+               (base32
+                "1a346qdimr1dvj53q033aqnahwd2dhyn9jadrs019nm0bzgw7g63"))))
+    (build-system emacs-build-system)
+    (arguments
+     `(#:phases
+       (modify-phases %standard-phases
+         ;; This phase incorrectly attempts to substitute "activate" and fails
+         ;; doing so.
+         (delete 'patch-el-files))
+       #:tests? #t
+       #:test-command '("ert-runner")))
+    (native-inputs
+     `(("ert-runner" ,ert-runner)
+       ("emacs-mocker" ,emacs-mocker)))
+    (home-page "https://github.com/jorgenschaefer/pyvenv")
+    (synopsis "Virtualenv minor mode for Emacs")
+    (description "pyvenv.el is a minor mode to support using Python virtual
+environments (virtualenv) inside Emacs.")
+    (license license:gpl3+)))
+
 (define-public emacs-rainbow-delimiters
   (package
     (name "emacs-rainbow-delimiters")
-- 
2.18.0

From c18ae613fcc42e5a85fc09859c3cf93c63b3db74 Mon Sep 17 00:00:00 2001
From: Maxim Cournoyer <[email-masked]>
Date: Mon, 12 Feb 2018 22:10:03 -0500
Subject: [PATCH 8/9] gnu: Add emacs-highlight-indentation.

* gnu/packages/emacs.scm (emacs-highlight-indentation): New variable.
---
 gnu/packages/emacs.scm | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/gnu/packages/emacs.scm b/gnu/packages/emacs.scm
index 3467fdbc8..797e747fb 100644
--- a/gnu/packages/emacs.scm
+++ b/gnu/packages/emacs.scm
@@ -4501,6 +4501,30 @@ functions to assist in reviewing changes on files.")
 environments (virtualenv) inside Emacs.")
     (license license:gpl3+)))
 
+(define-public emacs-highlight-indentation
+  (package
+    (name "emacs-highlight-indentation")
+    (version "0.7.0")
+    (source (origin
+              (method git-fetch)
+              (uri (git-reference
+                    (url "https://github.com/antonj/Highlight-Indentation-for-Emacs.git")
+                    (commit (string-append "v" version))))
+              (file-name (string-append name "-" version "-checkout"))
+              (sha256
+               (base32
+                "00l54k75qk24a0znzl4ij3s3nrnr2wy9ha3za8apphzlm98m907k"))))
+    (build-system emacs-build-system)
+    (home-page "https://github.com/antonj/Highlight-Indentation-for-Emacs/")
+    (synopsis "Highlighting indentation for Emacs")
+    (description "Provides two minor modes to highlight indentation guides in Emacs:
+@enumerate
+@item @code{highlight-indentation-mode}, which displays guidelines
+indentation (space indentation only).
+@item @code{ighlight-indentation-current-column-mode}, which displays guidelines for the current-point indentation (space indentation only).
+@end enumerate")
+    (license license:gpl2+)))
+
 (define-public emacs-rainbow-delimiters
   (package
     (name "emacs-rainbow-delimiters")
-- 
2.18.0

From ba9e9f14e83bd0467db22dd19c562916bd9418ab Mon Sep 17 00:00:00 2001
From: Maxim Cournoyer <[email-masked]>
Date: Mon, 12 Feb 2018 22:10:31 -0500
Subject: [PATCH 9/9] gnu: Add emacs-elpy.

* gnu/packages/emacs.scm (emacs-elpy): New variable.
---
 gnu/packages/emacs.scm | 58 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 58 insertions(+)

diff --git a/gnu/packages/emacs.scm b/gnu/packages/emacs.scm
index 797e747fb..372f72dab 100644
--- a/gnu/packages/emacs.scm
+++ b/gnu/packages/emacs.scm
@@ -4525,6 +4525,64 @@ indentation (space indentation only).
 @end enumerate")
     (license license:gpl2+)))
 
+(define-public emacs-elpy
+  (package
+    (name "emacs-elpy")
+    (version "1.23.0")
+    (source (origin
+              (method git-fetch)
+              (uri (git-reference
+                    (url "https://github.com/jorgenschaefer/elpy.git")
+                    (commit version)))
+              (file-name (string-append name "-" version "-checkout"))
+              (sha256
+               (base32
+                "0dy18lyvpgr8vi2a7r13i8bn6k3b12z4l8hx0y80sh3mnakvs14n"))))
+    (build-system emacs-build-system)
+    (arguments
+     `(#:include (cons* "^elpy\\/" "^snippets\\/" %default-include)
+       #:phases
+       ;; TODO: Make `elpy-config' display Guix commands :)
+       (modify-phases %standard-phases
+         ;; One elpy test depends on being run inside a Python virtual
+         ;; environment to pass. We have nothing to gain from doing so here,
+         ;; so we just trick Elpy into thinking we are (see:
+         ;; https://github.com/jorgenschaefer/elpy/pull/1293).
+         (add-before 'check 'fake-virtualenv
+           (lambda _
+             (setenv "VIRTUAL_ENV" "/tmp")))
+         ;; TODO: Remove after next release (see:
+         ;; https://github.com/jorgenschaefer/elpy/pull/1293).
+         (add-after 'unpack 'fix-broken-test
+           (lambda _
+             (substitute* "test/elpy-config-test.el"
+               (("python-check-command") "elpy-syntax-check-command")))))
+       #:tests? #t
+       #:test-command '("ert-runner")))
+    (propagated-inputs
+     `(("emacs-company" ,emacs-company)
+       ("emacs-find-file-in-project" ,emacs-find-file-in-project)
+       ("emacs-highlight-indentation" ,emacs-highlight-indentation)
+       ("emacs-yasnippet" ,emacs-yasnippet)
+       ("pyvenv" ,emacs-pyvenv)
+       ("s" ,emacs-s)))
+    (native-inputs
+     ;; TODO: Generate texinfo documentation.
+     `(("ert-runner" ,ert-runner)
+       ("emacs-f" ,emacs-f)
+       ("python" ,python-wrapper)
+       ("python-autopep8" ,python-autopep8)
+       ("python-black" ,python-black)
+       ("python-flake8" ,python-flake8)
+       ("python-jedi" ,python-jedi)
+       ("python-yapf" ,python-yapf)))
+    (home-page "https://github.com/jorgenschaefer/elpy")
+    (synopsis "Python development environment for Emacs")
+    (description "Elpy brings powerful Python editing to Emacs.  It combines
+and configures a number of other packages written in Emacs Lisp as well
+as Python.")
+    (license license:gpl3+)))
+
 (define-public emacs-rainbow-delimiters
   (package
     (name "emacs-rainbow-delimiters")
-- 
2.18.0