-
-
Save caiorss/26f8f47dd12ccc870d3d 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 local-path (path) | |
"Return the local portion of a path. | |
If PATH is local, return it unaltered. | |
If PATH is remote, return the remote diretory portion of the path." | |
(if (tramp-tramp-file-p path) | |
(elt (tramp-dissect-file-name path) 3) | |
path)) | |
(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))) | |
(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 () | |
(interactive) | |
(with-virtualenv-python | |
(run-python))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment