[PATCH 0/4] Add Importmagic

OpenSubmitted by Ryan Prior.
Details
3 participants
  • Nicolas Goaziou
  • Marius Bakke
  • Ryan Prior
Owner
unassigned
Severity
normal
R
R
Ryan Prior wrote on 17 May 2020 20:32
(address . guix-patches@gnu.org)
20200517183241.16325-1-rprior@protonmail.com
Importmagic fixes Python imports automatically. It has a few dependencies
(sexpdata, epc) not yet packaged in Guix, and a corresponding Emacs mode.

Ryan Prior (4):
gnu: Add python-importmagic.
gnu: Add python-sexpdata.
gnu: Add python-epc.
gnu: Add emacs-importmagic.

gnu/packages/emacs-xyz.scm | 23 ++++++++++++++
gnu/packages/python-xyz.scm | 62 +++++++++++++++++++++++++++++++++++++
2 files changed, 85 insertions(+)

--
2.17.1
R
R
Ryan Prior wrote on 17 May 2020 20:41
[PATCH 2/4] gnu: Add python-sexpdata.
(address . 41366@debbugs.gnu.org)
20200517184142.16603-2-rprior@protonmail.com
* gnu/packages/python-xyz.scm (python-sexpdata): New variable.
---
gnu/packages/python-xyz.scm | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)

Toggle diff (32 lines)
diff --git a/gnu/packages/python-xyz.scm b/gnu/packages/python-xyz.scm
index 131d8c6d35..58de95b21a 100644
--- a/gnu/packages/python-xyz.scm
+++ b/gnu/packages/python-xyz.scm
@@ -5769,6 +5769,25 @@ them as the version argument or in a SCM managed file.")
 (define-public python2-setuptools-scm
   (package-with-python2 python-setuptools-scm))
 
+(define-public python-sexpdata
+  (package
+    (name "python-sexpdata")
+    (version "0.0.3")
+    (source
+     (origin
+       (method url-fetch)
+       (uri (pypi-uri "sexpdata" version))
+       (sha256
+        (base32
+         "1q4lsjyzzqrdv64l0pv4ij9nd8gqhvxqcrpxc2xpxs652sk2gj0s"))))
+    (build-system python-build-system)
+    (home-page "https://github.com/jd-boyd/sexpdata")
+    (synopsis "S-expression parser for Python")
+    (description
+     "Sexpdata is an S-expression parser/serializer.  It has load and dump
+functions like pickle, json or PyYAML module.")
+    (license license:bsd-3)))
+
 (define-public python-pathlib2
   (package
     (name "python-pathlib2")
-- 
2.17.1
R
R
Ryan Prior wrote on 17 May 2020 20:41
[PATCH 1/4] gnu: Add python-importmagic.
(address . 41366@debbugs.gnu.org)
20200517184142.16603-1-rprior@protonmail.com
* gnu/packages/python-xyz.el (python-importmagic): New variable.
---
gnu/packages/python-xyz.scm | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)

Toggle diff (40 lines)
diff --git a/gnu/packages/python-xyz.scm b/gnu/packages/python-xyz.scm
index c26a766d64..131d8c6d35 100644
--- a/gnu/packages/python-xyz.scm
+++ b/gnu/packages/python-xyz.scm
@@ -77,6 +77,7 @@
 ;;; Copyright © 2020 Lars-Dominik Braun <ldb@leibniz-psychology.org>
 ;;; Copyright © 2020 Alex ter Weele <alex.ter.weele@gmail.com>
 ;;; Copyright © 2020 Matthew Kraai <kraai@ftbfs.org>
+;;; Copyright © 2020 Ryan Prior <rprior@protonmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -5897,6 +5898,25 @@ need to use the older and less efficient @code{pkg_resources} package.")
        ("python-contextlib2" ,python2-contextlib2-bootstrap)
        ("python-importlib-resources" ,python2-importlib-resources-bootstrap))))))
 
+(define-public python-importmagic
+  (package
+    (name "python-importmagic")
+    (version "0.1.7")
+    (source
+     (origin
+       (method url-fetch)
+       (uri (pypi-uri "importmagic" version))
+       (sha256
+        (base32
+         "1n7qxa1snj06aw45mcfz7bxc46zp7fxj687140g2k6jcnyjmfxrz"))))
+    (build-system python-build-system)
+    (home-page "https://github.com/alecthomas/importmagic")
+    (synopsis "Library for adding, removing and managing Python imports")
+    (description
+     "Importmagic is a Python library for automatically managing imports by
+finding unresolved symbols in Python code and their corresponding imports.")
+    (license license:bsd-3)))
+
 (define-public python-jaraco-packaging
   (package
     (name "python-jaraco-packaging")
-- 
2.17.1
R
R
Ryan Prior wrote on 17 May 2020 20:41
[PATCH 3/4] gnu: Add python-epc.
(address . 41366@debbugs.gnu.org)
20200517184142.16603-3-rprior@protonmail.com
* gnu/packages/python-xyz.py (python-epc): New variable.
---
gnu/packages/python-xyz.scm | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)

Toggle diff (36 lines)
diff --git a/gnu/packages/python-xyz.scm b/gnu/packages/python-xyz.scm
index 58de95b21a..0ec672259b 100644
--- a/gnu/packages/python-xyz.scm
+++ b/gnu/packages/python-xyz.scm
@@ -8826,6 +8826,29 @@ functions to find and load entry points.")
 (define-public python2-entrypoints
   (package-with-python2 python-entrypoints))
 
+(define-public python-epc
+  (package
+    (name "python-epc")
+    (version "0.0.5")
+    (source
+     (origin
+       (method url-fetch)
+       (uri (pypi-uri "epc" version))
+       (sha256
+        (base32
+         "09bx1ln1bwa00917dndlgs4k589h8qx2x080xch5m58p92kjwkd1"))))
+    (build-system python-build-system)
+    (propagated-inputs
+     `(("python-sexpdata" ,python-sexpdata)))
+    (native-inputs
+     `(("python-nose" ,python-nose)))
+    (home-page "https://github.com/tkf/python-epc")
+    (synopsis "Remote procedure call (RPC) stack for Emacs Lisp and Python")
+    (description
+     "Python-EPC can call elisp functions from Python and Python functions
+from elisp.")
+    (license license:gpl3)))
+
 (define-public python-nbconvert
   (package
     (name "python-nbconvert")
-- 
2.17.1
R
R
Ryan Prior wrote on 17 May 2020 20:42
[PATCH 4/4] gnu: Add emacs-importmagic.
(address . 41366@debbugs.gnu.org)
20200517184142.16603-4-rprior@protonmail.com
* gnu/packages/emacs-xyz.py (emacs-importmagic): New variable.
---
gnu/packages/emacs-xyz.scm | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)

Toggle diff (43 lines)
diff --git a/gnu/packages/emacs-xyz.scm b/gnu/packages/emacs-xyz.scm
index 4bbd482409..859417dc62 100644
--- a/gnu/packages/emacs-xyz.scm
+++ b/gnu/packages/emacs-xyz.scm
@@ -70,6 +70,7 @@
 ;;; Copyright © 2020 Alberto Eleuterio Flores Guerrero <barbanegra+guix@posteo.mx>
 ;;; Copyright © 2020 Marius Bakke <mbakke@fastmail.com>
 ;;; Copyright © 2020 pinoaffe <pinoaffe@airmail.cc>
+;;; Copyright © 2020 Ryan Prior <rprior@protonmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -16625,6 +16626,28 @@ provided by other Emacs packages dealing with pass:
 image, rotate it, save modified images, and more.")
       (license license:gpl3+))))
 
+(define-public emacs-importmagic
+  (package
+    (name "emacs-importmagic")
+    (version "20180520.303")
+    (source
+     (origin
+       (method url-fetch)
+       (uri
+        (string-append "https://melpa.org/packages/importmagic-" version ".tar"))
+       (sha256
+        (base32 "0xk4i4x4836ksv2pr3aarpbkq6b5sz8c3y6f39fwf698v8zirhs9"))))
+    (build-system emacs-build-system)
+    (propagated-inputs
+     `(("emacs-epc" ,emacs-epc)
+       ("emacs-f" ,emacs-f)
+       ("python-epc" ,python-epc)
+       ("python-importmagic" ,python-importmagic)))
+    (home-page "https://github.com/anachronic/importmagic.el")
+    (synopsis "Fix Python imports")
+    (description "Importmagic.el fixes unresolved imports in Python buffers.")
+    (license license:gpl3)))
+
 (define-public emacs-package-lint
   (let ((commit "69bb89d00ba212b734c676ad056aa793c450b288"))
     (package
-- 
2.17.1
M
M
Marius Bakke wrote on 23 May 2020 21:02
87o8qe79vj.fsf@devup.no
Ryan Prior via Guix-patches via <guix-patches@gnu.org> writes:

Toggle quote (2 lines)
> * gnu/packages/emacs-xyz.py (emacs-importmagic): New variable.

Thanks! This patch did not apply for me somehow, can you rebase on the
current master branch?

I applied the other three, all LGTM.
-----BEGIN PGP SIGNATURE-----

iQEzBAEBCgAdFiEEu7At3yzq9qgNHeZDoqBt8qM6VPoFAl7Jc0AACgkQoqBt8qM6
VPo3Pwf+LW1PdANrq1PymtnY7w3ELQZVzKTvjuYaZr98kGjs1ep/Rh0sDTjbgMNl
xg9ZCnqJvViwmBoIDY8A9GbOAcx9bP5BmuBrjQ7QFokjuhUAWHdcktmO47cF/SrZ
9L/VGuf5kVdkmcXqbLUd9L0I2v7r26UF5Gafc81PFRyRxlO8NW8R24+FQDbiiz3C
ZA0d3BfLirW9tY6I2/fHeyBhrrm7v7nKRroY5yc6ZfLlUcgDOBvyBTrI96cZY3hV
KaQCB0TcTdmJqohS5zr4+CcOt01cCcVxmeW5mcofc5+cfpdl1bOnhJtWgPpfBkI2
yId6tSj6zEgGXAB2cH00SHERewqJfg==
=RRFy
-----END PGP SIGNATURE-----

R
R
Ryan Prior wrote on 23 May 2020 21:27
(name . Marius Bakke)(address . mbakke@fastmail.com)
teSJzl5ZJmyFGIPgKRWlybzSW9oX3F5ygHglHRzZ5SXWqVaeDqcnW5d3nJJmEt_963MKLNLPZw3ik1laj28gVxvqa7Nie4z_XYEq5iF-odI=@protonmail.com
‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
On Saturday, May 23, 2020 7:02 PM, Marius Bakke <mbakke@fastmail.com> wrote:

Toggle quote (2 lines)
> This patch did not apply for me somehow

Looks like a conflict in the copyright line. (Something something lawyers.) New patch attached!

Toggle quote (2 lines)
> I applied the other three, all LGTM.

Thank you!


Ryan
From fdb49b29a29c2955a7efe39a0d20f0a8a0752bb4 Mon Sep 17 00:00:00 2001
From: Ryan Prior <rprior@protonmail.com>
Date: Sun, 17 May 2020 12:56:00 -0500
Subject: [PATCH] gnu: Add emacs-importmagic.

* gnu/packages/emacs-xyz.py (emacs-importmagic): New variable.
---
gnu/packages/emacs-xyz.scm | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)

Toggle diff (43 lines)
diff --git a/gnu/packages/emacs-xyz.scm b/gnu/packages/emacs-xyz.scm
index fe68a56fd6..94f5fdbb4e 100644
--- a/gnu/packages/emacs-xyz.scm
+++ b/gnu/packages/emacs-xyz.scm
@@ -71,6 +71,7 @@
 ;;; Copyright © 2020 Marius Bakke <mbakke@fastmail.com>
 ;;; Copyright © 2020 pinoaffe <pinoaffe@airmail.cc>
 ;;; Copyright © 2020 Vinicius Monego <monego@posteo.net>
+;;; Copyright © 2020 Ryan Prior <rprior@protonmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -16672,6 +16673,28 @@ provided by other Emacs packages dealing with pass:
 image, rotate it, save modified images, and more.")
       (license license:gpl3+))))
 
+(define-public emacs-importmagic
+  (package
+    (name "emacs-importmagic")
+    (version "20180520.303")
+    (source
+     (origin
+       (method url-fetch)
+       (uri
+        (string-append "https://melpa.org/packages/importmagic-" version ".tar"))
+       (sha256
+        (base32 "0xk4i4x4836ksv2pr3aarpbkq6b5sz8c3y6f39fwf698v8zirhs9"))))
+    (build-system emacs-build-system)
+    (propagated-inputs
+     `(("emacs-epc" ,emacs-epc)
+       ("emacs-f" ,emacs-f)
+       ("python-epc" ,python-epc)
+       ("python-importmagic" ,python-importmagic)))
+    (home-page "https://github.com/anachronic/importmagic.el")
+    (synopsis "Fix Python imports")
+    (description "Importmagic.el fixes unresolved imports in Python buffers.")
+    (license license:gpl3)))
+
 (define-public emacs-package-lint
   (let ((commit "69bb89d00ba212b734c676ad056aa793c450b288"))
     (package
-- 
2.26.2
N
N
Nicolas Goaziou wrote on 23 May 2020 22:00
(name . Ryan Prior via Guix-patches via)(address . guix-patches@gnu.org)
87lflibevo.fsf@nicolasgoaziou.fr
Hello,

Ryan Prior via Guix-patches via <guix-patches@gnu.org> writes:

Toggle quote (6 lines)
> + (propagated-inputs
> + `(("emacs-epc" ,emacs-epc)
> + ("emacs-f" ,emacs-f)
> + ("python-epc" ,python-epc)
> + ("python-importmagic" ,python-importmagic)))

OOC, are you sure Python packages need to be propagated in this case?

Regards,

--
Nicolas Goaziou
R
R
Ryan Prior wrote on 23 May 2020 22:41
(name . Nicolas Goaziou)(address . mail@nicolasgoaziou.fr)
mh3HQaHZyCgMpSKMhLf1PIKfM1C87zFz3Gf9DgJT3LoIxwYw8vjC6xau5z95g2oF5wgGxA4hY1-0Tf__vLty8oohgzIIZco9UPB-oDi1Kzk=@protonmail.com
‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
On Saturday, May 23, 2020 8:00 PM, Nicolas Goaziou <mail@nicolasgoaziou.fr> wrote:

Toggle quote (2 lines)
> OOC, are you sure Python packages need to be propagated in this case?

Hi Nicholas! I tried it with the python packages in "inputs" and impotmagic.el complained about not being able to find them. I'm going to be helping with maintenance of importmagic.el so maybe that's something I can fix on the package side?

At present this seems to work better. I don't know yet what the difference is between inputs and propagated-inputs when it comes to Python packages so maybe somebody else might have a better answer.

Ryan
M
M
Marius Bakke wrote on 23 May 2020 23:12
(address . 41366@debbugs.gnu.org)
871rna73ui.fsf@devup.no
Ryan Prior <rprior@protonmail.com> writes:

Toggle quote (9 lines)
> ‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
> On Saturday, May 23, 2020 8:00 PM, Nicolas Goaziou <mail@nicolasgoaziou.fr> wrote:
>
>> OOC, are you sure Python packages need to be propagated in this case?
>
> Hi Nicholas! I tried it with the python packages in "inputs" and impotmagic.el complained about not being able to find them. I'm going to be helping with maintenance of importmagic.el so maybe that's something I can fix on the package side?
>
> At present this seems to work better. I don't know yet what the difference is between inputs and propagated-inputs when it comes to Python packages so maybe somebody else might have a better answer.

The difference is that propagated-inputs will be installed to the
profile when you 'guix install emacs-importmagic'.

Propagating these will only work if the user already has 'python' in the
profile, which sets up PYTHONPATH.

For regular executables, we solve this by "wrapping" the executable with
PYTHONPATH to avoid the need for propagation.

Ideally we'd patch importmagic.el so that it automatically sets
PYTHONPATH referring to these two packages (prepending to any existing
PYTHONPATH). I think python-shell-interpreter also should use the
absolute file name of the "python" executable so it does not have to be
installed separately.

Do you think that can work?

Thanks for chiming in Nicolas, I had completely missed those propagated
Python packages. :-)
-----BEGIN PGP SIGNATURE-----

iQEzBAEBCgAdFiEEu7At3yzq9qgNHeZDoqBt8qM6VPoFAl7JkcUACgkQoqBt8qM6
VPp9OQgA1UGVo6SQHzk5mCp0nT+VxyKvIAiDiKAsKH/9ulot528pX2HPY0dq8j37
a5zbXK2qOMXF6blhtTWfwwbBA2AwO6ezOrpfk3xoAr3n5W8ZMouNdT+QnNzTRABu
ft3755BvBHs2e42FoHTe5kyTiYazts465ftKCqFiUu1tEQWb5S0lcWxxWJBetu6U
KSsFGQId8Nl4R/Z4I4ZlRFoKiWcl1jEId+NHBN7sa4sJ+e6Q3gibqbW4ahZnTKx9
ZMFqSd7yke4KGJKV0jWNvTTj4LlSTBZIp74z1kQT7AcXqPqcdRHPODK2kVebHh3B
uLfiU12Mp3WNCLjLGEAKccNgASHlIw==
=ezga
-----END PGP SIGNATURE-----

R
R
Ryan Prior wrote on 23 May 2020 23:18
(name . Marius Bakke)(address . mbakke@fastmail.com)
tZcu57rG0mQyS7slbEWBfMtR_7Zip0SISyoBaynvvGdicF4jYzfE32Ux4fOz6EUKCV1ZsOrpZwtcGEdqp9SGAD2ChadhMWVU38-En_MGv8U=@protonmail.com
‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
On Saturday, May 23, 2020 9:12 PM, Marius Bakke <mbakke@fastmail.com> wrote:

Toggle quote (2 lines)
> Do you think that can work?

I'm going to look into it. Prepending the PYTHONPATH and manipulating the python-shell-interpreter doesn't sound like it should be tricky.

Do you by chance know of other Emacs packages in Guix which do this kind of patching so I can look at an example? I'll do some grepping around and see what I can find, or just try something and iterate from there.


Ryan
?