Updating Doom Emacs.

This commit is contained in:
Derek Taylor
2020-06-19 22:43:40 -05:00
parent 0f664d532a
commit a5c86c514a
453 changed files with 13527 additions and 12455 deletions

View File

@@ -7,7 +7,6 @@
- [[#description][Description]]
- [[#module-flags][Module Flags]]
- [[#plugins][Plugins]]
- [[#hacks][Hacks]]
- [[#prerequisites][Prerequisites]]
- [[#language-server-protocol-support][Language Server Protocol Support]]
- [[#features][Features]]
@@ -26,6 +25,8 @@ Adds Python support to Doom Emacs.
+ ~+lsp~ Language Server Protocol support
+ ~+pyenv~ Python virtual environment support via [[https://github.com/pyenv/pyenv][pyenv]]
+ ~+conda~ Python virtual environment support via [[https://conda.io/en/latest/][Conda]]
+ ~+poetry~ Python packaging, dependency management, and virtual environment
support via [[https://python-poetry.org/][Poetry]]
+ ~+cython~ Cython files support via [[https://github.com/cython/cython/blob/master/Tools/cython-mode.el][Cython-mode]]
** Plugins
@@ -42,17 +43,14 @@ Adds Python support to Doom Emacs.
+ [[https://github.com/necaris/conda.el][conda]]*
+ ~+pyenv~
+ [[https://github.com/pythonic-emacs/pyenv-mode][pyenv]]*
+ ~+poetry~
+ [[https://github.com/galaunay/poetry.el][poetry]]*
+ ~+lsp~ and ~:tools lsp~
+ [[https://github.com/emacs-lsp/lsp-mode][lsp]]
+ [[https://github.com/emacs-lsp/lsp-python-ms][lsp-python-ms]]*
+ ~+cython~
+ [[https://github.com/cython/cython/blob/master/Tools/cython-mode.el][Cython-mode]]
+ ~:tools flycheck~ [[https://github.com/lbolla/emacs-flycheck-cython/tree/master][Flycheck-cython]]
** Hacks
+ As per our "your system your rules" mantra, lsp-python-ms has been modified to
*not* automatically install its server if it cannot find it. Install it with
~M-x lsp-python-ms-setup~.
+ ~:checkers syntax~ [[https://github.com/lbolla/emacs-flycheck-cython/tree/master][Flycheck-cython]]
* Prerequisites
This module has no direct prerequisites. Here are some of its soft dependencies.
@@ -73,22 +71,26 @@ This module has no direct prerequisites. Here are some of its soft dependencies.
+ Python virtual environments install instructions at:
+ [[https://github.com/pyenv/pyenv][pyenv]]
+ [[https://conda.io/en/latest/][Conda]]
+ [[https://python-poetry.org/][Poetry]]
+ ~pipenv~ requires [[https://pipenv.readthedocs.io/en/latest/][pipenv]]
+ ~cython~ requires [[https://cython.org/][Cython]]
** Language Server Protocol Support
Requires the ~+lsp~ flag and ~:tools lsp~ module to be enabled.
By default LSP will use Microsoft's language server if installed.
This module must be enabled with the =+lsp= flag, and the =:tools lsp= module
must be enabled. LSP will try pyls then mspyls; the first that is available.
To install the language server:
~M-x lsp-python-ms-setup~
To update the server:
~M-x lsp-python-ms-update-server~
*To use [[https://pypi.org/project/python-language-server/][Python Language Server]] (pyls)* install it with ~pip install
'python-language-server[all]'~
Alternatively you can use the [[https://pypi.org/project/python-language-server/][Python Language Server]] instead.
~pip install 'python-language-server[all]'~
*To use mspyls*, install it with ~M-x lsp-install-server~ and add this to your
private config.el:
#+BEGIN_SRC elisp
(after! lsp-python-ms
(set-lsp-priority! 'mspyls 1))
#+END_SRC
* Features
This module supports LSP. It requires installation of [[https://pypi.org/project/python-language-server/][Python Language
@@ -114,7 +116,7 @@ To enable support for auto-formatting with black enable ~:editor format-all~ in
| ~<localleader> t O~ | ~nosetests-pdb-one~ |
| ~<localleader> t V~ | ~nosetests-pdb-module~ |
| ~<localleader> t f~ | ~python-pytest-file~ |
| ~<localleader> t k~ | ~python-pytest-file-dwin~ |
| ~<localleader> t k~ | ~python-pytest-file-dwim~ |
| ~<localleader> t t~ | ~python-pytest-function~ |
| ~<localleader> t m~ | ~python-pytest-function-dwim~ |
| ~<localleader> t r~ | ~python-pytest-repeat~ |

View File

@@ -4,6 +4,7 @@
(defun +python/open-repl ()
"Open the Python REPL."
(interactive)
(require 'python)
(unless python-shell-interpreter
(user-error "`python-shell-interpreter' isn't set"))
(pop-to-buffer
@@ -23,6 +24,7 @@
(defun +python/open-ipython-repl ()
"Open an IPython REPL."
(interactive)
(require 'python)
(let ((python-shell-interpreter (or (+python-executable-find "ipython") "ipython"))
(python-shell-interpreter-args (string-join +python-ipython-repl-args " ")))
(+python/open-repl)))
@@ -31,6 +33,7 @@
(defun +python/open-jupyter-repl ()
"Open a Jupyter console."
(interactive)
(require 'python)
(add-to-list 'python-shell-completion-native-disabled-interpreters "jupyter")
(let ((python-shell-interpreter (or (+python-executable-find "jupyter") "jupyter"))
(python-shell-interpreter-args (format "console %s" (string-join +python-jupyter-repl-args " "))))

View File

@@ -16,13 +16,17 @@ called.")
;; Packages
(use-package! python
:defer t
:mode ("[./]flake8\\'" . conf-mode)
:mode ("/Pipfile\\'" . conf-mode)
:init
(setq python-environment-directory doom-cache-dir
python-indent-guess-indent-offset-verbose nil)
(when (featurep! +lsp)
(add-hook 'python-mode-local-vars-hook #'lsp!))
(add-hook 'python-mode-local-vars-hook #'lsp!)
;; Use "mspyls" in eglot if in PATH
(when (executable-find "Microsoft.Python.LanguageServer")
(set-eglot-client! 'python-mode '("Microsoft.Python.LanguageServer"))))
:config
(set-repl-handler! 'python-mode #'+python/open-repl :persist t)
(set-docsets! 'python-mode "Python 3" "NumPy" "SciPy")
@@ -93,14 +97,16 @@ called.")
(setq anaconda-mode-installation-directory (concat doom-etc-dir "anaconda/")
anaconda-mode-eldoc-as-single-line t)
(add-hook! 'python-mode-local-vars-hook
(add-hook! 'python-mode-local-vars-hook :append
(defun +python-init-anaconda-mode-maybe-h ()
"Enable `anaconda-mode' if `lsp-mode' isn't."
"Enable `anaconda-mode' if `lsp-mode' is absent and
`python-shell-interpreter' is present."
(unless (or (bound-and-true-p lsp-mode)
(bound-and-true-p lsp--buffer-deferred))
(bound-and-true-p eglot--managed-mode)
(bound-and-true-p lsp--buffer-deferred)
(not (executable-find python-shell-interpreter)))
(anaconda-mode +1))))
:config
(add-hook 'anaconda-mode-hook #'anaconda-eldoc-mode)
(set-company-backend! 'anaconda-mode '(company-anaconda))
(set-lookup-handlers! 'anaconda-mode
:definition #'anaconda-mode-find-definitions
@@ -108,6 +114,8 @@ called.")
:documentation #'anaconda-mode-show-doc)
(set-popup-rule! "^\\*anaconda-mode" :select nil)
(add-hook 'anaconda-mode-hook #'anaconda-eldoc-mode)
(defun +python-auto-kill-anaconda-processes-h ()
"Kill anaconda processes if this buffer is the last python buffer."
(when (and (eq major-mode 'python-mode)
@@ -277,23 +285,26 @@ called.")
'append))
(use-package! lsp-python-ms
:when (featurep! +lsp)
:after (python lsp-clients)
:init
(setq lsp-python-ms-dir (concat doom-etc-dir "mspyls/"))
(use-package! poetry
:when (featurep! +poetry)
:after python)
(use-package! lsp-python-ms
:when (and (featurep! +lsp) (not (featurep! :tools lsp +eglot)))
:after lsp-clients
:preface
(after! python
(setq lsp-python-ms-python-executable-cmd python-shell-interpreter))
;; HACK lsp-python-ms shouldn't install itself if it isn't present. This
;; circumvents LSP falling back to pyls when lsp-python-ms is absent.
;; Installing the server should be a deliberate act; either 'M-x
;; lsp-python-ms-setup' or setting `lsp-python-ms-executable' to an existing
;; install will do.
(defadvice! +python--dont-auto-install-server-a ()
:override #'lsp-python-ms--command-string
lsp-python-ms-executable))
:init
;; HACK If you don't have python installed, then opening python buffers with
;; this on causes a "wrong number of arguments: nil 0" error, because of
;; careless usage of `cl-destructuring-bind'. This silences that error,
;; since we may still want to write some python on a system without
;; python installed!
(defadvice! +python--silence-errors-a (orig-fn &rest args)
:around #'lsp-python-ms--extra-init-params
(ignore-errors (apply orig-fn args))))
(use-package! cython-mode
@@ -309,5 +320,5 @@ called.")
(use-package! flycheck-cython
:when (featurep! +cython)
:when (featurep! :tools flycheck)
:when (featurep! :checkers syntax)
:after cython-mode)

View File

@@ -5,7 +5,7 @@
"This module requires (:tools lsp)")
(if (not (executable-find "python"))
(warn! "Python isn't installed.")
(error! "Couldn't find python in your PATH")
(unless (featurep! +lsp)
(unless (zerop (shell-command "python -c 'import setuptools'"))
(warn! "setuptools wasn't detected, which anaconda-mode requires"))))
@@ -20,6 +20,32 @@
(unless (executable-find "conda")
(warn! "Couldn't find conda in your PATH")))
(when (featurep! +poetry)
(if (not (executable-find "poetry"))
(warn! "Couldn't find poetry in your PATH")))
(when (featurep! +cython)
(unless (executable-find "cython")
(warn! "Couldn't find cython. cython-mode will not work.")))
(when (featurep! +ipython)
(unless (executable-find "ipython")
(warn! "Couldn't find ipython in your PATH")))
(unless (executable-find "pytest")
(warn! "Couldn't find pytest. Running tests through pytest will not work."))
(unless (executable-find "nosetests")
(warn! "Couldn't find nosetests. Running tests through nose will not work."))
(unless (executable-find "pipenv")
(warn! "Couldn't find pipenv. pipenv support will not work."))
(unless (executable-find "isort")
(warn! "Couldn't find isort. Import sorting will not work."))
(when (featurep! :editor format)
(unless (executable-find "pyflakes")
(warn! "Couldn't find pyflakes. Import management will not work."))
(unless (executable-find "black")
(warn! "Couldn't find black. Code formatting will not work.")))

View File

@@ -2,33 +2,39 @@
;;; lang/python/packages.el
;; Major modes
(package! pip-requirements)
(package! pip-requirements :pin "216cd1690f80cc965d4ae47b8753fc185f778ff6")
(when (featurep! +cython)
(package! cython-mode)
(when (featurep! :tools flycheck)
(package! flycheck-cython)))
(package! cython-mode :pin "12ab8bc0056a0e77ccc0756955eb1621fd3b35db")
(when (featurep! :checkers syntax)
(package! flycheck-cython :pin "ecc4454d35ab5317ab66a04406f36f0c1dbc0b76")))
;; LSP
(when (featurep! +lsp)
(package! lsp-python-ms))
(when (and (featurep! +lsp)
(not (featurep! :tools lsp +eglot)))
(package! lsp-python-ms :pin "db6f2636da1037bda06d5a2d992c4857ce3ad9b0"))
;; Programming environment
(package! anaconda-mode)
(package! anaconda-mode :pin "10299bd9ff38c4f0da1d892905d02ef828e7fdce")
(when (featurep! :completion company)
(package! company-anaconda))
(package! company-anaconda :pin "da1566db41a68809ef7f91ebf2de28118067c89b"))
;; Environment management
(package! pipenv)
(package! pyvenv)
(package! pipenv :pin "b730bb509e8b60af9f5ab1f1e6c3458d1d95d789")
(package! pyvenv :pin "861998b6d157ae73b829f02a5a6c8a9118310831")
(when (featurep! +pyenv)
(package! pyenv-mode))
(package! pyenv-mode :pin "d191037fe62ed8d4fee5888845da3e2c386d8e89"))
(when (featurep! +conda)
(package! conda))
(package! conda :pin "9d0213020ff170b17e11b35cad40ac9a8bf30f4c"))
(when (featurep! +poetry)
(package! poetry :pin "d876522e5af576d53c62b2838f85c9441fe62258"))
;; Testing frameworks
(package! nose)
(package! python-pytest)
(package! nose
;; REVIEW Remove this when emacsmirror/epkgs updates its emacsattic index
:recipe (:host github :repo "emacsattic/nose")
:pin "f8528297519eba911696c4e68fa88892de9a7b72")
(package! python-pytest :pin "09ad688df207ee9b02c990d3897a9e2841931d97")
;; Import managements
(package! pyimport)
(package! py-isort)
(package! pyimport :pin "a6f63cf7ed93f0c0f7c207e6595813966f8852b9")
(package! py-isort :pin "e67306f459c47c53a65604e4eea88a3914596560")