-
-
Save caiorss/4fce0e4388580144b376 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun python-find-python-command (&optional root) | |
"Return the python interpreter to use for ROOT." | |
(let ((env-root (local-path | |
(locate-dominating-file | |
(or root default-directory) "bin/python")))) | |
(or (when env-root (concat env-root "bin/python")) | |
python-python-command))) | |
(defun python-find-project-root (&optional start) | |
"Return the root of this Python project." | |
(let ((start (or start default-directory))) | |
(or (locate-dominating-file start "setup.py") | |
(locate-dominating-file start ".git")))) | |
(defmacro with-virtualenv-python (&rest body) | |
"Locate a local Python interpreter and make it available in the body." | |
`(let* ((local-python-command (python-find-python-command)) | |
(python-command local-python-command) | |
(python-python-command local-python-command) | |
(test-case-python-executable local-python-command)) | |
,@body)) | |
(defun run-virtualenv-python (new) | |
(interactive "P") | |
(with-virtualenv-python | |
(let ((default-directory (python-find-project-root))) | |
(run-python python-python-command nil new)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment