Skip to content

Commit fa49954

Browse files
authored
Merge pull request #49 from sambrightman/venv-mkvirtualenv-using
Allow interpreter to be set non-interactively
2 parents b4fd61a + f2f5792 commit fa49954

File tree

5 files changed

+103
-24
lines changed

5 files changed

+103
-24
lines changed

.travis.yml

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,28 @@
1-
language: emacs-lisp
1+
language: generic
22
sudo: false
33
dist: trusty
4-
before_install:
5-
- git clone https://github.com/rejeep/evm.git ~/.evm
6-
- evm config path /tmp
7-
- evm install $EVM_EMACS
8-
- evm use $EVM_EMACS
9-
- sudo apt-get install -y python-pip
10-
- sudo pip install virtualenv
11-
- curl -fsSkL https://raw.github.com/cask/cask/master/go | python
12-
- cask
4+
addons:
5+
apt:
6+
packages:
7+
- python-pip
138
env:
149
global:
15-
- PATH="~/.evm/bin:~/.cask/bin:$PATH"
10+
- PATH=~/.evm/bin:~/.cask/bin:$PATH
1611
matrix:
1712
- EVM_EMACS=emacs-24.5-travis
1813
- EVM_EMACS=emacs-25.1-travis
1914
- EVM_EMACS=emacs-25.2-travis
2015
- EVM_EMACS=emacs-25.3-travis
21-
- EVM_EMACS=emacs-git-snapshot-travis
16+
# - EVM_EMACS=emacs-git-snapshot-travis
17+
before_install:
18+
- pip install -U --user virtualenv
19+
- curl -fsSkL https://raw.github.com/rejeep/evm/master/go | bash
20+
- evm config path /tmp
21+
- evm install $EVM_EMACS
22+
- evm use $EVM_EMACS
23+
- hash -r
24+
- curl -fsSkL https://raw.github.com/cask/cask/master/go | python
25+
- cask exec emacs --version
26+
- cask install
2227
script:
23-
cask exec ert-runner
28+
- cask exec ert-runner

Cask

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
(source gnu)
12
(source melpa)
23

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

89
(development
910
(depends-on "ert-runner")
10-
(depends-on "noflet"))
11+
(depends-on "noflet")
12+
(depends-on "with-simulated-input"))

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,12 @@ list), then the new virtualenv will be created in the current default
180180
directory. Also callable noninteractively as `(venv-mkvirtualenv
181181
"name")`.
182182

183+
#### `venv-mkvirtualenv-using`
184+
185+
Supplying a prefix command (`C-u`) to `venv-mkvirtualenv` will prompt
186+
for a Python interpreter to use. You can use this function to specify
187+
the interpreter noninteractively.
188+
183189
#### `venv-rmvirtualenv`
184190

185191
Prompt for the name of a virutalenv and delete it. Also callable

test/virtualenvwrapper-test.el

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
(load (expand-file-name "virtualenvwrapper.el" default-directory))
99
(require 's)
1010
(require 'noflet)
11+
(require 'with-simulated-input)
1112

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

@@ -58,6 +59,60 @@
5859
(venv-rmvirtualenv venv-tmp-env)
5960
(should-error (venv-workon venv-tmp-env))))
6061

62+
(ert-deftest venv-mkvirtualenv-select-default-interpreter ()
63+
(with-temp-location
64+
(let ((current-prefix-arg '(4)))
65+
(with-simulated-input
66+
"RET"
67+
(venv-mkvirtualenv venv-tmp-env))
68+
(should (equal venv-current-name venv-tmp-env))
69+
(venv-deactivate)
70+
(venv-rmvirtualenv venv-tmp-env))))
71+
72+
(ert-deftest venv-mkvirtualenv-select-different-interpreter ()
73+
(with-temp-location
74+
(let ((current-prefix-arg '(4)))
75+
(with-simulated-input
76+
(concat (executable-find "python") " RET")
77+
(venv-mkvirtualenv venv-tmp-env))
78+
(should (equal venv-current-name venv-tmp-env))
79+
(venv-deactivate)
80+
(venv-rmvirtualenv venv-tmp-env))))
81+
82+
(ert-deftest venv-mkvirtualenv-using-default-interpreter-works ()
83+
(with-temp-location
84+
(venv-mkvirtualenv-using nil venv-tmp-env)
85+
(should (equal venv-current-name venv-tmp-env))
86+
(venv-deactivate)
87+
(venv-rmvirtualenv venv-tmp-env)))
88+
89+
(ert-deftest venv-mkvirtualenv-using-different-interpreter-works ()
90+
(with-temp-location
91+
(venv-mkvirtualenv-using (executable-find "python") venv-tmp-env)
92+
(should (equal venv-current-name venv-tmp-env))
93+
(venv-deactivate)
94+
(venv-rmvirtualenv venv-tmp-env)))
95+
96+
(ert-deftest venv-mkvirtualenv-using-select-default-interpreter ()
97+
(with-temp-location
98+
(with-simulated-input
99+
"RET"
100+
(let ((current-prefix-arg '(4)))
101+
(venv-mkvirtualenv-using "some invalid interpreter" venv-tmp-env)))
102+
(should (equal venv-current-name venv-tmp-env))
103+
(venv-deactivate)
104+
(venv-rmvirtualenv venv-tmp-env)))
105+
106+
(ert-deftest venv-mkvirtualenv-using-select-different-interpreter ()
107+
(with-temp-location
108+
(with-simulated-input
109+
(concat (executable-find "python") " RET")
110+
(let ((current-prefix-arg '(4)))
111+
(venv-mkvirtualenv-using "some invalid interpreter" venv-tmp-env)))
112+
(should (equal venv-current-name venv-tmp-env))
113+
(venv-deactivate)
114+
(venv-rmvirtualenv venv-tmp-env)))
115+
61116
(ert-deftest venv-workon-works ()
62117
(with-temp-env
63118
venv-tmp-env
@@ -82,7 +137,7 @@
82137
;; we remove out dir to exec-path
83138
(should (not (s-contains? venv-tmp-env (car exec-path)))))
84139

85-
(ert-deftest venv-workon-errors-for-nonexistance ()
140+
(ert-deftest venv-workon-errors-for-nonexistence ()
86141
(should-error (venv-workon "i-hopefully-do-not-exist")))
87142

88143
(ert-deftest venv-list-virtualenvs-works ()

virtualenvwrapper.el

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -324,20 +324,22 @@ throwing an error if not"
324324
)
325325

326326
;;;###autoload
327-
(defun venv-mkvirtualenv (&rest names)
328-
"Create new virtualenvs NAMES. If venv-location is a single
329-
directory, the new virtualenvs are made there; if it is a list of
330-
directories, the new virtualenvs are made in the current
331-
default-directory."
327+
(defun venv-mkvirtualenv-using (interpreter &rest names)
328+
"Create new virtualenvs NAMES using INTERPRETER. If venv-location
329+
is a single directory, the new virtualenvs are made there; if it
330+
is a list of directories, the new virtualenvs are made in the
331+
current `default-directory'."
332332
(interactive)
333333
(venv--check-executable)
334-
(let ((parent-dir (if (stringp venv-location)
334+
(let* ((foo (if current-prefix-arg
335+
(read-string "Python executable: ")
336+
interpreter))
337+
(parent-dir (if (stringp venv-location)
335338
(file-name-as-directory
336339
(expand-file-name venv-location))
337340
default-directory))
338-
(python-exe-arg (when current-prefix-arg
339-
(concat "--python="
340-
(read-string "Python executable: " "python"))))
341+
(python-exe-arg (when foo
342+
(concat "--python=" foo)))
341343
(names (if names names
342344
(list (read-from-minibuffer "New virtualenv: ")))))
343345
;; map over all the envs we want to make
@@ -356,6 +358,15 @@ default-directory."
356358
;; workon the last venv we made
357359
(venv-workon (car (last names)))))
358360

361+
;;;###autoload
362+
(defun venv-mkvirtualenv (&rest names)
363+
"Create new virtualenvs NAMES. If venv-location is a single
364+
directory, the new virtualenvs are made there; if it is a list of
365+
directories, the new virtualenvs are made in the current
366+
`default-directory'."
367+
(interactive)
368+
(apply #'venv-mkvirtualenv-using nil names))
369+
359370
;;;###autoload
360371
(defun venv-rmvirtualenv (&rest names)
361372
"Delete virtualenvs NAMES."

0 commit comments

Comments
 (0)