2022-03-28 15:03:21 +02:00
#+title : :lang python
#+subtitle : Beautiful is better than ugly
#+created : June 15, 2015
#+since : 0.7
2021-10-16 01:28:32 +02:00
* Description :unfold:
This module adds [[https://www.python.org/ ][Python ]] support to Doom Emacs.
2022-09-26 02:19:42 +08:00
- Syntax checking ([[doom-package:flycheck ]])
2021-10-16 01:28:32 +02:00
- Snippets
2022-09-26 02:19:42 +08:00
- Run tests ([[doom-package:nose ]], [[doom-package:pytest ]])
- Auto-format (with ~black~ , requires [[doom-module::editor format ]])
2021-10-16 01:28:32 +02:00
- LSP integration (=mspyls= , =pyls= , or =pyright= )
** Maintainers
- [[doom-user: ][@hlissner ]]
[[doom-contrib-maintainer: ][Become a maintainer? ]]
** Module flags
- +conda ::
Enable python virtual environment support via [[https://conda.io/en/latest/ ][Conda ]].
- +cython ::
Enable support for Cython files support.
- +lsp ::
2022-09-26 02:19:42 +08:00
Enable LSP support for ~python-mode~ . Requires [[doom-module::tools lsp ]] and a langserver
2021-10-16 01:28:32 +02:00
(supports mspyls, pyls, and pyright).
- +poetry ::
Enable Python packaging, dependency management, and virtual environment
support via [[https://python-poetry.org/ ][Poetry ]].
- +pyenv ::
Enable Python virtual environment support via [[https://github.com/pyenv/pyenv ][pyenv ]]
- +pyright ::
2022-09-26 02:19:42 +08:00
Use the pyright LSP server instead of mspyls or pyls (requires [[doom-module:+lsp ]]).
2022-04-09 18:38:04 +03:00
- +tree-sitter ::
Leverages tree-sitter for better syntax highlighting and structural text
2022-09-26 02:19:42 +08:00
editing. Requires [[doom-module::tools tree-sitter ]].
2021-10-16 01:28:32 +02:00
** Packages
2022-09-26 02:19:42 +08:00
- [[doom-package:anaconda-mode ]]
- [[doom-package:conda ]]
- [[doom-package:nose ]]
- [[doom-package:pipenv ]]
- [[doom-package:pip-requirements ]]
- [[doom-package:poetry ]] if [[doom-module:+poetry ]]
- [[doom-package:pyenv ]]
- [[doom-package:pyimport ]]
- [[doom-package:py-isort ]]
- [[doom-package:python-pytest ]]
- if [[doom-module:+cython ]]
- [[doom-package:cython-mode ]]
- [[doom-package:flycheck-cython ]] if [[doom-module::checkers syntax ]]
- if [[doom-module:+lsp ]]
- if [[doom-module:+pyright ]]
- [[doom-package:lsp-pyright ]]
2021-10-16 01:28:32 +02:00
- else
2022-09-26 02:19:42 +08:00
- [[doom-package:lsp-python-ms ]]
2021-10-16 01:28:32 +02:00
** Hacks
2022-09-26 02:19:42 +08:00
- [[doom-package:anaconda-mode ]] is configured to activate when [[doom-package:lsp-mode ]] (or [[doom-package:eglot ]]) don't -- or
2021-10-16 01:28:32 +02:00
fail to.
** TODO Changelog
# This section will be machine generated. Don't edit it by hand.
/This module does not have a changelog yet./
* Installation
[[id:01cffea4-3329-45e2-a892-95a384ab2338 ][Enable this module in your ~doom!~ block. ]]
This module has no hard requirements, but softly depends on:
- For this module's supported test runners:
- ~$ pip install pytest~
- ~$ pip install nose~
2022-09-26 02:19:42 +08:00
- The [[doom-module::editor format ]] module uses Black for python files: ~$ pip install black~
- [[doom-package:pyimport ]] requires Python's module ~pyflakes~ : ~$ pip install pyflakes~
- [[doom-package:py-isort ]] requires [[https://github.com/timothycrosley/isort ][isort ]] to be installed: ~pip install isort~
2021-10-16 01:28:32 +02:00
- Python virtual environments install instructions at:
- [[https://github.com/pyenv/pyenv ][pyenv ]]
- [[https://conda.io/en/latest/ ][Conda ]]
- [[https://python-poetry.org/ ][Poetry ]]
- [[https://pipenv.readthedocs.io/en/latest/ ][pipenv ]]
- ~cython~ requires [[https://cython.org/ ][Cython ]]
2019-10-15 10:00:56 +02:00
2019-10-03 12:40:46 -04:00
** Language Server Protocol Support
2022-09-26 02:19:42 +08:00
For LSP support the [[doom-module::tools lsp ]] module must be enabled, along with this module's
[[doom-module:+lsp ]] flag. By default, it supports [[doom-package:mspyls ]] and [[doom-package:pyls ]], in that order. With the
[[doom-module:+pyright ]] flag, it will try Pyright first.
2020-05-09 01:13:04 -04:00
2023-07-22 18:12:19 +02:00
An alternative LSP server can be used by installing them through the
[[cmd: ][lsp-install-server ]] command, or an external package manager. For example:
- To install [[https://pypi.org/project/python-language-server/ ][*pyls* ]]: ~$ pip install python-language-server[all]~ .
- To install *mspyls* : ~M-x lsp-install-server RET mspyls~ .
- To install *pyright* : ~$ pip install pyright~ or ~$ npm i -g pyright~ .
2020-05-09 01:13:04 -04:00
2021-10-16 01:28:32 +02:00
* TODO Usage
#+begin_quote
🔨 /This module's usage documentation is incomplete./ [[doom-contrib-module: ][Complete it? ]]
#+end_quote
2020-07-25 10:15:00 -07:00
2021-10-16 01:28:32 +02:00
This module supports LSP. It requires installation of [[https://pypi.org/project/python-language-server/ ][Python Language 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
2022-09-26 02:19:42 +08:00
To enable support for auto-formatting with black enable [[doom-module::editor format ]].
2019-10-03 12:40:46 -04:00
** Keybindings
2021-10-16 01:28:32 +02:00
| Binding | Description |
|-------------------+----------------------------------|
| [[kbd:][<localleader> c c]] | ~Compile Cython buffer~ |
2023-07-22 18:12:19 +02:00
| [[kbd:][<localleader> i i]] | ~Insert missing imports~ |
2021-10-16 01:28:32 +02:00
| [[kbd:][<localleader> i r]] | ~Remove unused imports~ |
| [[kbd:][<localleader> i s]] | ~Sort imports~ |
| [[kbd:][<localleader> i o]] | ~Optimize imports~ |
| [[kbd:][<localleader> t r]] | ~nosetests-again~ |
| [[kbd:][<localleader> t a]] | ~nosetests-all~ |
| [[kbd:][<localleader> t s]] | ~nosetests-one~ |
| [[kbd:][<localleader> t v]] | ~nosetests-module~ |
| [[kbd:][<localleader> t A]] | ~nosetests-pdb-all~ |
| [[kbd:][<localleader> t O]] | ~nosetests-pdb-one~ |
| [[kbd:][<localleader> t V]] | ~nosetests-pdb-module~ |
| [[kbd:][<localleader> t f]] | ~python-pytest-file~ |
| [[kbd:][<localleader> t k]] | ~python-pytest-file-dwim~ |
| [[kbd:][<localleader> t t]] | ~python-pytest-function~ |
| [[kbd:][<localleader> t m]] | ~python-pytest-function-dwim~ |
| [[kbd:][<localleader> t r]] | ~python-pytest-repeat~ |
| [[kbd:][<localleader> t p]] | ~python-pytest-popup~ |
| [[kbd:][<localleader> g d]] | ~anaconda-mode-find-definitions~ |
| [[kbd:][<localleader> g h]] | ~anaconda-mode-show-doc~ |
| [[kbd:][<localleader> g a]] | ~anaconda-mode-find-assignments~ |
| [[kbd:][<localleader> g f]] | ~anaconda-mode-find-file~ |
| [[kbd:][<localleader> g u]] | ~anaconda-mode-find-references~ |
* TODO Configuration
#+begin_quote
🔨 /This module's configuration documentation is incomplete./ [[doom-contrib-module: ][Complete it? ]]
#+end_quote
2019-10-03 12:40:46 -04:00
2023-07-22 18:12:19 +02:00
The arguments passed to the [[https://ipython.org/ ][ipython ]] or [[https://jupyter.org/ ][jupyter ]] shells can be altered through
these two variables:
2021-10-16 01:28:32 +02:00
#+begin_src emacs-lisp
;; in $DOOMDIR/config.el
2019-10-03 12:40:46 -04:00
(setq +python-ipython-repl-args '("-i" "--simple-prompt" "--no-color-info"))
(setq +python-jupyter-repl-args '("--simple-prompt"))
2021-10-16 01:28:32 +02:00
#+end_src
* Troubleshooting
/There are no known problems with this module./ [[doom-report: ][Report one? ]]
* Frequently asked questions
/This module has no FAQs yet./ [[doom-suggest-faq: ][Ask one? ]]
* TODO Appendix
#+begin_quote
🔨 This module has no appendix yet. [[doom-contrib-module: ][Write one? ]]
#+end_quote