From d56ab4c8fc8979dc5f07f40c2c0d87b336a09593 Mon Sep 17 00:00:00 2001 From: Matthias Meulien Date: Sat, 1 Jul 2023 16:07:01 +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--list-imports, python--do-isort, python-fix-imports): Make process use customisable arguments. --- etc/NEWS | 4 +++ lisp/progmodes/python.el | 53 ++++++++++++++++++++++++++++------------ 2 files changed, 42 insertions(+), 15 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index 1a86c9e55e2..46eab6c38bc 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -383,6 +383,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..4d5bcfcaa49 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -297,11 +297,19 @@ python (defcustom python-interpreter "python" "Python interpreter for noninteractive use. + +Some Python interpreters also require changes to +`python-interpreter-args'. + To customize the Python shell, modify `python-shell-interpreter' instead." :version "29.1" :type 'string) +(defcustom python-interpreter-args "" + "Default arguments for the Python interpreter." + :version "30.1" + :type 'string) ;;; Bindings @@ -2558,7 +2566,7 @@ python-shell-interpreter (cond ((executable-find "python3") "python3") ((executable-find "python") "python") (t "python3")) - "Default Python interpreter for shell. + "Default Python interpreter used for user interactions. Some Python interpreters also require changes to `python-shell-interpreter-args'. In particular, setting @@ -2573,7 +2581,7 @@ python-shell-internal-buffer-name :safe 'stringp) (defcustom python-shell-interpreter-args "-i" - "Default arguments for the Python interpreter." + "Default arguments for the Python interpreter for shell." :type 'string) (defcustom python-shell-interpreter-interactive-arg "-i" @@ -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