[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#64406: [PATCH] Improve commands to manage Python imports
From: |
Matthias Meulien |
Subject: |
bug#64406: [PATCH] Improve commands to manage Python imports |
Date: |
Thu, 13 Jul 2023 23:07:40 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) |
Eli Zaretskii <eliz@gnu.org> writes:
>> Cc: 64406@debbugs.gnu.org
>> From: Matthias Meulien <orontee@gmail.com>
>> Date: Sun, 09 Jul 2023 08:09:17 +0200
>>
>> Here are two patches.
>>
>> The first one revert part of the original patch where I introduced a
>> useless detailed check of isort exit status itself.
>>
>> The second one relates to your remarks: It shift the custom exit status
>> of the Python script and make sure that an error is reported assoon as
>> exit code >0.
>
> Thanks. Could you please make a single patch from these two? There's
> no need to revert the original one in a separate patch.
Yes.
>> Subject: [PATCH 1/2] Fix "Improve Python imports management commands"
>>
>> * lisp/progmodes/python.el (python--do-isort): The isort library don't
>> check for its version itself!
>
> I don't think I understand this log entry. What does it mean "the
> isort library don't check its version"?
You're right, it doesn't make sense.
>> + ((eq 3 status) " (maybe isort version is less than 5.7.0?)")
> ^^^^^^^
> Here, "is older" should be more clear, I think.
Ok.
>From 778324822a9e191e33e6890555d65d3500a7109c Mon Sep 17 00:00:00 2001
From: Matthias Meulien <orontee@gmail.com>
Date: Thu, 13 Jul 2023 22:47:01 +0200
Subject: [PATCH] Fix "Improve Python imports management commands"
* lisp/progmodes/python.el (python--list-imports): Prefer to use an
exit status >1.
(python--list-imports-check-status): New function to check status of
Python script.
(python--do-isort): Fix wrong status check introduced with
6295d7abdd4.
---
lisp/progmodes/python.el | 29 +++++++++++++++--------------
1 file changed, 15 insertions(+), 14 deletions(-)
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 4291ab03ca6..a23339a2180 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -6451,9 +6451,9 @@ python--list-imports
try:
from isort import find_imports_in_stream, find_imports_in_paths
except ModuleNotFoundError:
- exit(1)
-except ImportError:
exit(2)
+except ImportError:
+ exit(3)
query, files, result = argv[1] or None, argv[2:], {}
@@ -6484,6 +6484,17 @@ python--import-sources
(project-files proj))
(list default-directory)))
+(defun python--list-imports-check-status (status)
+ (unless (eq 0 status)
+ (let* ((details
+ (cond
+ ((eq 2 status) " (maybe isort is missing?)")
+ ((eq 3 status) " (maybe isort version is older than 5.7.0?)")
+ (t "")))
+ (msg
+ (concat "%s exited with status %s" details)))
+ (error msg python-interpreter status))))
+
(defun python--list-imports (name source)
"List all Python imports matching NAME in SOURCE.
If NAME is nil, list all imports. SOURCE can be a buffer or a
@@ -6507,13 +6518,7 @@ python--list-imports
(or name "")
(mapcar #'file-local-name source)))))
lines)
- (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)))
+ (python--list-imports-check-status status)
(goto-char (point-min))
(while (not (eobp))
(push (buffer-substring-no-properties (point) (pos-eol))
@@ -6556,13 +6561,9 @@ python--do-isort
nil (list temp nil) nil
"-m" "isort" "-" args))
(tick (buffer-chars-modified-tick)))
- (cond
- ((eq 1 status)
+ (unless (eq 0 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)))))))))
--
2.39.2