aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes/python.el
diff options
context:
space:
mode:
authorMatthias Meulien2023-07-01 22:12:43 +0200
committerEli Zaretskii2023-07-06 10:27:14 +0300
commit6295d7abdd43ed6611cc3dd0682d56265cbc4528 (patch)
treeff6c5456462357bd3de0b7e583bc7c24e3798dde /lisp/progmodes/python.el
parentcb906249450aeec41f73273b69af097e84cc681a (diff)
downloademacs-6295d7abdd43ed6611cc3dd0682d56265cbc4528.tar.gz
emacs-6295d7abdd43ed6611cc3dd0682d56265cbc4528.zip
Improve Python imports management commands
* lisp/progmodes/python.el (python--list-imports): Handle import errors. (python--do-isort): Specialize error message. (Bug#64406)
Diffstat (limited to 'lisp/progmodes/python.el')
-rw-r--r--lisp/progmodes/python.el22
1 files 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."
6446 6446
6447;;; Import management 6447;;; Import management
6448(defconst python--list-imports "\ 6448(defconst python--list-imports "\
6449from isort import find_imports_in_stream, find_imports_in_paths 6449from sys import argv, exit, stdin
6450from sys import argv, stdin 6450
6451try:
6452 from isort import find_imports_in_stream, find_imports_in_paths
6453except ModuleNotFoundError:
6454 exit(1)
6455except ImportError:
6456 exit(2)
6451 6457
6452query, files, result = argv[1] or None, argv[2:], {} 6458query, files, result = argv[1] or None, argv[2:], {}
6453 6459
@@ -6501,9 +6507,13 @@ recursively."
6501 (or name "") 6507 (or name "")
6502 (mapcar #'file-local-name source))))) 6508 (mapcar #'file-local-name source)))))
6503 lines) 6509 lines)
6504 (unless (eq 0 status) 6510 (cond
6511 ((eq 1 status)
6505 (error "%s exited with status %s (maybe isort is missing?)" 6512 (error "%s exited with status %s (maybe isort is missing?)"
6506 python-interpreter status)) 6513 python-interpreter status))
6514 ((eq 2 status)
6515 (error "%s exited with status %s (maybe isort version is <5.7.0?)"
6516 python-interpreter status)))
6507 (goto-char (point-min)) 6517 (goto-char (point-min))
6508 (while (not (eobp)) 6518 (while (not (eobp))
6509 (push (buffer-substring-no-properties (point) (pos-eol)) 6519 (push (buffer-substring-no-properties (point) (pos-eol))
@@ -6546,9 +6556,13 @@ Return non-nil if the buffer was actually modified."
6546 nil (list temp nil) nil 6556 nil (list temp nil) nil
6547 "-m" "isort" "-" args)) 6557 "-m" "isort" "-" args))
6548 (tick (buffer-chars-modified-tick))) 6558 (tick (buffer-chars-modified-tick)))
6549 (unless (eq 0 status) 6559 (cond
6560 ((eq 1 status)
6550 (error "%s exited with status %s (maybe isort is missing?)" 6561 (error "%s exited with status %s (maybe isort is missing?)"
6551 python-interpreter status)) 6562 python-interpreter status))
6563 ((eq 2 status)
6564 (error "%s exited with status %s (maybe isort version is <5.7.0?)"
6565 python-interpreter status)))
6552 (replace-buffer-contents temp) 6566 (replace-buffer-contents temp)
6553 (not (eq tick (buffer-chars-modified-tick))))))))) 6567 (not (eq tick (buffer-chars-modified-tick)))))))))
6554 6568