Skip to content

Commit

Permalink
virtualenv-workon now sets exec-path and the PATH environment variable
Browse files Browse the repository at this point in the history
  • Loading branch information
aculich committed Jan 9, 2012
1 parent ac8f2c4 commit 268466e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
10 changes: 7 additions & 3 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ launch a python shell. This method is recommended because it is
more flexible and will allow multiple virtualenvs running at once
in future versions.

Notes:

virtualenv-workon will now modify Emacs' exec-path as well as the
shell environment's PATH so that if you run shell-command or launch a
command in an emacs subprocess it will use any commands it finds in
your ~/.virtualenvs/<env>/bin directory.

Bugs:

All bug reports can be filed by opening a new issue on github at:
Expand All @@ -83,6 +90,3 @@ in future versions.
* support for multiple python processes in different virtualenvs

* add "paster shell" features

* add support for shell-command

18 changes: 16 additions & 2 deletions virtualenv.el
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ top-level .dir-locals.el file, e.g.: \
(defvar virtualenv-workon-history nil
"History list of virtual environments used.")

(defvar virtualenv-saved-path nil
"Saves `exec-path' and the `PATH' environment variable when
invoking `virtualenv-workon'.")

(defun virtualenv-formatted-mode-string (&optional name)
"Format the `virtualenv-mode-name' string.
Optional argument NAME is a string that will appear as [NAME] in
Expand Down Expand Up @@ -190,8 +194,8 @@ the virtual environment or if not a string then query the user."
(lambda (d)
(when (file-exists-p
(expand-file-name
(concat
virtualenv-root "/" d "/bin")))
(concat d "/bin")
virtualenv-root))
d))
(directory-files virtualenv-root nil "^[^.]"))))
(result (completing-read prompt dirs nil t nil
Expand All @@ -212,6 +216,16 @@ the virtual environment or if not a string then query the user."
(when buffer
(kill-buffer buffer))
(setq virtualenv-workon-session env)
(let* ((bin (expand-file-name
(concat env "/bin")
virtualenv-root))
(oldpath (or (car virtualenv-saved-path)
(getenv "PATH")))
(oldexec (or (cdr virtualenv-saved-path)
exec-path)))
(setq virtualenv-saved-path (cons oldpath oldexec))
(add-to-list 'exec-path bin)
(setenv "PATH" (concat bin ":" oldpath)))
(when virtualenv-workon-starts-python
(cond ((fboundp 'python-shell-switch-to-shell)
(python-shell-switch-to-shell))
Expand Down

0 comments on commit 268466e

Please sign in to comment.