emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 6295d7abdd4: Improve Python imports management commands


From: Eli Zaretskii
Subject: master 6295d7abdd4: Improve Python imports management commands
Date: Thu, 6 Jul 2023 03:27:45 -0400 (EDT)

branch: master
commit 6295d7abdd43ed6611cc3dd0682d56265cbc4528
Author: Matthias Meulien <orontee@gmail.com>
Commit: Eli Zaretskii <eliz@gnu.org>

    Improve Python imports management commands
    
    * lisp/progmodes/python.el (python--list-imports): Handle import
    errors.
    (python--do-isort): Specialize error message.  (Bug#64406)
---
 lisp/progmodes/python.el | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 50d712ebb0c..4291ab03ca6 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -6446,8 +6446,14 @@ REPORT-FN is Flymake's callback function."
 
 ;;; Import management
 (defconst python--list-imports "\
-from isort import find_imports_in_stream, find_imports_in_paths
-from sys import argv, stdin
+from sys import argv, exit, stdin
+
+try:
+    from isort import find_imports_in_stream, find_imports_in_paths
+except ModuleNotFoundError:
+    exit(1)
+except ImportError:
+    exit(2)
 
 query, files, result = argv[1] or None, argv[2:], {}
 
@@ -6501,9 +6507,13 @@ recursively."
                                 (or name "")
                                 (mapcar #'file-local-name source)))))
              lines)
-        (unless (eq 0 status)
+        (cond
+         ((eq 1 status)
           (error "%s exited with status %s (maybe isort is missing?)"
                  python-interpreter status))
+         ((eq 2 status)
+          (error "%s exited with status %s (maybe isort version is <5.7.0?)"
+                 python-interpreter status)))
         (goto-char (point-min))
         (while (not (eobp))
          (push (buffer-substring-no-properties (point) (pos-eol))
@@ -6546,9 +6556,13 @@ Return non-nil if the buffer was actually modified."
                                nil (list temp nil) nil
                                "-m" "isort" "-" args))
                 (tick (buffer-chars-modified-tick)))
-            (unless (eq 0 status)
+            (cond
+             ((eq 1 status)
               (error "%s exited with status %s (maybe isort is missing?)"
                      python-interpreter status))
+             ((eq 2 status)
+              (error "%s exited with status %s (maybe isort version is 
<5.7.0?)"
+                     python-interpreter status)))
             (replace-buffer-contents temp)
             (not (eq tick (buffer-chars-modified-tick)))))))))
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]