doomemacs/modules/lang/python
Henrik Lissner dafa4deef4
lang/python: autoload lsp-python-ms setup/update commands
And set lsp-python-ms-python-executable-cmd a little sooner, to make it
easier for folks to change.
2019-12-28 13:52:15 -05:00
..
autoload Update optimize import to use py-isort 2019-12-15 16:50:31 +01:00
config.el lang/python: autoload lsp-python-ms setup/update commands 2019-12-28 13:52:15 -05:00
doctor.el Add :tools lsp checks for +lsp flag 2019-04-24 18:16:05 -04:00
packages.el Make isort default python import sorting package 2019-12-15 16:50:30 +01:00
README.org Add an entry in the readme for the isort prequisite 2019-12-15 16:50:31 +01:00

lang/python

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 pyenv
  • +conda Python virtual environment support via Conda
  • +cython Cython files support via Cython-mode

Plugins

Hacks

  • As per our "your system your rules" mantra, lsp-python-ms has been modified to not automatically install its server if it cannot find it. Install it with M-x lsp-python-ms-setup.

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 Black for python files

    • pip install black
  • pyimport requires Python's module pyflakes:

    • pip install pyflakes
  • py-isort requires isort to be installed:

    • pip install isort
  • Python virtual environments install instructions at:

  • pipenv requires pipenv
  • cython requires Cython

Language Server Protocol Support

Requires the +lsp flag and :tools lsp module to be enabled. By default LSP will use Microsoft's language server if installed.

To install the language server: M-x lsp-python-ms-setup To update the server: M-x lsp-python-ms-update-server

Alternatively you can use the Python Language Server instead. pip install 'python-language-server[all]'

Features

This module supports LSP. It requires installation of Python Language Server or Microsoft Language Server, see 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-dwin
<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 ipython and jupyter shells:

;; ~/.doom.d/config.el
(setq +python-ipython-repl-args '("-i" "--simple-prompt" "--no-color-info"))
(setq +python-jupyter-repl-args '("--simple-prompt"))