Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -332,10 +332,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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, could you check "allow edits from maintainers". There's a couple clarifications I'd like to make to this documentation that are probably easier for me to just do than to explain :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Allow edits from maintainers" is checked. Edit away :)

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"))
Expand Down
18 changes: 18 additions & 0 deletions test/virtualenvwrapper-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,21 @@
(s-concat (venv-name-to-dir venv-tmp-env) ".project"))
(venv-workon venv-tmp-env)
(should (not (equal default-directory temp-dir)))))))

(ert-deftest venv-projectile-auto-workon-works-with-text-file ()
(with-temp-env
venv-tmp-env
;; the reason for setting a bogus venv-location here is that the
;; venv-location shouldn't matter, projectile-auto-workon should happen
;; indepedent of it's being set or not
(let* ((venv-location "bogus")
;; Create a file in the projectile-project-root with
;; the text content of the venv to be activated
(venv-tmp-text-file (make-temp-file "venv" nil nil venv-tmp-env))
(venv-tmp-text-name (file-name-nondirectory venv-tmp-text-file)))
(noflet ((projectile-project-root () temporary-file-directory))
(setq venv-dirlookup-names (list venv-tmp-text-name))
(venv-deactivate)
(venv-projectile-auto-workon)
(assert-venv-activated)
(delete-file venv-tmp-text-file)))))
11 changes: 9 additions & 2 deletions virtualenvwrapper.el
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,15 @@ Set your common venvs names in `venv-dirlookup-names'"
(--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))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a comment here clarifying what this code does? Doesn't have to be long, I just find if a bit hard to read in ELisp since there's no explicit else and I don't want to be scratching my head on this code more than necessary somewhere down the road.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a comment.
Please check if the comment makes it clear what the code does.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perfect!

(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
Expand Down