Skip to content

Commit

Permalink
Merge pull request aculich#17 from orontee/master
Browse files Browse the repository at this point in the history
Bug fix and Windows port
  • Loading branch information
aculich committed Sep 30, 2012
2 parents 8ffba73 + 6e56be5 commit 9efee44
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions virtualenv.el
Expand Up @@ -113,6 +113,11 @@ better to use this than for it to appear blank.")

(defvar virtualenv-mode-name virtualenv-mode-name-default)

(defvar virtualenv-executables-dir
(if (eq system-type 'windows-nt) "/Scripts" "/bin")
"The name of the directory containing executables. It is system
dependent.")

(defvar virtualenv-default-directory nil
"Buffer-local variable that should be set in your project's
top-level .dir-locals.el file as the place you want to start the python shell.
Expand Down Expand Up @@ -161,7 +166,7 @@ not set, then use `virtualenv-mode-name-default'."
(make-local-variable 'virtualenv-mode-name)
(setq virtualenv-mode-name string)))

(defalias 'virutalenv-old-hack-dir-local-variables (symbol-function 'hack-dir-local-variables))
(defalias 'virtualenv-old-hack-dir-local-variables (symbol-function 'hack-dir-local-variables))

;;;###autoload
(defun virtualenv-workon (&optional env)
Expand Down Expand Up @@ -214,7 +219,7 @@ the virtual environment or if not a string then query the user."
(lambda (d)
(when (file-exists-p
(expand-file-name
(concat d "/bin")
(concat d virtualenv-executables-dir)
root))
d))
(directory-files root nil "^[^.]"))))
Expand All @@ -239,15 +244,20 @@ the virtual environment or if not a string then query the user."
(kill-buffer buffer))
(setq virtualenv-workon-session env)
(let* ((bin (expand-file-name
(concat env "/bin")
(concat env virtualenv-executables-dir)
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)))
(setenv "PATH"
(if (eq system-type 'windows-nt)
(concat bin path-separator
(replace-regexp-in-string
(regexp-quote "/") "\\" oldpath))
(concat bin path-separator oldpath))))
(when virtualenv-workon-starts-python
(cond ((fboundp 'python-shell-switch-to-shell)
(python-shell-switch-to-shell))
Expand Down Expand Up @@ -316,14 +326,17 @@ the virtual environment or if not a string then query the user."
(let* ((activate (expand-file-name
"activate"
(expand-file-name
(concat workon "/bin")
(concat workon virtualenv-executables-dir)
virtualenv-root)))
(process-environment
(when (file-exists-p activate)
(split-string
(shell-command-to-string
(if (eq system-type 'windows-nt)
(format "call %s & cd %s && set"
activate default-directory)
(format "source %s; (cd %s && env)"
activate default-directory))
activate default-directory)))
"\n")))
(exec-path (split-string (getenv "PATH") path-separator)))
ad-do-it
Expand Down

0 comments on commit 9efee44

Please sign in to comment.