Skip to content

Commit 3c041e3

Browse files
oronteeEli-Zaretskii
authored andcommitted
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.
1 parent a5a8de4 commit 3c041e3

File tree

2 files changed

+45
-18
lines changed

2 files changed

+45
-18
lines changed

etc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,10 @@ instead of:
411411
and another_expression):
412412
do_something()
413413

414+
*** New user option 'python-interpreter-args'.
415+
This allows the user to specify command line arguments to the non
416+
interactive Python interpreter specified by 'python-interpreter'.
417+
414418
** use-package
415419

416420
+++

lisp/progmodes/python.el

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -297,11 +297,18 @@
297297

298298
(defcustom python-interpreter "python"
299299
"Python interpreter for noninteractive use.
300-
To customize the Python shell, modify `python-shell-interpreter'
301-
instead."
300+
Some Python interpreters also require changes to
301+
`python-interpreter-args'.
302+
303+
To customize the Python interpreter for interactive use, modify
304+
`python-shell-interpreter' instead."
302305
:version "29.1"
303306
:type 'string)
304307

308+
(defcustom python-interpreter-args ""
309+
"Arguments for the Python interpreter for noninteractive use."
310+
:version "30.1"
311+
:type 'string)
305312

306313

307314
;;; Bindings
@@ -2558,7 +2565,7 @@ position, else returns nil."
25582565
(cond ((executable-find "python3") "python3")
25592566
((executable-find "python") "python")
25602567
(t "python3"))
2561-
"Default Python interpreter for shell.
2568+
"Python interpreter for interactive use.
25622569

25632570
Some Python interpreters also require changes to
25642571
`python-shell-interpreter-args'. In particular, setting
@@ -2573,11 +2580,12 @@ Some Python interpreters also require changes to
25732580
:safe 'stringp)
25742581

25752582
(defcustom python-shell-interpreter-args "-i"
2576-
"Default arguments for the Python interpreter."
2583+
"Arguments for the Python interpreter for interactive use."
25772584
:type 'string)
25782585

25792586
(defcustom python-shell-interpreter-interactive-arg "-i"
2580-
"Interpreter argument to force it to run interactively."
2587+
"Interpreter argument to force it to run interactively.
2588+
This is used only for prompt detection."
25812589
:type 'string
25822590
:version "24.4")
25832591

@@ -6505,18 +6513,25 @@ recursively."
65056513
(let* ((temp (current-buffer))
65066514
(status (if (bufferp source)
65076515
(with-current-buffer source
6508-
(call-process-region (point-min) (point-max)
6509-
python-interpreter
6510-
nil (list temp nil) nil
6511-
"-c" python--list-imports
6512-
(or name "")))
6516+
(apply #'call-process-region
6517+
(point-min) (point-max)
6518+
python-interpreter
6519+
nil (list temp nil) nil
6520+
(append
6521+
(split-string-shell-command
6522+
python-interpreter-args)
6523+
`("-c" ,python--list-imports)
6524+
(list (or name "")))))
65136525
(with-current-buffer buffer
65146526
(apply #'call-process
65156527
python-interpreter
65166528
nil (list temp nil) nil
6517-
"-c" python--list-imports
6518-
(or name "")
6519-
(mapcar #'file-local-name source)))))
6529+
(append
6530+
(split-string-shell-command
6531+
python-interpreter-args)
6532+
`("-c" ,python--list-imports)
6533+
(list (or name ""))
6534+
(mapcar #'file-local-name source))))))
65206535
lines)
65216536
(python--list-imports-check-status status)
65226537
(goto-char (point-min))
@@ -6559,7 +6574,11 @@ Return non-nil if the buffer was actually modified."
65596574
(point-min) (point-max)
65606575
python-interpreter
65616576
nil (list temp nil) nil
6562-
"-m" "isort" "-" args))
6577+
(append
6578+
(split-string-shell-command
6579+
python-interpreter-args)
6580+
'("-m" "isort" "-")
6581+
args)))
65636582
(tick (buffer-chars-modified-tick)))
65646583
(unless (eq 0 status)
65656584
(error "%s exited with status %s (maybe isort is missing?)"
@@ -6629,10 +6648,14 @@ asking."
66296648
(with-temp-buffer
66306649
(let ((temp (current-buffer)))
66316650
(with-current-buffer buffer
6632-
(call-process-region (point-min) (point-max)
6633-
python-interpreter
6634-
nil temp nil
6635-
"-m" "pyflakes"))
6651+
(apply #'call-process-region
6652+
(point-min) (point-max)
6653+
python-interpreter
6654+
nil temp nil
6655+
(append
6656+
(split-string-shell-command
6657+
python-interpreter-args)
6658+
'("-m" "pyflakes"))))
66366659
(goto-char (point-min))
66376660
(when (looking-at-p ".* No module named pyflakes$")
66386661
(error "%s couldn't find pyflakes" python-interpreter))

0 commit comments

Comments
 (0)