From: Fabián Ezequiel Gallina Date: Mon, 6 Jul 2015 23:08:01 +0000 (-0300) Subject: python.el: Fix local/remote shell environment setup X-Git-Tag: emacs-25.0.90~1536 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=287bce988895b104c33d53faacfffd91d8d8e0f1;p=emacs.git 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. --- 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 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 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 @@ ;; 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))