diff --git a/.travis.yml b/.travis.yml index fb325fa..607ceb0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/Cask b/Cask index 948f451..ffd7969 100644 --- a/Cask +++ b/Cask @@ -1,3 +1,4 @@ +(source gnu) (source melpa) (package "virtualenvwrapper" "20140315" "a featureful virtualenv tool for Emacs") @@ -7,4 +8,5 @@ (development (depends-on "ert-runner") - (depends-on "noflet")) + (depends-on "noflet") + (depends-on "with-simulated-input")) diff --git a/README.md b/README.md index 5c66682..acb4f0f 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/test/virtualenvwrapper-test.el b/test/virtualenvwrapper-test.el index a394470..837b520 100644 --- a/test/virtualenvwrapper-test.el +++ b/test/virtualenvwrapper-test.el @@ -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") @@ -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 @@ -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 () diff --git a/virtualenvwrapper.el b/virtualenvwrapper.el index 17fa02f..c6f8f82 100644 --- a/virtualenvwrapper.el +++ b/virtualenvwrapper.el @@ -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 @@ -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."