diff options
| author | Fabián Ezequiel Gallina | 2014-11-22 20:09:30 -0300 |
|---|---|---|
| committer | Fabián Ezequiel Gallina | 2014-11-22 20:09:30 -0300 |
| commit | 238c052fdb9da3b1f96c09809461b70813c5bebc (patch) | |
| tree | 11fe1953832ceba6980ef0215383b36131d37ad9 | |
| parent | bd3625c432ee3d05ae4316d3b0ad2c0225e6d532 (diff) | |
| download | emacs-238c052fdb9da3b1f96c09809461b70813c5bebc.tar.gz emacs-238c052fdb9da3b1f96c09809461b70813c5bebc.zip | |
Set PYTHONUNBUFFERED on shell startup.
Fixes: debbugs:18595
* lisp/progmodes/python.el (python-shell-unbuffered): New var.
(python-shell-calculate-process-environment): Use it.
* test/automated/python-tests.el
(python-shell-calculate-process-environment-4)
(python-shell-calculate-process-environment-5): New tests.
(python-shell-make-comint-3): Use file-equal-p.
(python-shell-get-or-create-process-1)
(python-shell-get-or-create-process-2)
(python-shell-get-or-create-process-3): Fix interpreter for
Windows.
| -rw-r--r-- | lisp/ChangeLog | 7 | ||||
| -rw-r--r-- | lisp/progmodes/python.el | 22 | ||||
| -rw-r--r-- | test/ChangeLog | 11 | ||||
| -rw-r--r-- | test/automated/python-tests.el | 89 |
4 files changed, 86 insertions, 43 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 0f16eabdc03..e59c3910fd7 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,10 @@ | |||
| 1 | 2014-11-22 Fabián Ezequiel Gallina <fgallina@gnu.org> | ||
| 2 | |||
| 3 | Set PYTHONUNBUFFERED on shell startup. | ||
| 4 | |||
| 5 | * progmodes/python.el (python-shell-unbuffered): New var. | ||
| 6 | (python-shell-calculate-process-environment): Use it. | ||
| 7 | |||
| 1 | 2014-11-22 Michael Albinus <michael.albinus@gmx.de> | 8 | 2014-11-22 Michael Albinus <michael.albinus@gmx.de> |
| 2 | 9 | ||
| 3 | * net/tramp.el (tramp-action-password): Clean password on subsequent | 10 | * net/tramp.el (tramp-action-password): Clean password on subsequent |
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 5a5a039afc9..4c27136f3b5 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el | |||
| @@ -94,13 +94,13 @@ | |||
| 94 | ;; python-shell-interpreter-args | 94 | ;; python-shell-interpreter-args |
| 95 | ;; "-i C:\\Python27\\Scripts\\ipython-script.py") | 95 | ;; "-i C:\\Python27\\Scripts\\ipython-script.py") |
| 96 | 96 | ||
| 97 | ;; If you are experiencing missing or delayed output in your shells, | 97 | ;; Missing or delayed output used to happen due to differences between |
| 98 | ;; that's likely caused by your Operating System's pipe buffering | 98 | ;; Operating Systems' pipe buffering (e.g. CPython 3.3.4 in Windows 7. |
| 99 | ;; (e.g. this is known to happen running CPython 3.3.4 in Windows 7. | ||
| 100 | ;; See URL `http://debbugs.gnu.org/cgi/bugreport.cgi?bug=17304'). To | 99 | ;; See URL `http://debbugs.gnu.org/cgi/bugreport.cgi?bug=17304'). To |
| 101 | ;; fix this, using CPython's "-u" commandline argument or setting the | 100 | ;; avoid this, the `python-shell-unbuffered' defaults to non-nil and |
| 102 | ;; "PYTHONUNBUFFERED" environment variable should help: See URL | 101 | ;; controls whether `python-shell-calculate-process-environment' |
| 103 | ;; `https://docs.python.org/3/using/cmdline.html#cmdoption-u'. | 102 | ;; should set the "PYTHONUNBUFFERED" environment variable on startup: |
| 103 | ;; See URL `https://docs.python.org/3/using/cmdline.html#cmdoption-u'. | ||
| 104 | 104 | ||
| 105 | ;; The interaction relies upon having prompts for input (e.g. ">>> " | 105 | ;; The interaction relies upon having prompts for input (e.g. ">>> " |
| 106 | ;; and "... " in standard Python shell) and output (e.g. "Out[1]: " in | 106 | ;; and "... " in standard Python shell) and output (e.g. "Out[1]: " in |
| @@ -1813,6 +1813,14 @@ Restart the Python shell after changing this variable for it to take effect." | |||
| 1813 | :group 'python | 1813 | :group 'python |
| 1814 | :safe 'booleanp) | 1814 | :safe 'booleanp) |
| 1815 | 1815 | ||
| 1816 | (defcustom python-shell-unbuffered t | ||
| 1817 | "Should shell output be unbuffered?. | ||
| 1818 | When non-nil, this may prevent delayed and missing output in the | ||
| 1819 | Python shell. See commentary for details." | ||
| 1820 | :type 'boolean | ||
| 1821 | :group 'python | ||
| 1822 | :safe 'booleanp) | ||
| 1823 | |||
| 1816 | (defcustom python-shell-process-environment nil | 1824 | (defcustom python-shell-process-environment nil |
| 1817 | "List of environment variables for Python shell. | 1825 | "List of environment variables for Python shell. |
| 1818 | This variable follows the same rules as `process-environment' | 1826 | This variable follows the same rules as `process-environment' |
| @@ -2087,6 +2095,8 @@ uniqueness for different types of configurations." | |||
| 2087 | (virtualenv (if python-shell-virtualenv-path | 2095 | (virtualenv (if python-shell-virtualenv-path |
| 2088 | (directory-file-name python-shell-virtualenv-path) | 2096 | (directory-file-name python-shell-virtualenv-path) |
| 2089 | nil))) | 2097 | nil))) |
| 2098 | (when python-shell-unbuffered | ||
| 2099 | (setenv "PYTHONUNBUFFERED" "1")) | ||
| 2090 | (when python-shell-extra-pythonpaths | 2100 | (when python-shell-extra-pythonpaths |
| 2091 | (setenv "PYTHONPATH" | 2101 | (setenv "PYTHONPATH" |
| 2092 | (format "%s%s%s" | 2102 | (format "%s%s%s" |
diff --git a/test/ChangeLog b/test/ChangeLog index 4f7f068e796..0da5f99b226 100644 --- a/test/ChangeLog +++ b/test/ChangeLog | |||
| @@ -1,3 +1,14 @@ | |||
| 1 | 2014-11-22 Fabián Ezequiel Gallina <fgallina@gnu.org> | ||
| 2 | |||
| 3 | * automated/python-tests.el | ||
| 4 | (python-shell-calculate-process-environment-4) | ||
| 5 | (python-shell-calculate-process-environment-5): New tests. | ||
| 6 | (python-shell-make-comint-3): Use file-equal-p. | ||
| 7 | (python-shell-get-or-create-process-1) | ||
| 8 | (python-shell-get-or-create-process-2) | ||
| 9 | (python-shell-get-or-create-process-3): Fix interpreter for | ||
| 10 | Windows (Bug#18595). | ||
| 11 | |||
| 1 | 2014-11-15 Fabián Ezequiel Gallina <fgallina@gnu.org> | 12 | 2014-11-15 Fabián Ezequiel Gallina <fgallina@gnu.org> |
| 2 | 13 | ||
| 3 | * automated/python-tests.el (python-indent-dedenters-8): New test | 14 | * automated/python-tests.el (python-indent-dedenters-8): New test |
diff --git a/test/automated/python-tests.el b/test/automated/python-tests.el index f368f995cae..f84ded8cad2 100644 --- a/test/automated/python-tests.el +++ b/test/automated/python-tests.el | |||
| @@ -1872,6 +1872,23 @@ Using `python-shell-interpreter' and | |||
| 1872 | python-shell-virtualenv-path | 1872 | python-shell-virtualenv-path |
| 1873 | path-separator original-path))))) | 1873 | path-separator original-path))))) |
| 1874 | 1874 | ||
| 1875 | (ert-deftest python-shell-calculate-process-environment-4 () | ||
| 1876 | "Test `python-shell-unbuffered' modification." | ||
| 1877 | (setenv "PYTHONUNBUFFERED") | ||
| 1878 | (let* ((process-environment | ||
| 1879 | (python-shell-calculate-process-environment))) | ||
| 1880 | ;; Defaults to t | ||
| 1881 | (should python-shell-unbuffered) | ||
| 1882 | (should (string= (getenv "PYTHONUNBUFFERED") "1")))) | ||
| 1883 | |||
| 1884 | (ert-deftest python-shell-calculate-process-environment-5 () | ||
| 1885 | (setenv "PYTHONUNBUFFERED") | ||
| 1886 | "Test `python-shell-unbuffered' modification." | ||
| 1887 | (let* ((python-shell-unbuffered nil) | ||
| 1888 | (process-environment | ||
| 1889 | (python-shell-calculate-process-environment))) | ||
| 1890 | (should (not (getenv "PYTHONUNBUFFERED"))))) | ||
| 1891 | |||
| 1875 | (ert-deftest python-shell-calculate-exec-path-1 () | 1892 | (ert-deftest python-shell-calculate-exec-path-1 () |
| 1876 | "Test `python-shell-exec-path' modification." | 1893 | "Test `python-shell-exec-path' modification." |
| 1877 | (let* ((original-exec-path exec-path) | 1894 | (let* ((original-exec-path exec-path) |
| @@ -1961,8 +1978,9 @@ and `python-shell-interpreter-args' in the new shell buffer." | |||
| 1961 | (should (process-live-p process)) | 1978 | (should (process-live-p process)) |
| 1962 | (with-current-buffer shell-buffer | 1979 | (with-current-buffer shell-buffer |
| 1963 | (should (eq major-mode 'inferior-python-mode)) | 1980 | (should (eq major-mode 'inferior-python-mode)) |
| 1964 | (should (string= python-shell-interpreter | 1981 | (should (file-equal-p |
| 1965 | (executable-find python-tests-shell-interpreter))) | 1982 | python-shell-interpreter |
| 1983 | (executable-find python-tests-shell-interpreter))) | ||
| 1966 | (should (string= python-shell-interpreter-args "-i")))) | 1984 | (should (string= python-shell-interpreter-args "-i")))) |
| 1967 | (kill-buffer shell-buffer)))) | 1985 | (kill-buffer shell-buffer)))) |
| 1968 | 1986 | ||
| @@ -2050,12 +2068,11 @@ and `python-shell-interpreter-args' in the new shell buffer." | |||
| 2050 | (skip-unless (executable-find python-tests-shell-interpreter)) | 2068 | (skip-unless (executable-find python-tests-shell-interpreter)) |
| 2051 | (python-tests-with-temp-file | 2069 | (python-tests-with-temp-file |
| 2052 | "" | 2070 | "" |
| 2053 | (let* ((python-shell-interpreter | 2071 | (let* ((cmd |
| 2054 | (executable-find python-tests-shell-interpreter)) | 2072 | (concat (executable-find python-tests-shell-interpreter) " -i")) |
| 2055 | (use-dialog-box) | 2073 | (use-dialog-box) |
| 2056 | (dedicated-process-name (python-shell-get-process-name t)) | 2074 | (dedicated-process-name (python-shell-get-process-name t)) |
| 2057 | (dedicated-process | 2075 | (dedicated-process (python-shell-get-or-create-process cmd t)) |
| 2058 | (python-shell-get-or-create-process python-shell-interpreter t)) | ||
| 2059 | (dedicated-shell-buffer (process-buffer dedicated-process))) | 2076 | (dedicated-shell-buffer (process-buffer dedicated-process))) |
| 2060 | (unwind-protect | 2077 | (unwind-protect |
| 2061 | (progn | 2078 | (progn |
| @@ -2073,12 +2090,11 @@ and `python-shell-interpreter-args' in the new shell buffer." | |||
| 2073 | (skip-unless (executable-find python-tests-shell-interpreter)) | 2090 | (skip-unless (executable-find python-tests-shell-interpreter)) |
| 2074 | (python-tests-with-temp-file | 2091 | (python-tests-with-temp-file |
| 2075 | "" | 2092 | "" |
| 2076 | (let* ((python-shell-interpreter | 2093 | (let* ((cmd |
| 2077 | (executable-find python-tests-shell-interpreter)) | 2094 | (concat (executable-find python-tests-shell-interpreter) " -i")) |
| 2078 | (use-dialog-box) | 2095 | (use-dialog-box) |
| 2079 | (process-name (python-shell-get-process-name nil)) | 2096 | (process-name (python-shell-get-process-name nil)) |
| 2080 | (process | 2097 | (process (python-shell-get-or-create-process cmd)) |
| 2081 | (python-shell-get-or-create-process python-shell-interpreter)) | ||
| 2082 | (shell-buffer (process-buffer process))) | 2098 | (shell-buffer (process-buffer process))) |
| 2083 | (unwind-protect | 2099 | (unwind-protect |
| 2084 | (progn | 2100 | (progn |
| @@ -2088,43 +2104,42 @@ and `python-shell-interpreter-args' in the new shell buffer." | |||
| 2088 | (kill-buffer shell-buffer) | 2104 | (kill-buffer shell-buffer) |
| 2089 | ;; Check there are no processes for current buffer. | 2105 | ;; Check there are no processes for current buffer. |
| 2090 | (should (not (python-shell-get-process)))) | 2106 | (should (not (python-shell-get-process)))) |
| 2091 | (ignore-errors (kill-buffer dedicated-shell-buffer)))))) | 2107 | (ignore-errors (kill-buffer shell-buffer)))))) |
| 2092 | 2108 | ||
| 2093 | (ert-deftest python-shell-get-or-create-process-3 () | 2109 | (ert-deftest python-shell-get-or-create-process-3 () |
| 2094 | "Check shell dedicated/global process preference." | 2110 | "Check shell dedicated/global process preference." |
| 2095 | (skip-unless (executable-find python-tests-shell-interpreter)) | 2111 | (skip-unless (executable-find python-tests-shell-interpreter)) |
| 2096 | (python-tests-with-temp-file | 2112 | (python-tests-with-temp-file |
| 2097 | "" | 2113 | "" |
| 2098 | (let* ((python-shell-interpreter | 2114 | (let* ((cmd |
| 2099 | (executable-find python-tests-shell-interpreter)) | 2115 | (concat (executable-find python-tests-shell-interpreter) " -i")) |
| 2116 | (python-shell-interpreter python-tests-shell-interpreter) | ||
| 2100 | (use-dialog-box) | 2117 | (use-dialog-box) |
| 2101 | (dedicated-process-name (python-shell-get-process-name t)) | 2118 | (dedicated-process-name (python-shell-get-process-name t)) |
| 2102 | (global-process) | 2119 | (global-process) |
| 2103 | (dedicated-process)) | 2120 | (dedicated-process)) |
| 2104 | (unwind-protect | 2121 | (progn |
| 2105 | (progn | 2122 | ;; Create global process |
| 2106 | ;; Create global process | 2123 | (run-python cmd nil) |
| 2107 | (run-python python-shell-interpreter nil) | 2124 | (setq global-process (get-buffer-process "*Python*")) |
| 2108 | (setq global-process (get-buffer-process "*Python*")) | 2125 | (should global-process) |
| 2109 | (should global-process) | 2126 | (set-process-query-on-exit-flag global-process nil) |
| 2110 | (set-process-query-on-exit-flag global-process nil) | 2127 | ;; Create dedicated process |
| 2111 | ;; Create dedicated process | 2128 | (run-python cmd t) |
| 2112 | (run-python python-shell-interpreter t) | 2129 | (setq dedicated-process (get-process dedicated-process-name)) |
| 2113 | (setq dedicated-process (get-process dedicated-process-name)) | 2130 | (should dedicated-process) |
| 2114 | (should dedicated-process) | 2131 | (set-process-query-on-exit-flag dedicated-process nil) |
| 2115 | (set-process-query-on-exit-flag dedicated-process nil) | 2132 | ;; Prefer dedicated. |
| 2116 | ;; Prefer dedicated. | 2133 | (should (equal (python-shell-get-or-create-process) |
| 2117 | (should (equal (python-shell-get-or-create-process) | 2134 | dedicated-process)) |
| 2118 | dedicated-process)) | 2135 | ;; Kill the dedicated so the global takes over. |
| 2119 | ;; Kill the dedicated so the global takes over. | 2136 | (kill-buffer (process-buffer dedicated-process)) |
| 2120 | (kill-buffer (process-buffer dedicated-process)) | 2137 | ;; Detect global. |
| 2121 | ;; Detect global. | 2138 | (should (equal (python-shell-get-or-create-process) global-process)) |
| 2122 | (should (equal (python-shell-get-or-create-process) global-process)) | 2139 | ;; Kill the global. |
| 2123 | ;; Kill the global. | 2140 | (kill-buffer (process-buffer global-process)) |
| 2124 | (kill-buffer (process-buffer global-process)) | 2141 | ;; Check there are no processes for current buffer. |
| 2125 | ;; Check there are no processes for current buffer. | 2142 | (should (not (python-shell-get-process))))))) |
| 2126 | (should (not (python-shell-get-process)))) | ||
| 2127 | (ignore-errors (kill-buffer dedicated-shell-buffer)))))) | ||
| 2128 | 2143 | ||
| 2129 | (ert-deftest python-shell-internal-get-or-create-process-1 () | 2144 | (ert-deftest python-shell-internal-get-or-create-process-1 () |
| 2130 | "Check internal shell process creation fallback." | 2145 | "Check internal shell process creation fallback." |