(defun python-shell-get-process-name (dedicated)
"Calculate the appropriate process name for inferior Python process.
-If DEDICATED is t and the variable `buffer-file-name' is non-nil
-returns a string with the form
-`python-shell-buffer-name'[variable `buffer-file-name'] else
-returns the value of `python-shell-buffer-name'."
- (let ((process-name
- (if (and dedicated
- buffer-file-name)
- (format "%s[%s]" python-shell-buffer-name buffer-file-name)
- (format "%s" python-shell-buffer-name))))
- process-name))
+If DEDICATED is t returns a string with the form
+`python-shell-buffer-name'[`buffer-name'] else returns the value
+of `python-shell-buffer-name'."
+ (if dedicated
+ (format "%s[%s]" python-shell-buffer-name (buffer-name))
+ python-shell-buffer-name))
(defun python-shell-internal-get-process-name ()
"Calculate the appropriate process name for Internal Python process.
The name is calculated from `python-shell-global-buffer-name' and
-a hash of all relevant global shell settings in order to ensure
-uniqueness for different types of configurations."
- (format "%s [%s]"
- python-shell-internal-buffer-name
- (md5
- (concat
- python-shell-interpreter
- python-shell-interpreter-args
- python-shell--prompt-calculated-input-regexp
- python-shell--prompt-calculated-output-regexp
- (mapconcat #'symbol-value python-shell-setup-codes "")
- (mapconcat #'identity python-shell-process-environment "")
- (mapconcat #'identity python-shell-extra-pythonpaths "")
- (mapconcat #'identity python-shell-exec-path "")
- (or python-shell-virtualenv-root "")
- (mapconcat #'identity python-shell-exec-path "")))))
+the `buffer-name'."
+ (format "%s[%s]" python-shell-internal-buffer-name (buffer-name)))
(defun python-shell-calculate-command ()
"Calculate the string used to execute the inferior Python process."
(defun python-shell-internal-get-or-create-process ()
"Get or create an inferior Internal Python process."
- (let* ((proc-name (python-shell-internal-get-process-name))
- (proc-buffer-name (format " *%s*" proc-name)))
- (when (not (process-live-p proc-name))
- (run-python-internal)
- (setq python-shell-internal-buffer proc-buffer-name))
- (get-buffer-process proc-buffer-name)))
+ (let ((proc-name (python-shell-internal-get-process-name)))
+ (if (process-live-p proc-name)
+ (get-process proc-name)
+ (run-python-internal))))
(define-obsolete-function-alias
'python-proc 'python-shell-internal-get-or-create-process "24.3")
(defvar python-tests-shell-interpreter "python")
(ert-deftest python-shell-get-process-name-1 ()
- "Check process name calculation on different scenarios."
+ "Check process name calculation sans `buffer-file-name'."
(python-tests-with-temp-buffer
- ""
- (should (string= (python-shell-get-process-name nil)
- python-shell-buffer-name))
- ;; When the `current-buffer' doesn't have `buffer-file-name', even
- ;; if dedicated flag is non-nil should not include its name.
- (should (string= (python-shell-get-process-name t)
- python-shell-buffer-name)))
+ ""
+ (should (string= (python-shell-get-process-name nil)
+ python-shell-buffer-name))
+ (should (string= (python-shell-get-process-name t)
+ (format "%s[%s]" python-shell-buffer-name (buffer-name))))))
+
+(ert-deftest python-shell-get-process-name-2 ()
+ "Check process name calculation with `buffer-file-name'."
(python-tests-with-temp-file
- ""
- ;; `buffer-file-name' is non-nil but the dedicated flag is nil and
- ;; should be respected.
- (should (string= (python-shell-get-process-name nil)
- python-shell-buffer-name))
- (should (string=
- (python-shell-get-process-name t)
- (format "%s[%s]" python-shell-buffer-name buffer-file-name)))))
+ ""
+ ;; `buffer-file-name' is non-nil but the dedicated flag is nil and
+ ;; should be respected.
+ (should (string= (python-shell-get-process-name nil)
+ python-shell-buffer-name))
+ (should (string=
+ (python-shell-get-process-name t)
+ (format "%s[%s]" python-shell-buffer-name (buffer-name))))))
(ert-deftest python-shell-internal-get-process-name-1 ()
- "Check the internal process name is config-unique."
- (let* ((python-shell-interpreter python-tests-shell-interpreter)
- (python-shell-interpreter-args "")
- (python-shell-prompt-regexp ">>> ")
- (python-shell-prompt-block-regexp "[.][.][.] ")
- (python-shell-setup-codes "")
- (python-shell-process-environment "")
- (python-shell-extra-pythonpaths "")
- (python-shell-exec-path "")
- (python-shell-virtualenv-path "")
- (expected (python-tests-with-temp-buffer
- "" (python-shell-internal-get-process-name))))
- ;; Same configurations should match.
- (should
- (string= expected
- (python-tests-with-temp-buffer
- "" (python-shell-internal-get-process-name))))
- (let ((python-shell-interpreter-args "-B"))
- ;; A minimal change should generate different names.
- (should
- (not (string=
- expected
- (python-tests-with-temp-buffer
- "" (python-shell-internal-get-process-name))))))))
-
-(ert-deftest python-shell-parse-command-1 ()
+ "Check the internal process name is buffer-unique sans `buffer-file-name'."
+ (python-tests-with-temp-buffer
+ ""
+ (should (string= (python-shell-internal-get-process-name)
+ (format "%s[%s]" python-shell-internal-buffer-name (buffer-name))))))
+
+(ert-deftest python-shell-internal-get-process-name-2 ()
+ "Check the internal process name is buffer-unique with `buffer-file-name'."
+ (python-tests-with-temp-file
+ ""
+ (should (string= (python-shell-internal-get-process-name)
+ (format "%s[%s]" python-shell-internal-buffer-name (buffer-name))))))
+
+(ert-deftest python-shell-calculate-command-1 ()
"Check the command to execute is calculated correctly.
Using `python-shell-interpreter' and
`python-shell-interpreter-args'."
(format "%s %s"
python-shell-interpreter
python-shell-interpreter-args)
- (python-shell-parse-command)))))
+ (python-shell-calculate-command)))))
(ert-deftest python-shell-calculate-process-environment-1 ()
"Test `python-shell-process-environment' modification."
path-separator original-pythonpath)))))
(ert-deftest python-shell-calculate-process-environment-3 ()
- "Test `python-shell-virtualenv-path' modification."
+ "Test `python-shell-virtualenv-root' modification."
(let* ((original-path (or (getenv "PATH") ""))
- (python-shell-virtualenv-path
+ (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-path))
+ (should (string= (getenv "VIRTUAL_ENV") python-shell-virtualenv-root))
(should (equal (getenv "PATH")
(format "%s/bin%s%s"
- python-shell-virtualenv-path
+ python-shell-virtualenv-root
path-separator original-path)))))
(ert-deftest python-shell-calculate-process-environment-4 ()
(ert-deftest python-shell-calculate-exec-path-2 ()
"Test `python-shell-exec-path' modification."
(let* ((original-exec-path exec-path)
- (python-shell-virtualenv-path
+ (python-shell-virtualenv-root
(directory-file-name (expand-file-name user-emacs-directory)))
(exec-path (python-shell-calculate-exec-path)))
(should (equal
exec-path
(append (cons
- (format "%s/bin" python-shell-virtualenv-path)
+ (format "%s/bin" python-shell-virtualenv-root)
original-exec-path))))))
(ert-deftest python-shell-make-comint-1 ()
(shell-buffer
(python-tests-with-temp-buffer
"" (python-shell-make-comint
- (python-shell-parse-command) proc-name)))
+ (python-shell-calculate-command) proc-name)))
(process (get-buffer-process shell-buffer)))
(unwind-protect
(progn
(shell-buffer
(python-tests-with-temp-buffer
"" (python-shell-make-comint
- (python-shell-parse-command) proc-name nil t)))
+ (python-shell-calculate-command) proc-name nil t)))
(process (get-buffer-process shell-buffer)))
(unwind-protect
(progn
(setenv "PYTHONSTARTUP" startup-file)
(python-tests-with-temp-buffer
"" (python-shell-make-comint
- (python-shell-parse-command) proc-name nil))))
+ (python-shell-calculate-command) proc-name nil))))
(process (get-buffer-process shell-buffer)))
(unwind-protect
(progn
(dedicated-proc-name (python-shell-get-process-name t))
(global-shell-buffer
(python-shell-make-comint
- (python-shell-parse-command) global-proc-name))
+ (python-shell-calculate-command) global-proc-name))
(dedicated-shell-buffer
(python-shell-make-comint
- (python-shell-parse-command) dedicated-proc-name))
+ (python-shell-calculate-command) dedicated-proc-name))
(global-process (get-buffer-process global-shell-buffer))
(dedicated-process (get-buffer-process dedicated-shell-buffer)))
(unwind-protect
. "from IPython.core.completerlib import module_completion")
(python-shell-completion-string-code
. "';'.join(get_ipython().Completer.all_completions('''%s'''))\n")
- (python-shell-virtualenv-path
+ (python-shell-virtualenv-root
. "/home/user/.virtualenvs/project"))))
(with-current-buffer buffer
(kill-all-local-variables)