unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Matthias Meulien <orontee@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: kobarity <kobarity@gmail.com>,
	arstoffel@gmail.com, 64397@debbugs.gnu.org
Subject: bug#64397: 29.0.91; Limited configuration of commands based on python-interpreter
Date: Thu, 13 Jul 2023 23:44:22 +0200	[thread overview]
Message-ID: <87fs5rv64p.fsf@gmail.com> (raw)
In-Reply-To: <83fs5s5phj.fsf@gnu.org> (Eli Zaretskii's message of "Thu, 13 Jul 2023 08:50:48 +0300")

[-- Attachment #1: Type: text/plain, Size: 1429 bytes --]

Eli Zaretskii <eliz@gnu.org> writes:

>> Date: Sun, 09 Jul 2023 21:17:48 +0900
>> From: kobarity <kobarity@gmail.com>
>> Cc: Eli Zaretskii <eliz@gnu.org>,
>> 	Augusto Stoffel <arstoffel@gmail.com>,
>> 	64397@debbugs.gnu.org
>> 
>> 
>> Matthias Meulien wrote:
>> > 
>> > kobarity <kobarity@gmail.com> writes:
>> > 
>> > > (...) How about the following descriptions?
>> > >
>> > > python-interpreter
>> > >   Python interpreter for noninteractive use.
>> > > python-interpreter-args
>> > >   Arguments for the Python interpreter for noninteractive use.
>> > > python-shell-interpreter
>> > >   Python interpreter for interactive use.
>> > > python-shell-interpreter-args
>> > >   Arguments for the Python interpreter for interactive use.
>> > 
>> > I like it.  But you skipped python-shell-interpreter-interactive-arg...
>> 
>> Sorry, I forgot about that.
>> `python-shell-interpreter-interactive-arg' is used only for prompt
>> detection, and its docstring has only one line:
>> 
>> Interpreter argument to force it to run interactively.
>> 
>> I think we can leave it as is, but if we want to improve it, how about
>> adding the second line?  I could not shorten it to fit on one line.
>> 
>> Interpreter argument to force it to run interactively.
>> This is used only for prompt detection.
>
> Thanks.
>
> Matthias, can you post an updated patch where the last comments about
> doc strings are taken care of?

Yes, here it is.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Custom-var-python-interpreter-args-bug-64397.patch --]
[-- Type: text/x-diff, Size: 6078 bytes --]

From e93577859330e8d7e42bc7cb7c9229ba6e722666 Mon Sep 17 00:00:00 2001
From: Matthias Meulien <orontee@gmail.com>
Date: Thu, 13 Jul 2023 23:38:41 +0200
Subject: [PATCH] Custom var python-interpreter-args (bug#64397)

* lisp/progmodes/python.el (python-interpreter): Mention new variable
in documentation.
(python-interpreter-args): New custom variable.
(python-shell-interpreter, python-shell-interpreter-args)
(python-shell-interpreter-interactive-arg): Improve documentation.
(python--list-imports, python--do-isort, python-fix-imports): Make
process use customisable arguments.
---
 etc/NEWS                 |  4 +++
 lisp/progmodes/python.el | 59 ++++++++++++++++++++++++++++------------
 2 files changed, 45 insertions(+), 18 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index 5d5ea990b92..ee099189e3b 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -397,6 +397,10 @@ instead of:
         and another_expression):
         do_something()
 
+*** New user option 'python-interpreter-args'.
+This allows the user to specify command line arguments to the non
+interactive Python interpreter specified by 'python-interpreter'.
+
 ** use-package
 
 +++
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 4291ab03ca6..e7044012cde 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -297,11 +297,18 @@ python
 
 (defcustom python-interpreter "python"
   "Python interpreter for noninteractive use.
-To customize the Python shell, modify `python-shell-interpreter'
-instead."
+Some Python interpreters also require changes to
+`python-interpreter-args'.
+
+To customize the Python interpreter for interactive use, modify
+`python-shell-interpreter' instead."
   :version "29.1"
   :type 'string)
 
+(defcustom python-interpreter-args ""
+  "Arguments for the Python interpreter for noninteractive use."
+  :version "30.1"
+  :type 'string)
 
 \f
 ;;; Bindings
@@ -2558,7 +2565,7 @@ python-shell-interpreter
   (cond ((executable-find "python3") "python3")
         ((executable-find "python") "python")
         (t "python3"))
-  "Default Python interpreter for shell.
+  "Python interpreter for interactive use.
 
 Some Python interpreters also require changes to
 `python-shell-interpreter-args'.  In particular, setting
@@ -2573,11 +2580,12 @@ python-shell-internal-buffer-name
   :safe 'stringp)
 
 (defcustom python-shell-interpreter-args "-i"
-  "Default arguments for the Python interpreter."
+  "Arguments for the Python interpreter for interactive use."
   :type 'string)
 
 (defcustom python-shell-interpreter-interactive-arg "-i"
-  "Interpreter argument to force it to run interactively."
+  "Interpreter argument to force it to run interactively.
+This is used only for prompt detection."
   :type 'string
   :version "24.4")
 
@@ -6494,18 +6502,25 @@ python--list-imports
       (let* ((temp (current-buffer))
              (status (if (bufferp source)
                          (with-current-buffer source
-                           (call-process-region (point-min) (point-max)
-                                                python-interpreter
-                                                nil (list temp nil) nil
-                                                "-c" python--list-imports
-                                                (or name "")))
+                           (apply #'call-process-region
+                                  (point-min) (point-max)
+                                  python-interpreter
+                                  nil (list temp nil) nil
+                                  (append
+                                   (split-string-shell-command
+                                    python-interpreter-args)
+                                   `("-c" ,python--list-imports)
+                                    (list (or name "")))))
                        (with-current-buffer buffer
                          (apply #'call-process
                                 python-interpreter
                                 nil (list temp nil) nil
-                                "-c" python--list-imports
-                                (or name "")
-                                (mapcar #'file-local-name source)))))
+                                (append
+                                 (split-string-shell-command
+                                  python-interpreter-args)
+                                 `("-c" ,python--list-imports)
+                                 (list (or name ""))
+                                 (mapcar #'file-local-name source))))))
              lines)
         (cond
          ((eq 1 status)
@@ -6554,7 +6569,11 @@ python--do-isort
                                (point-min) (point-max)
                                python-interpreter
                                nil (list temp nil) nil
-                               "-m" "isort" "-" args))
+                               (append
+                                 (split-string-shell-command
+                                  python-interpreter-args)
+                                 '("-m" "isort" "-")
+                                 args)))
                 (tick (buffer-chars-modified-tick)))
             (cond
              ((eq 1 status)
@@ -6628,10 +6647,14 @@ python-fix-imports
     (with-temp-buffer
       (let ((temp (current-buffer)))
         (with-current-buffer buffer
-          (call-process-region (point-min) (point-max)
-                               python-interpreter
-                               nil temp nil
-                               "-m" "pyflakes"))
+          (apply #'call-process-region
+                  (point-min) (point-max)
+                  python-interpreter
+                  nil temp nil
+                  (append
+                   (split-string-shell-command
+                    python-interpreter-args)
+                   '("-m" "pyflakes"))))
         (goto-char (point-min))
         (when (looking-at-p ".* No module named pyflakes$")
           (error "%s couldn't find pyflakes" python-interpreter))
-- 
2.39.2


  reply	other threads:[~2023-07-13 21:44 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-01  6:33 bug#64397: 29.0.91; Limited configuration of commands based on python-interpreter Matthias Meulien
2023-07-01 16:10 ` Matthias Meulien
2023-07-06  7:21   ` Eli Zaretskii
2023-07-06 14:51     ` kobarity
2023-07-07  8:09       ` Augusto Stoffel
2023-07-06 20:39     ` Matthias Meulien
2023-07-08  7:52       ` Eli Zaretskii
2023-07-08 11:28         ` kobarity
2023-07-08 13:50           ` Eli Zaretskii
2023-07-08 16:28           ` Matthias Meulien
2023-07-09 12:17             ` kobarity
2023-07-13  5:50               ` Eli Zaretskii
2023-07-13 21:44                 ` Matthias Meulien [this message]
2023-07-15  8:30                   ` Eli Zaretskii
2023-07-17 19:17                     ` Matthias Meulien
2023-07-20 16:02                       ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87fs5rv64p.fsf@gmail.com \
    --to=orontee@gmail.com \
    --cc=64397@debbugs.gnu.org \
    --cc=arstoffel@gmail.com \
    --cc=eliz@gnu.org \
    --cc=kobarity@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).