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.
This commit is contained in:
Matthias Meulien 2023-07-13 23:38:41 +02:00 committed by Eli Zaretskii
parent a5a8de4099
commit 3c041e3e96
2 changed files with 45 additions and 18 deletions

View file

@ -411,6 +411,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
+++

View file

@ -297,11 +297,18 @@
(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)
;;; Bindings
@ -2558,7 +2565,7 @@ position, else returns nil."
(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 @@ Some Python interpreters also require changes to
: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")
@ -6505,18 +6513,25 @@ recursively."
(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)
(python--list-imports-check-status status)
(goto-char (point-min))
@ -6559,7 +6574,11 @@ Return non-nil if the buffer was actually modified."
(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)))
(unless (eq 0 status)
(error "%s exited with status %s (maybe isort is missing?)"
@ -6629,10 +6648,14 @@ asking."
(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))