:lang python
Beautiful is better than ugly
1. Description
Adds Python support to Doom Emacs.
- Syntax checking (
flycheck) - Snippets
- Run tests (
nose,pytest) - Auto-format (
black), requires:editor format - LSP integration (mspyls, pyls, or pyright)
1.1. Maintainers
This module has no dedicated maintainers. Become a maintainer?
1.2. Module flags
- +conda
- Python virtual environment support via Conda.
- +cython
- Cython files support via cython-mode.
- +lsp
- Enable LSP support for
python-mode. Requires :tools lsp and a langserver (supports pyls, mspyls, and pyright). - +poetry
- Python packaging, dependency management, and virtual environment support via Poetry.
- +pyenv
- Python virtual environment support via pyenv.
- +pyright
- Use the pyright LSP server instead of mspyls or pyls. Requires +lsp.
1.3. Packages
- anaconda-mode
- conda if +conda
- nose
- pipenv
- pip-requirements
- poetry if +poetry
- pyenv if +pyenv
- pyimport
- py-isort
- python-pytest
- if +cython
- if +lsp and :tools lsp
- if +pyright
- else
1.4. Hacks
No hacks documented for this module.
2. Prerequisites
This module has no hard prerequisites, but a few soft ones:
- For this module’s supported test runners:
pip install pytestpip install nose
- The :editor format module uses Black for python files:
$ pip install black pyimportrequires Python’s modulepyflakes:$ pip install pyflakespy-isortrequires isort to be installed:$ pip install isort- Python virtual environments install instructions at:
cythonrequires Cython
2.1. Language Server Protocol Support
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.
Each of these servers must be installed on your system via your OS package manager or manually:
- Install pyls with
$ pip install python-language-server[all]. - Install mspyls with
M-x lsp-install-server RET mspyls. - Install pyright with
$ pip install pyrightor$ npm i -g pyright.
3. Usage
This module supports LSP. It requires installation of Python Language Server, Microsoft Language Server, or pyright, see LSP Support.
To enable support for auto-formatting with black enable :editor format in init.el file.
3.1. 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 |
4. Configuration
5. Troubleshooting
There are no known problems with this module. Report one?
6. TODO Appendix
This module has no appendix yet. Write one?