virtualenv activation hooks?
When I set up my virtual environment in emacs, I also configure flycheck's pylint to point to the executable that's in the virtual environment. The way I'm doing this right now is:
(defun my-set-
"Change flycheck pylint executable to virtualenv executable"
(if (and (boundp 'virtualenv-name)
(let ((pylintpath
))
(setq flycheck-
)))
(add-hook 'python-mode-hook 'my-set-
but this means if I open a Python file, then go "oh yeah, I need to set the virtual environment" and set it with (virtualenv-
The way I'd rather do this is make it a hook to (virtualenv-
Is there a way to automate this that actually supports the workflow I've described?
Question information
- Language:
- English Edit question
- Status:
- Answered
- Assignee:
- Andreas Roehler Edit question
- Last query:
- 2014-06-11
- Last reply:
- 2014-06-14
Andreas Roehler (a-roehler) said : | #1 |
As several virtualenv tools are out there, it's difficult to answer.
Maybe give some details of configuration, which files wherefrom in use etc.
For the moment some work-around advising `virtualenv-
;; (add-hook 'python-mode-hook 'my-set-
(defvar py-pylint-default (executable-find "pylint"))
(defun my-set-
"Change flycheck pylint executable to virtualenv executable"
;; virtualenv-name might be nil
(when (and (boundp 'virtualenv-
(virtualenv-p (py--normalize-
(let ((pylintpath
(concat (py--normalize-
"bin/
(setq flycheck-
;; IMO the inverse is needed also
(defun my-reset-pylint ()
"Set flycheck `pylint' executable to default value. "
(interactive)
(setq flycheck-
(defadvice virtualenv-activate (after my-set-
(my-set-
(ad-activate 'virtualenv-
(defadvice virtualenv-
(my-reset-
(ad-activate 'virtualenv-
;;;;
Andreas
Nathan Typanski (ntypanski) said : | #2 |
Thanks for the workaround, and glad to see you're working on a real solution also!
For reference, I use virtualenvwrapper to configure my virtualenvs. Everything from my Python environment is in `~/.virtualenvs
Unfortunately, the above as posted isn't loading in the current buffer, but works on all future buffers. I could chock that up to running development versions of absolutely everything, but I do think advising is the way to go and I think I should be able to find a configuration that works.
Thanks for the tips - and I agree with you, saving and restoring the pylint executable is necessary also. You wouldn't want to be using a venv pylint after deactivating it.
Can you help with this problem?
Provide an answer of your own, or ask Nathan Typanski for more information if necessary.