Add +python-{ipython,jupyter}-command vars for REPLs
This commit is contained in:
parent
76eae7bc46
commit
1c99aed0c0
2 changed files with 34 additions and 28 deletions
|
@ -1,5 +1,25 @@
|
||||||
;;; lang/python/autoload/python.el -*- lexical-binding: t; -*-
|
;;; lang/python/autoload/python.el -*- lexical-binding: t; -*-
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(defun +python-executable-find (exe)
|
||||||
|
"Resolve the path to the EXE executable.
|
||||||
|
Tries to be aware of your active conda/pipenv/virtualenv environment, before
|
||||||
|
falling back on searching your PATH."
|
||||||
|
(if (file-name-absolute-p exe)
|
||||||
|
(and (file-executable-p exe)
|
||||||
|
exe)
|
||||||
|
(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))))
|
||||||
|
((when (require 'conda nil t)
|
||||||
|
(let ((bin (expand-file-name (concat conda-env-current-name "/" exe-root)
|
||||||
|
(conda-env-default-location))))
|
||||||
|
(if (file-executable-p bin) bin))))
|
||||||
|
((when-let (bin (projectile-locate-dominating-file default-directory "bin/python"))
|
||||||
|
(setq-local doom-modeline-python-executable (expand-file-name "bin/python" bin))))
|
||||||
|
((executable-find exe))))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun +python/open-repl ()
|
(defun +python/open-repl ()
|
||||||
"Open the Python REPL."
|
"Open the Python REPL."
|
||||||
|
@ -25,8 +45,11 @@
|
||||||
"Open an IPython REPL."
|
"Open an IPython REPL."
|
||||||
(interactive)
|
(interactive)
|
||||||
(require 'python)
|
(require 'python)
|
||||||
(let ((python-shell-interpreter (or (+python-executable-find "ipython") "ipython"))
|
(let ((python-shell-interpreter
|
||||||
(python-shell-interpreter-args (string-join +python-ipython-repl-args " ")))
|
(or (+python-executable-find (car +python-ipython-command))
|
||||||
|
"ipython"))
|
||||||
|
(python-shell-interpreter-args
|
||||||
|
(string-join (cdr +python-ipython-command) " ")))
|
||||||
(+python/open-repl)))
|
(+python/open-repl)))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
|
@ -35,28 +58,13 @@
|
||||||
(interactive)
|
(interactive)
|
||||||
(require 'python)
|
(require 'python)
|
||||||
(add-to-list 'python-shell-completion-native-disabled-interpreters "jupyter")
|
(add-to-list 'python-shell-completion-native-disabled-interpreters "jupyter")
|
||||||
(let ((python-shell-interpreter (or (+python-executable-find "jupyter") "jupyter"))
|
(let ((python-shell-interpreter
|
||||||
(python-shell-interpreter-args (format "console %s" (string-join +python-jupyter-repl-args " "))))
|
(or (+python-executable-find (car +python-jupyter-command))
|
||||||
|
"jupyter"))
|
||||||
|
(python-shell-interpreter-args
|
||||||
|
(string-join (cdr +python-jupyter-command) " ")))
|
||||||
(+python/open-repl)))
|
(+python/open-repl)))
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun +python-executable-find (exe)
|
|
||||||
"TODO"
|
|
||||||
(if (file-name-absolute-p exe)
|
|
||||||
(and (file-executable-p exe)
|
|
||||||
exe)
|
|
||||||
(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))))
|
|
||||||
((when (require 'conda nil t)
|
|
||||||
(let ((bin (expand-file-name (concat conda-env-current-name "/" exe-root)
|
|
||||||
(conda-env-default-location))))
|
|
||||||
(if (file-executable-p bin) bin))))
|
|
||||||
((when-let (bin (projectile-locate-dominating-file default-directory "bin/python"))
|
|
||||||
(setq-local doom-modeline-python-executable (expand-file-name "bin/python" bin))))
|
|
||||||
((executable-find exe))))))
|
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun +python/optimize-imports ()
|
(defun +python/optimize-imports ()
|
||||||
"organize imports"
|
"organize imports"
|
||||||
|
|
|
@ -1,12 +1,10 @@
|
||||||
;;; lang/python/config.el -*- lexical-binding: t; -*-
|
;;; lang/python/config.el -*- lexical-binding: t; -*-
|
||||||
|
|
||||||
(defvar +python-ipython-repl-args '("-i" "--simple-prompt" "--no-color-info")
|
(defvar +python-ipython-command '("ipython" "-i" "--simple-prompt" "--no-color-info")
|
||||||
"CLI arguments to initialize ipython with when `+python/open-ipython-repl' is
|
"Command to initialize the ipython REPL for `+python/open-ipython-repl'.")
|
||||||
called.")
|
|
||||||
|
|
||||||
(defvar +python-jupyter-repl-args '("--simple-prompt")
|
(defvar +python-jupyter-command '("jupyter" "console" "--simple-prompt")
|
||||||
"CLI arguments to initialize 'jupiter console %s' with when
|
"Command to initialize the jupyter REPL for `+python/open-jupyter-repl'.")
|
||||||
`+python/open-ipython-repl' is called.")
|
|
||||||
|
|
||||||
(after! projectile
|
(after! projectile
|
||||||
(pushnew! projectile-project-root-files "setup.py" "requirements.txt"))
|
(pushnew! projectile-project-root-files "setup.py" "requirements.txt"))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue