]> code.delx.au - gnu-emacs/commitdiff
python.el: Fix local/remote shell environment setup
authorFabián Ezequiel Gallina <fgallina@gnu.org>
Mon, 6 Jul 2015 23:08:01 +0000 (20:08 -0300)
committerFabián Ezequiel Gallina <fgallina@gnu.org>
Mon, 6 Jul 2015 23:08:01 +0000 (20:08 -0300)
* 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.

lisp/progmodes/python.el
test/automated/python-tests.el

index 1c0f105ceaa8c909bc6538cf889509fea82d6460..95814fabca3b9e178c0f3a8294fe73cc3fc32710 100644 (file)
@@ -2060,23 +2060,24 @@ execution of body.  If `default-directory' points to a remote
 machine then modifies `tramp-remote-process-environment' and
 `tramp-remote-path' instead."
   (declare (indent 0) (debug (body)))
-  (let ((remote-p (file-remote-p default-directory)))
-    `(let ((process-environment
-            (if ,remote-p
-                process-environment
-              (python-shell-calculate-process-environment)))
-           (tramp-remote-process-environment
-            (if ,remote-p
-                (python-shell-calculate-process-environment)
-              tramp-remote-process-environment))
-           (exec-path
-            (if ,remote-p
-                (python-shell-calculate-exec-path)
-              exec-path))
-           (tramp-remote-path
-            (if ,remote-p
-                (python-shell-calculate-exec-path)
-              tramp-remote-path)))
+  (let ((remote-p (make-symbol "remote-p")))
+    `(let* ((,remote-p (file-remote-p default-directory))
+            (process-environment
+             (if ,remote-p
+                 process-environment
+               (python-shell-calculate-process-environment)))
+            (tramp-remote-process-environment
+             (if ,remote-p
+                 (python-shell-calculate-process-environment)
+               tramp-remote-process-environment))
+            (exec-path
+             (if ,remote-p
+                 exec-path
+               (python-shell-calculate-exec-path)))
+            (tramp-remote-path
+             (if ,remote-p
+                 (python-shell-calculate-exec-path)
+               tramp-remote-path)))
        ,(macroexp-progn body))))
 
 (defvar python-shell--prompt-calculated-input-regexp nil
index 2ed07464df66a3220e0e41d3df904f9e592af857..d490f7f9df5eaa4ab86f8b09f1187bbbcab57496 100644 (file)
@@ -27,6 +27,7 @@
 ;; Dependencies for testing:
 (require 'electric)
 (require 'hideshow)
+(require 'tramp-sh)
 
 
 (defmacro python-tests-with-temp-buffer (contents &rest body)
@@ -2463,17 +2464,12 @@ Using `python-shell-interpreter' and
 
 (ert-deftest python-shell-calculate-process-environment-3 ()
   "Test `python-shell-virtualenv-root' modification."
-  (let* ((original-path (or (getenv "PATH") ""))
-         (python-shell-virtualenv-root
+  (let* ((python-shell-virtualenv-root
           (directory-file-name user-emacs-directory))
          (process-environment
           (python-shell-calculate-process-environment)))
     (should (not (getenv "PYTHONHOME")))
-    (should (string= (getenv "VIRTUAL_ENV") python-shell-virtualenv-root))
-    (should (equal (getenv "PATH")
-                   (format "%s/bin%s%s"
-                           python-shell-virtualenv-root
-                           path-separator original-path)))))
+    (should (string= (getenv "VIRTUAL_ENV") python-shell-virtualenv-root))))
 
 (ert-deftest python-shell-calculate-process-environment-4 ()
   "Test `python-shell-unbuffered' modification."
@@ -2503,7 +2499,7 @@ Using `python-shell-interpreter' and
                      original-exec-path)))))
 
 (ert-deftest python-shell-calculate-exec-path-2 ()
-  "Test `python-shell-exec-path' modification."
+  "Test `python-shell-virtualenv-root' modification."
   (let* ((original-exec-path exec-path)
          (python-shell-virtualenv-root
           (directory-file-name (expand-file-name user-emacs-directory)))
@@ -2514,6 +2510,38 @@ Using `python-shell-interpreter' and
                       (format "%s/bin" python-shell-virtualenv-root)
                       original-exec-path))))))
 
+(ert-deftest python-shell-with-environment-1 ()
+  "Test with local `default-directory'."
+  (let* ((original-exec-path exec-path)
+         (python-shell-virtualenv-root
+          (directory-file-name (expand-file-name user-emacs-directory))))
+    (python-shell-with-environment
+      (should (equal
+               exec-path
+               (append (cons
+                        (format "%s/bin" python-shell-virtualenv-root)
+                        original-exec-path))))
+      (should (not (getenv "PYTHONHOME")))
+      (should (string= (getenv "VIRTUAL_ENV") python-shell-virtualenv-root)))))
+
+(ert-deftest python-shell-with-environment-2 ()
+  "Test with remote `default-directory'."
+  (let* ((default-directory "/ssh::/example/dir/")
+         (original-exec-path tramp-remote-path)
+         (original-process-environment tramp-remote-process-environment)
+         (python-shell-virtualenv-root
+          (directory-file-name (expand-file-name user-emacs-directory))))
+    (python-shell-with-environment
+      (should (equal
+               tramp-remote-path
+               (append (cons
+                        (format "%s/bin" python-shell-virtualenv-root)
+                        original-exec-path))))
+      (let ((process-environment tramp-remote-process-environment))
+        (should (not (getenv "PYTHONHOME")))
+        (should (string= (getenv "VIRTUAL_ENV")
+                         python-shell-virtualenv-root))))))
+
 (ert-deftest python-shell-make-comint-1 ()
   "Check comint creation for global shell buffer."
   (skip-unless (executable-find python-tests-shell-interpreter))