aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabián Ezequiel Gallina2015-07-06 20:08:01 -0300
committerFabián Ezequiel Gallina2015-07-06 20:08:01 -0300
commit287bce988895b104c33d53faacfffd91d8d8e0f1 (patch)
tree12f0c391ede2b76180ff9088f79c5229137a986e
parent60ea900848ee03e1ccdba565220f589e0d8e72e9 (diff)
downloademacs-287bce988895b104c33d53faacfffd91d8d8e0f1.tar.gz
emacs-287bce988895b104c33d53faacfffd91d8d8e0f1.zip
python.el: Fix local/remote shell environment setup
* lisp/progmodes/python.el (python-shell-with-environment): Fix remote/local environment setup. * test/automated/python-tests.el (python-shell-with-environment-1) (python-shell-with-environment-2): New tests.
-rw-r--r--lisp/progmodes/python.el35
-rw-r--r--test/automated/python-tests.el44
2 files changed, 54 insertions, 25 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 1c0f105ceaa..95814fabca3 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -2060,23 +2060,24 @@ execution of body. If `default-directory' points to a remote
2060machine then modifies `tramp-remote-process-environment' and 2060machine then modifies `tramp-remote-process-environment' and
2061`tramp-remote-path' instead." 2061`tramp-remote-path' instead."
2062 (declare (indent 0) (debug (body))) 2062 (declare (indent 0) (debug (body)))
2063 (let ((remote-p (file-remote-p default-directory))) 2063 (let ((remote-p (make-symbol "remote-p")))
2064 `(let ((process-environment 2064 `(let* ((,remote-p (file-remote-p default-directory))
2065 (if ,remote-p 2065 (process-environment
2066 process-environment 2066 (if ,remote-p
2067 (python-shell-calculate-process-environment))) 2067 process-environment
2068 (tramp-remote-process-environment 2068 (python-shell-calculate-process-environment)))
2069 (if ,remote-p 2069 (tramp-remote-process-environment
2070 (python-shell-calculate-process-environment) 2070 (if ,remote-p
2071 tramp-remote-process-environment)) 2071 (python-shell-calculate-process-environment)
2072 (exec-path 2072 tramp-remote-process-environment))
2073 (if ,remote-p 2073 (exec-path
2074 (python-shell-calculate-exec-path) 2074 (if ,remote-p
2075 exec-path)) 2075 exec-path
2076 (tramp-remote-path 2076 (python-shell-calculate-exec-path)))
2077 (if ,remote-p 2077 (tramp-remote-path
2078 (python-shell-calculate-exec-path) 2078 (if ,remote-p
2079 tramp-remote-path))) 2079 (python-shell-calculate-exec-path)
2080 tramp-remote-path)))
2080 ,(macroexp-progn body)))) 2081 ,(macroexp-progn body))))
2081 2082
2082(defvar python-shell--prompt-calculated-input-regexp nil 2083(defvar python-shell--prompt-calculated-input-regexp nil
diff --git a/test/automated/python-tests.el b/test/automated/python-tests.el
index 2ed07464df6..d490f7f9df5 100644
--- a/test/automated/python-tests.el
+++ b/test/automated/python-tests.el
@@ -27,6 +27,7 @@
27;; Dependencies for testing: 27;; Dependencies for testing:
28(require 'electric) 28(require 'electric)
29(require 'hideshow) 29(require 'hideshow)
30(require 'tramp-sh)
30 31
31 32
32(defmacro python-tests-with-temp-buffer (contents &rest body) 33(defmacro python-tests-with-temp-buffer (contents &rest body)
@@ -2463,17 +2464,12 @@ Using `python-shell-interpreter' and
2463 2464
2464(ert-deftest python-shell-calculate-process-environment-3 () 2465(ert-deftest python-shell-calculate-process-environment-3 ()
2465 "Test `python-shell-virtualenv-root' modification." 2466 "Test `python-shell-virtualenv-root' modification."
2466 (let* ((original-path (or (getenv "PATH") "")) 2467 (let* ((python-shell-virtualenv-root
2467 (python-shell-virtualenv-root
2468 (directory-file-name user-emacs-directory)) 2468 (directory-file-name user-emacs-directory))
2469 (process-environment 2469 (process-environment
2470 (python-shell-calculate-process-environment))) 2470 (python-shell-calculate-process-environment)))
2471 (should (not (getenv "PYTHONHOME"))) 2471 (should (not (getenv "PYTHONHOME")))
2472 (should (string= (getenv "VIRTUAL_ENV") python-shell-virtualenv-root)) 2472 (should (string= (getenv "VIRTUAL_ENV") python-shell-virtualenv-root))))
2473 (should (equal (getenv "PATH")
2474 (format "%s/bin%s%s"
2475 python-shell-virtualenv-root
2476 path-separator original-path)))))
2477 2473
2478(ert-deftest python-shell-calculate-process-environment-4 () 2474(ert-deftest python-shell-calculate-process-environment-4 ()
2479 "Test `python-shell-unbuffered' modification." 2475 "Test `python-shell-unbuffered' modification."
@@ -2503,7 +2499,7 @@ Using `python-shell-interpreter' and
2503 original-exec-path))))) 2499 original-exec-path)))))
2504 2500
2505(ert-deftest python-shell-calculate-exec-path-2 () 2501(ert-deftest python-shell-calculate-exec-path-2 ()
2506 "Test `python-shell-exec-path' modification." 2502 "Test `python-shell-virtualenv-root' modification."
2507 (let* ((original-exec-path exec-path) 2503 (let* ((original-exec-path exec-path)
2508 (python-shell-virtualenv-root 2504 (python-shell-virtualenv-root
2509 (directory-file-name (expand-file-name user-emacs-directory))) 2505 (directory-file-name (expand-file-name user-emacs-directory)))
@@ -2514,6 +2510,38 @@ Using `python-shell-interpreter' and
2514 (format "%s/bin" python-shell-virtualenv-root) 2510 (format "%s/bin" python-shell-virtualenv-root)
2515 original-exec-path)))))) 2511 original-exec-path))))))
2516 2512
2513(ert-deftest python-shell-with-environment-1 ()
2514 "Test with local `default-directory'."
2515 (let* ((original-exec-path exec-path)
2516 (python-shell-virtualenv-root
2517 (directory-file-name (expand-file-name user-emacs-directory))))
2518 (python-shell-with-environment
2519 (should (equal
2520 exec-path
2521 (append (cons
2522 (format "%s/bin" python-shell-virtualenv-root)
2523 original-exec-path))))
2524 (should (not (getenv "PYTHONHOME")))
2525 (should (string= (getenv "VIRTUAL_ENV") python-shell-virtualenv-root)))))
2526
2527(ert-deftest python-shell-with-environment-2 ()
2528 "Test with remote `default-directory'."
2529 (let* ((default-directory "/ssh::/example/dir/")
2530 (original-exec-path tramp-remote-path)
2531 (original-process-environment tramp-remote-process-environment)
2532 (python-shell-virtualenv-root
2533 (directory-file-name (expand-file-name user-emacs-directory))))
2534 (python-shell-with-environment
2535 (should (equal
2536 tramp-remote-path
2537 (append (cons
2538 (format "%s/bin" python-shell-virtualenv-root)
2539 original-exec-path))))
2540 (let ((process-environment tramp-remote-process-environment))
2541 (should (not (getenv "PYTHONHOME")))
2542 (should (string= (getenv "VIRTUAL_ENV")
2543 python-shell-virtualenv-root))))))
2544
2517(ert-deftest python-shell-make-comint-1 () 2545(ert-deftest python-shell-make-comint-1 ()
2518 "Check comint creation for global shell buffer." 2546 "Check comint creation for global shell buffer."
2519 (skip-unless (executable-find python-tests-shell-interpreter)) 2547 (skip-unless (executable-find python-tests-shell-interpreter))