Skip to content

Instantly share code, notes, and snippets.

@ieure
Created January 26, 2011 19:09
Show Gist options
  • Save ieure/797230 to your computer and use it in GitHub Desktop.
Save ieure/797230 to your computer and use it in GitHub Desktop.
(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