From 6fb4b4051930584078a5b905fc525a8e4f1bc1a4 Mon Sep 17 00:00:00 2001 From: Sam Brightman Date: Thu, 9 Nov 2017 20:54:13 +0000 Subject: [PATCH 1/5] Tidy up .travis.yml a bit more --- .travis.yml | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/.travis.yml b/.travis.yml index fb325fa..9a60978 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,23 +1,26 @@ -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 +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 + - curl -fsSkL https://raw.github.com/cask/cask/master/go | python + - cask install script: - cask exec ert-runner + - cask exec ert-runner From cd48457a859a8cfb90b1419a83ad27509f865d5d Mon Sep 17 00:00:00 2001 From: Sam Brightman Date: Wed, 20 Sep 2017 07:56:16 +0100 Subject: [PATCH 2/5] Ensure cask runs with the intended Emacs version Quoting $PATH prevents tilde expansion and cask uses execvp rather than a shell, so does not find Emacs correctly unless the path is already expanded. Shell command hashing prevents the correct Emacs from being found first, even when earlier in $PATH. --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 9a60978..b1fae30 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,7 @@ addons: - 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 @@ -20,6 +20,7 @@ before_install: - 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 install script: From 45845dd71277ed90828ce9f27c5f1c00cff86ef7 Mon Sep 17 00:00:00 2001 From: Sam Brightman Date: Thu, 9 Nov 2017 20:49:08 +0000 Subject: [PATCH 3/5] Always output Emacs version for visibility of correct testing --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index b1fae30..4eaa0bb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,6 +22,7 @@ before_install: - 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 From 8217d1031f8378d7a1cbad66c3a20de3ca7fa555 Mon Sep 17 00:00:00 2001 From: Sam Brightman Date: Fri, 10 Nov 2017 00:00:10 +0000 Subject: [PATCH 4/5] Temporarily remove snapshot testing * current EVM snapshot has no gnutls support * gnutls-bin not installed on Travis by default * installing it only hits bug in files.el Re-instate once a new snapshot is up. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 4eaa0bb..607ceb0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,7 @@ env: - 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 From f2f5792367a0724198bd651ab913415b24383597 Mon Sep 17 00:00:00 2001 From: Sam Brightman Date: Sun, 17 Sep 2017 00:21:45 +0100 Subject: [PATCH 5/5] Add venv-mkvirtualenv-using, allowing programmatic choice of interpreter --- Cask | 4 ++- README.md | 6 ++++ test/virtualenvwrapper-test.el | 57 +++++++++++++++++++++++++++++++++- virtualenvwrapper.el | 29 +++++++++++------ 4 files changed, 85 insertions(+), 11 deletions(-) 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."