doomemacs/modules/lang/python
Henrik Lissner 037b018cdd
feat: add .doommodule files
These optional dotfiles indicate the root of a module or module
group (:lang), and will later contain module metadata. They will also
serve as an alternative to packages.el and doctor.el, and will aide the
parts of the v3.0 module API concerned with resolving the current module
from a path (`doom-module-from-path`), which currently rely too heavily
on parsing path strings.

For now, however, they're simply placeholders.
2024-09-14 20:47:39 -04:00
..
autoload fix(python): repl: respect python-shell-dedicated 2023-02-23 00:34:37 -05:00
.doommodule feat: add .doommodule files 2024-09-14 20:47:39 -04:00
config.el refactor(lsp): let lsp-mode load lsp client packages 2024-09-09 17:24:45 -04:00
doctor.el refactor: deprecate featurep! for modulep! 2022-08-14 20:43:35 +02:00
packages.el bump: :lang python 2024-09-05 15:30:22 -04:00
README.org bump: :lang python 2024-09-05 15:30:22 -04:00

:lang python

Description   unfold

This module adds Python support to Doom Emacs.

Module flags

+conda
Enable python virtual environment support via Conda.
+cython
Enable support for Cython files support.
+lsp
Enable LSP support for python-mode. Requires doom-module::tools lsp and a langserver (pyls, jedi, ruff, or pyright).
+poetry
Enable Python packaging, dependency management, and virtual environment support via Poetry.
+pyenv
Enable Python virtual environment support via pyenv
+pyright
Add support for the pyright LSP server (requires doom-module:+lsp).
+tree-sitter
Leverages tree-sitter for better syntax highlighting and structural text editing. Requires doom-module::tools tree-sitter.

Hacks

TODO Changelog

This module does not have a changelog yet.

Installation

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
  • 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 isort to be installed: pip install isort
  • Python virtual environments install instructions at:

  • cython requires Cython

Language Server Protocol Support

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.

An alternative LSP server can be used by installing them through the lsp-install-server command, or an external package manager. For example:

  • To install basedpyright: $ pip install basedpyright
  • To install pyright: $ pip install pyright or $ npm i -g pyright.
  • To install pyls: $ pip install python-language-server[all].
  • To install mspyls: M-x lsp-install-server RET mspyls.

Formatter

Formatting is handled using the doom-module::editor format module via black.

TODO Usage

󱌣 This module's usage documentation is incomplete. Complete it?

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 doom-module::editor format.

Keybindings

Binding Description
<localleader> c c Compile Cython buffer
<localleader> i i Insert missing 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

TODO Configuration

󱌣 This module's configuration documentation is incomplete. Complete it?

The arguments passed to the ipython or jupyter shells can be altered through these two variables:

;; in $DOOMDIR/config.el
(setq +python-ipython-repl-args '("-i" "--simple-prompt" "--no-color-info"))
(setq +python-jupyter-repl-args '("--simple-prompt"))

Troubleshooting

There are no known problems with this module. Report one?

Frequently asked questions

This module has no FAQs yet. Ask one?

TODO Appendix

󱌣 This module has no appendix yet. Write one?