From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Matthias Meulien Newsgroups: gmane.emacs.bugs Subject: bug#64406: [PATCH] Improve commands to manage Python imports Date: Thu, 13 Jul 2023 23:07:40 +0200 Message-ID: <87jzv3v7tv.fsf@gmail.com> References: <874jmnbd5v.fsf@gmail.com> <87pm534puk.fsf@gmail.com> <87lefr399j.fsf@gmail.com> <87bkgl39bm.fsf@gmail.com> <83cz0w5opl.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="39183"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: arstoffel@gmail.com, 64406@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Jul 13 23:08:28 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qK3Y4-000A3O-LN for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 13 Jul 2023 23:08:28 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qK3Xh-00081H-4I; Thu, 13 Jul 2023 17:08:05 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qK3Xe-000815-VX for bug-gnu-emacs@gnu.org; Thu, 13 Jul 2023 17:08:02 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qK3Xe-0006fo-NW for bug-gnu-emacs@gnu.org; Thu, 13 Jul 2023 17:08:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qK3Xe-0006jD-8V for bug-gnu-emacs@gnu.org; Thu, 13 Jul 2023 17:08:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Matthias Meulien Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 13 Jul 2023 21:08:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 64406 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 64406-submit@debbugs.gnu.org id=B64406.168928247625846 (code B ref 64406); Thu, 13 Jul 2023 21:08:02 +0000 Original-Received: (at 64406) by debbugs.gnu.org; 13 Jul 2023 21:07:56 +0000 Original-Received: from localhost ([127.0.0.1]:40924 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qK3XX-0006io-K6 for submit@debbugs.gnu.org; Thu, 13 Jul 2023 17:07:55 -0400 Original-Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]:51389) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qK3XQ-0006iN-Vt for 64406@debbugs.gnu.org; Thu, 13 Jul 2023 17:07:53 -0400 Original-Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-3fbf1b82d9cso10986805e9.2 for <64406@debbugs.gnu.org>; Thu, 13 Jul 2023 14:07:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689282463; x=1691874463; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=Osza25XA+V7gL+jg/98CSJVL2c3hvYFwu7QN9ne6InY=; b=h7tHA/UeDbrinlkEDJkt1yYTTXeYx3qjiB9hzURgQhqfBD0XjZH+MFLt/i/TamuLVQ 1K9JF/h8gOIU5kcyhVggQ2ngz6u5L+qPPqt2gcMRnSMSa5Y/xLHiYC7WaAag/OOQoQQz kmdWjgzLCDQlX15F08RzJUK/nAVqLYCOIoUACbc76/qbICtmPVGnwLn0nrVGfchDV4th wi6ocRRFwFqpHckAJzkxzjkP2MdOYLmIkkcenOXspU+SeJFaSiCtu7dDt3GD4CK8t8aq X7nSgrsNOVNk7LTF3JqeleZEh70hthDSnJBN4WR6nxocade+eHu9abNlyvoAxkKgt+Qr p7dQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689282463; x=1691874463; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Osza25XA+V7gL+jg/98CSJVL2c3hvYFwu7QN9ne6InY=; b=ifvIT4YlzkogTw2jMXGLIyRe4+0413P0/Z7joZpPCSlwrFB6hoGCly5Bt6qK7Yy9Bv NhNdCOJVfl/UI3WOtORsONMQ87f+HO4ZPukEmzCsp2GWfY2m262fPhk1jjxfWvwDuYe9 ah97rB6w79e+tA03bGKO/3Wx2Zd+7hCQOdUftw6CJ8ixewlDdnNKQ90PaNWyX2ikCbsY liazkaKLzn9DojZUUO+iVmzUHwkTe0SNj2DRrtCebI1Iidc41CZ6qs1ezXp/Z4ogIaWm b5XdceOIQ2HlfL9m0KKbjBx4mgXsIhi2m3ESryqaJDbm8MgpHGbajTbn7Fasb8Abt8uP +eYw== X-Gm-Message-State: ABy/qLYFMTWKDBtCmnPfgkCK3L3GP6aWeoJ5Qhq+oRYkKCI1gNDrPg1v p/LtACK6t3VkUw6GEz0nX5iTQGHfGcFh6Q== X-Google-Smtp-Source: APBJJlGWlhFVENYthny450SnkbfznTiTiZejuGJXhvO1FwBmt9tYAzlb6QX4yIt7H/SCp0m4mUxFeg== X-Received: by 2002:a7b:cc81:0:b0:3fb:fca1:1965 with SMTP id p1-20020a7bcc81000000b003fbfca11965mr2217606wma.18.1689282462588; Thu, 13 Jul 2023 14:07:42 -0700 (PDT) Original-Received: from carbon.localdomain ([2a01:e0a:245:c850:98f5:429a:aa8e:95bb]) by smtp.gmail.com with ESMTPSA id k12-20020a7bc30c000000b003fba92fad35sm19148575wmj.26.2023.07.13.14.07.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jul 2023 14:07:41 -0700 (PDT) In-Reply-To: <83cz0w5opl.fsf@gnu.org> (Eli Zaretskii's message of "Thu, 13 Jul 2023 09:07:34 +0300") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:265049 Archived-At: --=-=-= Content-Type: text/plain Eli Zaretskii writes: >> Cc: 64406@debbugs.gnu.org >> From: Matthias Meulien >> 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. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Fix-Improve-Python-imports-management-commands.patch >From 778324822a9e191e33e6890555d65d3500a7109c Mon Sep 17 00:00:00 2001 From: Matthias Meulien 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 --=-=-=--