lang/python: use correct executables for flycheck

This commit is contained in:
Henrik Lissner 2019-07-22 00:37:34 +02:00
parent a124c1b993
commit 77da28f06a
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -43,6 +43,24 @@ called.")
(when (featurep! +lsp)
(add-hook 'python-mode-local-vars-hook #'lsp!))
(add-hook 'python-mode-hook
(defun +python-use-correct-flycheck-executables-h ()
"Use the correct Python executables for Flycheck."
(let ((executable python-shell-interpreter))
(save-excursion
(save-match-data
(when (or (looking-at "#!/usr/bin/env \\(python[^ \n]+\\)")
(looking-at "#!\\([^ \n]+/python[^ \n]+\\)"))
(setq executable (substring-no-properties (match-string 1))))))
;; Try to compile using the appropriate version of Python for
;; the file.
(setq-local flycheck-python-pycompile-executable executable)
;; We might be running inside a virtualenv, in which case the
;; modules won't be available. But calling the executables
;; directly will work.
(setq-local flycheck-python-pylint-executable "pylint")
(setq-local flycheck-python-flake8-executable "flake8"))))
(define-key python-mode-map (kbd "DEL") nil) ; interferes with smartparens
(sp-local-pair 'python-mode "'" nil
:unless '(sp-point-before-word-p