Skip to content

Commit

Permalink
Merge pull request #49 from sambrightman/venv-mkvirtualenv-using
Browse files Browse the repository at this point in the history
Allow interpreter to be set non-interactively
  • Loading branch information
porterjamesj authored Nov 19, 2017
2 parents b4fd61a + f2f5792 commit fa49954
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 24 deletions.
31 changes: 18 additions & 13 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
language: emacs-lisp
language: generic
sudo: false
dist: trusty
before_install:
- git clone https://github.com/rejeep/evm.git ~/.evm
- evm config path /tmp
- evm install $EVM_EMACS
- evm use $EVM_EMACS
- sudo apt-get install -y python-pip
- sudo pip install virtualenv
- curl -fsSkL https://raw.github.com/cask/cask/master/go | python
- cask
addons:
apt:
packages:
- python-pip
env:
global:
- PATH="~/.evm/bin:~/.cask/bin:$PATH"
- PATH=~/.evm/bin:~/.cask/bin:$PATH
matrix:
- EVM_EMACS=emacs-24.5-travis
- EVM_EMACS=emacs-25.1-travis
- EVM_EMACS=emacs-25.2-travis
- EVM_EMACS=emacs-25.3-travis
- EVM_EMACS=emacs-git-snapshot-travis
# - EVM_EMACS=emacs-git-snapshot-travis
before_install:
- pip install -U --user virtualenv
- curl -fsSkL https://raw.github.com/rejeep/evm/master/go | bash
- evm config path /tmp
- evm install $EVM_EMACS
- evm use $EVM_EMACS
- hash -r
- curl -fsSkL https://raw.github.com/cask/cask/master/go | python
- cask exec emacs --version
- cask install
script:
cask exec ert-runner
- cask exec ert-runner
4 changes: 3 additions & 1 deletion Cask
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
(source gnu)
(source melpa)

(package "virtualenvwrapper" "20140315" "a featureful virtualenv tool for Emacs")
Expand All @@ -7,4 +8,5 @@

(development
(depends-on "ert-runner")
(depends-on "noflet"))
(depends-on "noflet")
(depends-on "with-simulated-input"))
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,12 @@ list), then the new virtualenv will be created in the current default
directory. Also callable noninteractively as `(venv-mkvirtualenv
"name")`.

#### `venv-mkvirtualenv-using`

Supplying a prefix command (`C-u`) to `venv-mkvirtualenv` will prompt
for a Python interpreter to use. You can use this function to specify
the interpreter noninteractively.

#### `venv-rmvirtualenv`

Prompt for the name of a virutalenv and delete it. Also callable
Expand Down
57 changes: 56 additions & 1 deletion test/virtualenvwrapper-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
(load (expand-file-name "virtualenvwrapper.el" default-directory))
(require 's)
(require 'noflet)
(require 'with-simulated-input)

(setq venv-tmp-env "emacs-venvwrapper-test")

Expand Down Expand Up @@ -58,6 +59,60 @@
(venv-rmvirtualenv venv-tmp-env)
(should-error (venv-workon venv-tmp-env))))

(ert-deftest venv-mkvirtualenv-select-default-interpreter ()
(with-temp-location
(let ((current-prefix-arg '(4)))
(with-simulated-input
"RET"
(venv-mkvirtualenv venv-tmp-env))
(should (equal venv-current-name venv-tmp-env))
(venv-deactivate)
(venv-rmvirtualenv venv-tmp-env))))

(ert-deftest venv-mkvirtualenv-select-different-interpreter ()
(with-temp-location
(let ((current-prefix-arg '(4)))
(with-simulated-input
(concat (executable-find "python") " RET")
(venv-mkvirtualenv venv-tmp-env))
(should (equal venv-current-name venv-tmp-env))
(venv-deactivate)
(venv-rmvirtualenv venv-tmp-env))))

(ert-deftest venv-mkvirtualenv-using-default-interpreter-works ()
(with-temp-location
(venv-mkvirtualenv-using nil venv-tmp-env)
(should (equal venv-current-name venv-tmp-env))
(venv-deactivate)
(venv-rmvirtualenv venv-tmp-env)))

(ert-deftest venv-mkvirtualenv-using-different-interpreter-works ()
(with-temp-location
(venv-mkvirtualenv-using (executable-find "python") venv-tmp-env)
(should (equal venv-current-name venv-tmp-env))
(venv-deactivate)
(venv-rmvirtualenv venv-tmp-env)))

(ert-deftest venv-mkvirtualenv-using-select-default-interpreter ()
(with-temp-location
(with-simulated-input
"RET"
(let ((current-prefix-arg '(4)))
(venv-mkvirtualenv-using "some invalid interpreter" venv-tmp-env)))
(should (equal venv-current-name venv-tmp-env))
(venv-deactivate)
(venv-rmvirtualenv venv-tmp-env)))

(ert-deftest venv-mkvirtualenv-using-select-different-interpreter ()
(with-temp-location
(with-simulated-input
(concat (executable-find "python") " RET")
(let ((current-prefix-arg '(4)))
(venv-mkvirtualenv-using "some invalid interpreter" venv-tmp-env)))
(should (equal venv-current-name venv-tmp-env))
(venv-deactivate)
(venv-rmvirtualenv venv-tmp-env)))

(ert-deftest venv-workon-works ()
(with-temp-env
venv-tmp-env
Expand All @@ -82,7 +137,7 @@
;; we remove out dir to exec-path
(should (not (s-contains? venv-tmp-env (car exec-path)))))

(ert-deftest venv-workon-errors-for-nonexistance ()
(ert-deftest venv-workon-errors-for-nonexistence ()
(should-error (venv-workon "i-hopefully-do-not-exist")))

(ert-deftest venv-list-virtualenvs-works ()
Expand Down
29 changes: 20 additions & 9 deletions virtualenvwrapper.el
Original file line number Diff line number Diff line change
Expand Up @@ -324,20 +324,22 @@ throwing an error if not"
)

;;;###autoload
(defun venv-mkvirtualenv (&rest names)
"Create new virtualenvs NAMES. If venv-location is a single
directory, the new virtualenvs are made there; if it is a list of
directories, the new virtualenvs are made in the current
default-directory."
(defun venv-mkvirtualenv-using (interpreter &rest names)
"Create new virtualenvs NAMES using INTERPRETER. If venv-location
is a single directory, the new virtualenvs are made there; if it
is a list of directories, the new virtualenvs are made in the
current `default-directory'."
(interactive)
(venv--check-executable)
(let ((parent-dir (if (stringp venv-location)
(let* ((foo (if current-prefix-arg
(read-string "Python executable: ")
interpreter))
(parent-dir (if (stringp venv-location)
(file-name-as-directory
(expand-file-name venv-location))
default-directory))
(python-exe-arg (when current-prefix-arg
(concat "--python="
(read-string "Python executable: " "python"))))
(python-exe-arg (when foo
(concat "--python=" foo)))
(names (if names names
(list (read-from-minibuffer "New virtualenv: ")))))
;; map over all the envs we want to make
Expand All @@ -356,6 +358,15 @@ default-directory."
;; workon the last venv we made
(venv-workon (car (last names)))))

;;;###autoload
(defun venv-mkvirtualenv (&rest names)
"Create new virtualenvs NAMES. If venv-location is a single
directory, the new virtualenvs are made there; if it is a list of
directories, the new virtualenvs are made in the current
`default-directory'."
(interactive)
(apply #'venv-mkvirtualenv-using nil names))

;;;###autoload
(defun venv-rmvirtualenv (&rest names)
"Delete virtualenvs NAMES."
Expand Down

0 comments on commit fa49954

Please sign in to comment.