Skip to content

Commit 6e61c08

Browse files
committed
Make VIRTUAL_ENV not end with "/" as same as normal virtualenv activation
If a virtualenv is normally activated, environment variable VIRTUAL_ENV does not end with "/", and its value is equal to sys.prefix in the python process. On the other hand, virtualenvwrapper.el before this commit makes VIRTUAL_ENV end with "/". Therefore, its value is different from sys.prefix in the python process spawned from Emacs. VIRTUAL_ENV ending with "/" might cause issues. For example, Jedi https://github.com/davidhalter/jedi stops working, in such case. Jedi creates PIPE-ed child process at each completion requests or so, and keeps them opened, if VIRTUAL_ENV is not equal to sys.prefix in child process. Finally, it stops working soon, because of EMFILE ("Too many open files"). Though child process management of Jedi may have to be more efficient, virtualenvwrapper.el also have to make VIRTUAL_ENV not end with "/", IMHO, because normal virtualenv activation does so, and the format of environment variable is a kind of API for inter process co-operation. According to commit f7c97e2 ("ensure venv-location has slash on end") for issue #51, there are some code paths, which expect venv-current-dir to end with "/". Therefore, this commit eliminates tail "/" of venv-current-dir at each assigning non-nil value to VIRTUAL_ENV, instead of making venv-current-dir not end with "/".
1 parent 107e7e0 commit 6e61c08

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

test/virtualenvwrapper-test.el

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
(should (s-contains? venv-tmp-env (getenv "PATH")))
5151
;; we set VIRTUAL_ENV for jedi and whoever else needs it
5252
(should (s-contains? venv-tmp-env (getenv "VIRTUAL_ENV")))
53+
;; VIRTUAL_ENV does not end with "/"
54+
(should (not (s-ends-with? "/" (getenv "VIRTUAL_ENV"))))
5355
;; we add our dir to exec-path
5456
(should (s-contains? venv-tmp-env (car exec-path))))
5557

virtualenvwrapper.el

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ prompting the user with the string PROMPT"
242242
(setenv "PATH" path)
243243
;; keep eshell path in sync
244244
(setq eshell-path-env path))
245-
(setenv "VIRTUAL_ENV" venv-current-dir)
245+
(setenv "VIRTUAL_ENV" (s-chop-suffix "/" venv-current-dir))
246246
(if venv-workon-cd
247247
(venv--switch-to-project-dir))
248248
(venv--set-venv-gud-pdb-command-name)
@@ -537,7 +537,7 @@ virtualenvwrapper.el."
537537
ad-do-it
538538
(venv-shell-init buffer-name)
539539
(setenv "PATH" (concat venv-current-dir venv-executables-dir path-separator (getenv "PATH")))
540-
(setenv "VIRTUAL_ENV" venv-current-dir)))))
540+
(setenv "VIRTUAL_ENV" (s-chop-suffix "/" venv-current-dir))))))
541541
(ad-activate 'shell))
542542

543543

0 commit comments

Comments
 (0)