dotfiles/emacs/.emacs.d/config/init-python.el

56 lines
1.8 KiB
EmacsLisp
Raw Normal View History

;; -*- lexical-binding: t; -*-
;; Python configuration
(use-package python
:defer t
:straight (:type built-in)
:config
2021-02-21 03:03:33 +00:00
(add-hook 'python-mode-hook #'highlight-indent-guides-mode)
;; Redefine the python-mypy flycheck checker to account for projectile-compilation-dir
(flycheck-define-checker python-mypy
"Mypy syntax and type checker. Requires mypy>=0.580.
See URL `http://mypy-lang.org/'."
:command ("mypy"
"--show-column-numbers"
(config-file "--config-file" flycheck-python-mypy-config)
(option "--cache-dir" flycheck-python-mypy-cache-dir)
source-original)
:error-patterns
((error line-start (file-name) ":" line (optional ":" column)
": error:" (message) line-end)
(warning line-start (file-name) ":" line (optional ":" column)
": warning:" (message) line-end)
(info line-start (file-name) ":" line (optional ":" column)
": note:" (message) line-end))
:modes python-mode
;; Ensure the file is saved, to work around
;; https://github.com/python/mypy/issues/4746.
:predicate flycheck-buffer-saved-p
:working-directory (lambda (checker)
(or (projectile-compilation-dir)
default-directory))))
;; pyvenv to track virtual environments
(use-package pyvenv
:defer 3
:config
(pyvenv-mode)
(pyvenv-tracking-mode))
;; pyenv to track Python version
(use-package pyenv-mode
:defer t)
;; LSP using Microsoft's pyright language server
(use-package lsp-pyright
:hook (python-mode . (lambda ()
(require 'lsp-pyright)
(lsp-deferred)))
:custom
(lsp-pyright-use-library-code-for-types t)
:general
(python-mode-map "C-c C-d" #'lsp-describe-thing-at-point))
(provide 'init-python)