init.el
;;; PYTHON IDE FEATURES
;;; EGLOT SETUP
;; using eglot for lsp (use-package eglot :ensure t :defer t :hook (python-mode . eglot-ensure))
;; using emacs-pet to find correct python executable in venv and so on (use-package pet :ensure t :config (add-hook 'python-base-mode-hook 'pet-mode -10))
;; to set up python-mode to use the correct interpreter when you execute M-x run-python (add-hook 'python-mode-hook (lambda () (setq-local python-shell-interpreter (pet-executable-find "python") python-shell-virtualenv-root (pet-virtualenv-root))))
;; to help you setup the flake8, pylint and mypy checkers (add-hook 'python-mode-hook 'pet-flycheck-setup)
This venv must be somewhere visible to emacs-pet
.
python3 -m venv python-venv . python-venv/bin/activate command -V python3 python3 -m pip install python-lsp-server
;;; Directory Local Variables -*- no-byte-compile: t -*- ;;; For more information see (info "(emacs) Directory Variables")
((python-mode . ((eglot-workspace-configuration . ((pylsp (plugins (mccabe (enabled . nil)) (pycodestyle (enabled . nil)) (flake8 (enabled . t)) (pylint (enabled . nil)) (mypy (enabled . t)) (isort (enabled . t)))) (pyls (plugins (mccabe (enabled . nil)) (pylint (enabled . nil)) (pycodestyle (enabled . nil)) (flake8 (enabled . t)) (mypy (enabled . t)) (isort (enabled . t)))))))))
Configure flake8 as you want:
[flake8] max-line-length = 120 exclude = venv, .venv extend-ignore = E501,D100