diff --git a/README.md b/README.md index 5c66682..03f7fc2 100644 --- a/README.md +++ b/README.md @@ -324,10 +324,11 @@ instead: (projectile-find-file))) ``` -As long as a virtualenv is found in the `projectile-project-root` and -whose name is in the list `venv-dirlookup-names` it will be -automatically activated. By default, it's value is `'(".venv", "venv")'`, -but you can set if however you like to match your naming conventions: +As long as a virtualenv or a text file with the name of the virtualenv is +found in the `projectile-project-root` and whose name is in the list +`venv-dirlookup-names` it will be automatically activated. By default, it's +value is `'(".venv", "venv")'`, but you can set if however you like to match +your naming conventions: ```lisp (setq venv-dirlookup-names '(".venv" "pyenv" ".virtual")) diff --git a/virtualenvwrapper.el b/virtualenvwrapper.el index fac8fd7..01a7746 100644 --- a/virtualenvwrapper.el +++ b/virtualenvwrapper.el @@ -94,12 +94,19 @@ to activate when one of them is found." "If a venv in the projetile root exists, activates it. Set your common venvs names in `venv-dirlookup-names'" (let ((path (--first - (file-exists-p it) - (--map (concat (projectile-project-root) it) - venv-dirlookup-names)))) + (file-exists-p it) + (--map (concat (projectile-project-root) it) + venv-dirlookup-names)))) (when path - (setq venv-current-name path) ;; there's really nothing that feels good to do here ;_; - (venv--activate-dir path)))) + ;; If the PATH is a regular and readable file, read the first + ;; string in this file and use it to active the virtualenv. + (if (and path (file-regular-p path) (file-readable-p path)) + (with-temp-buffer + (insert-file-contents path) + (venv-workon (car (split-string (buffer-string) "\n" t)))) + ;; PATH is not a file, assume it's a virtualenv directory and activate it + (setq venv-current-name path) ;; there's really nothing that feels good to do here ;_; + (venv--activate-dir path))))) ;; internal utility functions