2018-07-17 20:57:32 +02:00
|
|
|
;;; lang/python/autoload/python.el -*- lexical-binding: t; -*-
|
2017-03-04 18:46:38 -05:00
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun +python/repl ()
|
|
|
|
"Open the Python REPL."
|
2017-03-19 22:50:52 -04:00
|
|
|
(interactive)
|
2017-04-22 17:08:26 -04:00
|
|
|
(process-buffer (run-python nil t t)))
|
2018-07-31 14:02:34 +02:00
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun +python-version ()
|
|
|
|
"Return the currently installed version of python on your system or active in
|
|
|
|
the current pipenv.
|
|
|
|
|
|
|
|
This is not necessarily aware of env management tools like virtualenv, pyenv or
|
|
|
|
pipenv, unless those tools have modified the PATH that Emacs picked up when you
|
|
|
|
started it."
|
2018-09-21 13:31:46 -04:00
|
|
|
(let* ((pipenv-dir (pipenv-project-p))
|
|
|
|
(default-directory (or pipenv-dir default-directory))
|
|
|
|
(command (if pipenv-dir
|
2018-07-31 14:02:34 +02:00
|
|
|
"pipenv run python --version"
|
|
|
|
"python --version"))
|
|
|
|
(bin (car (split-string command " "))))
|
|
|
|
(unless (executable-find bin)
|
|
|
|
(user-error "Couldn't find %s executable in PATH" bin))
|
|
|
|
(with-temp-buffer
|
|
|
|
(let ((p (apply #'call-process bin nil (current-buffer) nil
|
|
|
|
(cdr (split-string command " " t))))
|
|
|
|
(output (string-trim (buffer-string))))
|
|
|
|
(unless (zerop p)
|
|
|
|
(user-error "'%s' failed: %s" command output))
|
2018-09-21 13:31:46 -04:00
|
|
|
(cadr (split-string output " " t))))))
|