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
|
2019-02-18 01:56:38 -05:00
|
|
|
(defun +python/open-repl ()
|
2017-03-04 18:46:38 -05:00
|
|
|
"Open the Python REPL."
|
2017-03-19 22:50:52 -04:00
|
|
|
(interactive)
|
2018-10-02 23:52:29 -04:00
|
|
|
(unless python-shell-interpreter
|
|
|
|
(user-error "`python-shell-interpreter' isn't set"))
|
2018-09-26 20:37:35 -04:00
|
|
|
(pop-to-buffer
|
|
|
|
(process-buffer
|
2019-03-04 20:48:52 -05:00
|
|
|
(if-let* ((pipenv (+python-executable-find "pipenv"))
|
2018-10-02 23:52:29 -04:00
|
|
|
(pipenv-project (pipenv-project-p)))
|
|
|
|
(let ((default-directory pipenv-project)
|
|
|
|
(python-shell-interpreter-args
|
|
|
|
(format "run %s %s"
|
|
|
|
python-shell-interpreter
|
|
|
|
python-shell-interpreter-args))
|
|
|
|
(python-shell-interpreter pipenv))
|
|
|
|
(run-python nil t t))
|
|
|
|
(run-python nil t t)))))
|
2018-07-31 14:02:34 +02:00
|
|
|
|
2018-10-06 00:24:44 -04:00
|
|
|
;;;###autoload
|
|
|
|
(defun +python/open-ipython-repl ()
|
|
|
|
"Open an IPython REPL."
|
|
|
|
(interactive)
|
2019-03-04 20:48:52 -05:00
|
|
|
(let ((python-shell-interpreter (or (+python-executable-find "ipython") "ipython"))
|
2019-02-28 04:10:35 -05:00
|
|
|
(python-shell-interpreter-args (string-join +python-ipython-repl-args " ")))
|
2019-02-18 01:56:38 -05:00
|
|
|
(+python/open-repl)))
|
2018-10-06 00:24:44 -04:00
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun +python/open-jupyter-repl ()
|
|
|
|
"Open a Jupyter console."
|
|
|
|
(interactive)
|
|
|
|
(add-to-list 'python-shell-completion-native-disabled-interpreters "jupyter")
|
2019-03-04 20:48:52 -05:00
|
|
|
(let ((python-shell-interpreter (or (+python-executable-find "jupyter") "jupyter"))
|
2019-02-28 04:10:35 -05:00
|
|
|
(python-shell-interpreter-args (format "console %s" (string-join +python-jupyter-repl-args " "))))
|
2019-02-18 01:56:38 -05:00
|
|
|
(+python/open-repl)))
|
2019-03-04 20:48:52 -05:00
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun +python-executable-find (exe)
|
|
|
|
"TODO"
|
|
|
|
(if (file-name-absolute-p exe)
|
2019-05-21 17:16:40 -04:00
|
|
|
(and (file-executable-p exe)
|
|
|
|
exe)
|
2019-03-04 20:48:52 -05:00
|
|
|
(let ((exe-root (format "bin/%s" exe)))
|
|
|
|
(cond ((when python-shell-virtualenv-root
|
|
|
|
(let ((bin (expand-file-name exe-root python-shell-virtualenv-root)))
|
|
|
|
(if (file-exists-p bin) bin))))
|
2019-03-05 02:30:14 -05:00
|
|
|
((when (require 'conda nil t)
|
2019-03-04 20:48:52 -05:00
|
|
|
(let ((bin (expand-file-name (concat conda-env-current-name "/" exe-root)
|
2019-06-15 00:38:13 +02:00
|
|
|
(conda-env-default-location))))
|
2019-03-04 20:48:52 -05:00
|
|
|
(if (file-executable-p bin) bin))))
|
2019-06-25 21:38:16 +02:00
|
|
|
((when-let (bin (projectile-locate-dominating-file default-directory "bin/python"))
|
2019-03-04 20:48:52 -05:00
|
|
|
(setq-local doom-modeline-python-executable (expand-file-name "bin/python" bin))))
|
|
|
|
((executable-find exe))))))
|