2019-10-03 12:40:46 -04:00
#+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~
2020-08-07 19:04:41 -04:00
+ LSP integration (mspyls, pyls, or pyright)
2019-10-03 12:40:46 -04:00
** Module Flags
+ ~+lsp~ Language Server Protocol support
2020-08-07 19:04:41 -04:00
+ ~+pyright~ Use the pyright LSP server instead of mspyls or pyls (requires
~+lsp~ ).
2019-10-03 12:40:46 -04:00
+ ~+pyenv~ Python virtual environment support via [[https://github.com/pyenv/pyenv ][pyenv ]]
+ ~+conda~ Python virtual environment support via [[https://conda.io/en/latest/ ][Conda ]]
2020-04-22 20:48:00 +03:00
+ ~+poetry~ Python packaging, dependency management, and virtual environment
support via [[https://python-poetry.org/ ][Poetry ]]
2020-08-07 19:04:41 -04:00
+ ~+cython~ Cython files support via [[https://github.com/cython/cython/blob/master/Tools/cython-mode.el ][cython-mode ]]
2019-10-03 12:40:46 -04:00
** Plugins
+ [[https://github.com/pythonic-emacs/anaconda-mode ][anaconda-mode ]]*
+ [[https://github.com/Wilfred/pyimport ][pyimport ]]*
2019-12-11 12:00:29 +01:00
+ [[https://github.com/paetzke/py-isort.el ][py-isort ]]*
2020-12-12 01:01:45 -05:00
+ [[https://github.com/emacsattic/nose/ ][nose ]]*
2019-10-03 12:40:46 -04:00
+ [[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 ]]*
2020-08-07 19:04:41 -04:00
+ if ~+conda~
2019-10-03 12:40:46 -04:00
+ [[https://github.com/necaris/conda.el ][conda ]]*
2020-08-07 19:04:41 -04:00
+ if ~+pyenv~
2019-10-03 12:40:46 -04:00
+ [[https://github.com/pythonic-emacs/pyenv-mode ][pyenv ]]*
2020-08-07 19:04:41 -04:00
+ if ~+poetry~
2020-04-22 20:48:00 +03:00
+ [[https://github.com/galaunay/poetry.el ][poetry ]]*
2020-08-07 19:04:41 -04:00
+ if ~+lsp~ and ~:tools lsp~
2019-10-03 12:40:46 -04:00
+ [[https://github.com/emacs-lsp/lsp-mode ][lsp ]]
2020-08-07 19:04:41 -04:00
+ if ~+pyright~
+ [[https://github.com/emacs-lsp/lsp-pyright ][lsp-pyright ]]
+ else
+ [[https://github.com/emacs-lsp/lsp-python-ms ][lsp-python-ms ]]
+ if ~+cython~
+ [[https://github.com/cython/cython/blob/master/Tools/cython-mode.el ][cython-mode ]]
+ if ~:checkers syntax~ : [[https://github.com/lbolla/emacs-flycheck-cython/tree/master ][flycheck-cython ]]
2019-10-03 12:40:46 -04:00
* Prerequisites
2020-08-07 19:04:41 -04:00
This module has no hard prerequisites, but a few soft ones:
2019-10-03 12:40:46 -04:00
2020-08-07 19:04:41 -04:00
+ For this module's supported test runners:
2019-10-03 12:40:46 -04:00
+ ~pip install pytest~
+ ~pip install nose~
2020-08-07 19:04:41 -04:00
+ 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~
2019-10-03 12:40:46 -04:00
+ Python virtual environments install instructions at:
+ [[https://github.com/pyenv/pyenv ][pyenv ]]
+ [[https://conda.io/en/latest/ ][Conda ]]
2020-04-22 20:48:00 +03:00
+ [[https://python-poetry.org/ ][Poetry ]]
2020-08-07 19:04:41 -04:00
+ [[https://pipenv.readthedocs.io/en/latest/ ][pipenv ]]
2019-10-15 10:00:56 +02:00
+ ~cython~ requires [[https://cython.org/ ][Cython ]]
2019-10-03 12:40:46 -04:00
** Language Server Protocol Support
2020-08-07 19:04:41 -04:00
For LSP support the =:tools lsp= module must be enabled, along with this
module's =+lsp= flag. By default, it supports =mspyls= and =pyls= , in that
order. With the =+pyright= flag, it will try Pyright first.
2020-05-09 01:13:04 -04:00
2020-08-07 19:04:41 -04:00
Each of these servers must be installed on your system via your OS package
manager or manually:
2020-05-09 01:13:04 -04:00
2020-08-07 19:04:41 -04:00
+ [[https://pypi.org/project/python-language-server/ ][*pyls* ]] can be installed with ~pip install python-language-server[all]~ .
+ *mspyls* can be installed by typing =M-x lsp-install-server RET mspyls= .
+ *pyright* can be installed with ~pip install pyright~ or ~npm i -g pyright~ .
2020-07-25 10:15:00 -07:00
2019-10-03 12:40:46 -04:00
* Features
This module supports LSP. It requires installation of [[https://pypi.org/project/python-language-server/ ][Python Language
2020-07-25 10:15:00 -07:00
Server]], [[https://github.com/Microsoft/python-language-server ][Microsoft Language Server ]], or [[https://github.com/microsoft/pyright ][pyright ]], see [[Language Server Protocol Support ][LSP Support ]].
2019-10-03 12:40:46 -04:00
2020-08-07 19:04:41 -04:00
To enable support for auto-formatting with black enable ~:editor format~ in
2019-10-03 12:40:46 -04:00
~init.el~ file.
** Keybindings
| Binding | Description |
|---------------------+----------------------------------|
2019-10-15 10:00:56 +02:00
| ~<localleader> c c~ | ~Compile Cython buffer~ |
2019-10-03 12:40:46 -04:00
| ~<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~ |
2020-03-20 23:37:57 +01:00
| ~<localleader> t k~ | ~python-pytest-file-dwim~ |
2019-10-03 12:40:46 -04:00
| ~<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~ |
2019-11-21 12:48:50 -05:00
| ~<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~ |
2019-10-03 12:40:46 -04:00
* 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