aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes/python.el
diff options
context:
space:
mode:
authorFabián Ezequiel Gallina2015-08-21 22:34:39 -0300
committerFabián Ezequiel Gallina2015-08-21 22:34:39 -0300
commite2a5e3f87aba493623734dcf9b872e10c6077496 (patch)
tree05b2fe7b86cf9426711350116cdef3451d5687ab /lisp/progmodes/python.el
parent49071a4afcc4e8b12a407d977cfad1db4d49f629 (diff)
downloademacs-e2a5e3f87aba493623734dcf9b872e10c6077496.tar.gz
emacs-e2a5e3f87aba493623734dcf9b872e10c6077496.zip
python.el: Ensure remote process-environment on non-interactive processes
* lisp/progmodes/python.el (python-shell-tramp-refresh-process-environment): New function. (python-shell-with-environment): Use it. * test/automated/python-tests.el (python-shell-with-environment-2): Update.
Diffstat (limited to 'lisp/progmodes/python.el')
-rw-r--r--lisp/progmodes/python.el86
1 files changed, 57 insertions, 29 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index b5bfe6741b5..9c4a0f1bbfb 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -2098,7 +2098,30 @@ appends `python-shell-remote-exec-path' instead of `exec-path'."
2098 (tramp-set-connection-property vec "remote-path" remote-path) 2098 (tramp-set-connection-property vec "remote-path" remote-path)
2099 (tramp-set-remote-path vec)))) 2099 (tramp-set-remote-path vec))))
2100 2100
2101(defvar python-shell--with-environment-wrapped nil) 2101(defun python-shell-tramp-refresh-process-environment (vec env)
2102 "Update VEC's process environment with ENV."
2103 ;; Stolen from `tramp-open-connection-setup-interactive-shell'.
2104 (let ((env (append `(,(tramp-get-remote-locale vec))
2105 (copy-sequence env)))
2106 unset vars item)
2107 (while env
2108 (setq item (tramp-compat-split-string (car env) "="))
2109 (setcdr item (mapconcat 'identity (cdr item) "="))
2110 (if (and (stringp (cdr item)) (not (string-equal (cdr item) "")))
2111 (push (format "%s %s" (car item) (cdr item)) vars)
2112 (push (car item) unset))
2113 (setq env (cdr env)))
2114 (when vars
2115 (tramp-send-command
2116 vec
2117 (format "while read var val; do export $var=$val; done <<'%s'\n%s\n%s"
2118 tramp-end-of-heredoc
2119 (mapconcat 'identity vars "\n")
2120 tramp-end-of-heredoc)
2121 t))
2122 (when unset
2123 (tramp-send-command
2124 vec (format "unset %s" (mapconcat 'identity unset " ")) t))))
2102 2125
2103(defmacro python-shell-with-environment (&rest body) 2126(defmacro python-shell-with-environment (&rest body)
2104 "Modify shell environment during execution of BODY. 2127 "Modify shell environment during execution of BODY.
@@ -2109,34 +2132,39 @@ machine then modifies `tramp-remote-process-environment' and
2109 (declare (indent 0) (debug (body))) 2132 (declare (indent 0) (debug (body)))
2110 (let ((vec (make-symbol "vec"))) 2133 (let ((vec (make-symbol "vec")))
2111 `(progn 2134 `(progn
2112 (if python-shell--with-environment-wrapped 2135 (let* ((,vec
2113 ,(macroexp-progn body) 2136 (when (file-remote-p default-directory)
2114 (let* ((,vec 2137 (ignore-errors
2115 (when (file-remote-p default-directory) 2138 (tramp-dissect-file-name default-directory 'noexpand))))
2116 (ignore-errors 2139 (process-environment
2117 (tramp-dissect-file-name default-directory 'noexpand)))) 2140 (if ,vec
2118 (process-environment 2141 process-environment
2119 (if ,vec 2142 (python-shell-calculate-process-environment)))
2120 process-environment 2143 (exec-path
2121 (python-shell-calculate-process-environment))) 2144 (if ,vec
2122 (exec-path 2145 exec-path
2123 (if ,vec 2146 (python-shell-calculate-exec-path)))
2124 exec-path 2147 (tramp-remote-process-environment
2125 (python-shell-calculate-exec-path))) 2148 (if ,vec
2126 (tramp-remote-process-environment 2149 (python-shell-calculate-process-environment)
2127 (if ,vec 2150 tramp-remote-process-environment)))
2128 (python-shell-calculate-process-environment) 2151 (when (tramp-get-connection-process ,vec)
2129 tramp-remote-process-environment)) 2152 ;; For already existing connections, the new exec path must
2130 (python-shell--with-environment-wrapped t)) 2153 ;; be re-set, otherwise it won't take effect. One example
2131 (when (tramp-get-connection-process ,vec) 2154 ;; of such case is when remote dir-locals are read and
2132 ;; For already existing connections, modified env vars must 2155 ;; *then* subprocesses are triggered within the same
2133 ;; be re-set again. This is a normal thing to happen when 2156 ;; connection.
2134 ;; remote dir-locals are read from remote and *then* 2157 (python-shell-tramp-refresh-remote-path
2135 ;; processes should be started within the same connection 2158 ,vec (python-shell-calculate-exec-path))
2136 ;; with env vars calculated from them. 2159 ;; The `tramp-remote-process-environment' variable is only
2137 (python-shell-tramp-refresh-remote-path 2160 ;; effective when the started process is an interactive
2138 ,vec (python-shell-calculate-exec-path))) 2161 ;; shell, otherwise (like in the case of processes started
2139 ,(macroexp-progn body)))))) 2162 ;; with `process-file') the environment is not changed.
2163 ;; This makes environment modifications effective
2164 ;; inconditionally.
2165 (python-shell-tramp-refresh-process-environment
2166 ,vec tramp-remote-process-environment))
2167 ,(macroexp-progn body)))))
2140 2168
2141(defvar python-shell--prompt-calculated-input-regexp nil 2169(defvar python-shell--prompt-calculated-input-regexp nil
2142 "Calculated input prompt regexp for inferior python shell. 2170 "Calculated input prompt regexp for inferior python shell.