Since lsp-python-ms changed its priority from 1 to -1 in emacs-lsp/lsp-python-ms@396c25c, it is no longer the first choice when both is available.
138 lines
5.6 KiB
Org Mode
138 lines
5.6 KiB
Org Mode
#+TITLE: lang/python
|
|
#+DATE: Oct, 2019
|
|
#+SINCE: v2.0.9
|
|
#+STARTUP: inlineimages
|
|
|
|
* Table of Contents :TOC_3:noexport:
|
|
- [[#description][Description]]
|
|
- [[#module-flags][Module Flags]]
|
|
- [[#plugins][Plugins]]
|
|
- [[#prerequisites][Prerequisites]]
|
|
- [[#language-server-protocol-support][Language Server Protocol Support]]
|
|
- [[#features][Features]]
|
|
- [[#keybindings][Keybindings]]
|
|
- [[#configuration][Configuration]]
|
|
|
|
* Description
|
|
Adds Python support to Doom Emacs.
|
|
|
|
+ Syntax checking (~flycheck~)
|
|
+ Snippets
|
|
+ Run tests (~nose~, ~pytest~)
|
|
+ Auto-format (~black~), requires ~:editor format~
|
|
|
|
** Module Flags
|
|
+ ~+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
|
|
+ [[https://github.com/pythonic-emacs/anaconda-mode][anaconda-mode]]*
|
|
+ [[https://github.com/Wilfred/pyimport][pyimport]]*
|
|
+ [[https://github.com/paetzke/py-isort.el][py-isort]]*
|
|
+ [[https://melpa.org/#/nose][nose]]*
|
|
+ [[https://github.com/wbolster/emacs-python-pytest][python-pytest]]*
|
|
+ [[https://github.com/Wilfred/pip-requirements.el][pip-requirements]]*
|
|
+ [[https://github.com/pwalsh/pipenv.el][pipenv]]*
|
|
+ ~:editor format~
|
|
+ [[https://github.com/lassik/emacs-format-all-the-code][format-all]]*
|
|
+ ~+conda~
|
|
+ [[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]]
|
|
+ ~: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.
|
|
|
|
+ To run tests inside of Emacs:
|
|
+ ~pip install pytest~
|
|
+ ~pip install nose~
|
|
|
|
+ The ~:editor format~ module uses [[https://github.com/psf/black][Black]] for python files
|
|
+ ~pip install black~
|
|
|
|
+ ~pyimport~ requires Python's module ~pyflakes~:
|
|
+ ~pip install pyflakes~
|
|
|
|
+ ~py-isort~ requires [[https://github.com/timothycrosley/isort][isort]] to be installed:
|
|
+ ~pip install isort~
|
|
|
|
+ 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
|
|
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 use [[https://pypi.org/project/python-language-server/][Python Language Server]] (pyls)* install it with ~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
|
|
Server]] or [[https://github.com/Microsoft/python-language-server][Microsoft Language Server]], see [[Language Server Protocol Support][LSP Support]].
|
|
|
|
To enable support for auto-formatting with black enable ~:editor format-all~ in
|
|
~init.el~ file.
|
|
|
|
** Keybindings
|
|
|
|
| Binding | Description |
|
|
|---------------------+----------------------------------|
|
|
| ~<localleader> c c~ | ~Compile Cython buffer~ |
|
|
| ~<localleader> i i~ | ~Insert mising imports~ |
|
|
| ~<localleader> i r~ | ~Remove unused imports~ |
|
|
| ~<localleader> i s~ | ~Sort imports~ |
|
|
| ~<localleader> i o~ | ~Optimize imports~ |
|
|
| ~<localleader> t r~ | ~nosetests-again~ |
|
|
| ~<localleader> t a~ | ~nosetests-all~ |
|
|
| ~<localleader> t s~ | ~nosetests-one~ |
|
|
| ~<localleader> t v~ | ~nosetests-module~ |
|
|
| ~<localleader> t A~ | ~nosetests-pdb-all~ |
|
|
| ~<localleader> t O~ | ~nosetests-pdb-one~ |
|
|
| ~<localleader> t V~ | ~nosetests-pdb-module~ |
|
|
| ~<localleader> t f~ | ~python-pytest-file~ |
|
|
| ~<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~ |
|
|
| ~<localleader> t p~ | ~python-pytest-popup~ |
|
|
| ~<localleader> g d~ | ~anaconda-mode-find-definitions~ |
|
|
| ~<localleader> g h~ | ~anaconda-mode-show-doc~ |
|
|
| ~<localleader> g a~ | ~anaconda-mode-find-assignments~ |
|
|
| ~<localleader> g f~ | ~anaconda-mode-find-file~ |
|
|
| ~<localleader> g u~ | ~anaconda-mode-find-references~ |
|
|
|
|
* Configuration
|
|
This module has the following variables to set extra arguments to [[https://ipython.org/][ipython]] and
|
|
[[https://jupyter.org/][jupyter]] shells:
|
|
|
|
#+BEGIN_SRC elisp
|
|
;; ~/.doom.d/config.el
|
|
(setq +python-ipython-repl-args '("-i" "--simple-prompt" "--no-color-info"))
|
|
(setq +python-jupyter-repl-args '("--simple-prompt"))
|
|
#+END_SRC
|