You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
2.4 KiB
78 lines
2.4 KiB
;;; python-mode-settings.el --- Defines mode settings for python. |
|
;;; |
|
;;; Commentary: |
|
;;; |
|
;;; |
|
;;; - For each project you will need to install flake8/autopep8 into the virtualenv |
|
;;; - For each project you will need to install jedi into the virtualenv |
|
;;; - To set your pyenv use M-x pyenv-mode and select your local virtualenv |
|
;; thx rakan.me |
|
(defun pyenv-activate-current-project () |
|
"Automatically activates pyenv version if .python-version file exists." |
|
(interactive) |
|
(f-traverse-upwards |
|
(lambda (path) |
|
(message path) |
|
(let ((pyenv-version-path (f-expand ".python-version" path))) |
|
(if (f-exists? pyenv-version-path) |
|
(let ((pyenv-current-version (s-trim (f-read-text pyenv-version-path 'utf-8)))) |
|
(pyenv-mode-set pyenv-current-version) |
|
(message (concat "Setting virtualenv to " pyenv-current-version)))))))) |
|
|
|
;; Right now this will require M-x jedi:install-server |
|
;; to use it in a project. |
|
;; TODO: Do the server installation automatically. |
|
(use-package jedi |
|
:ensure t |
|
:hook (python-mode . jedi:setup) |
|
:init |
|
(setq jedi:complete-on-dot t)) |
|
|
|
(use-package company-jedi |
|
:ensure t |
|
:requires jedi |
|
:hook (python-mode . company-jedi)) |
|
|
|
;; For Python enable Elpy. |
|
(use-package elpy |
|
:ensure t |
|
:requires jedi |
|
:init |
|
(elpy-enable) |
|
(setq elpy-rpc-backend "jedi")) |
|
|
|
|
|
;; Enable pyenv integration. |
|
(if (executable-find "pyenv") |
|
(use-package pyenv-mode |
|
:ensure t |
|
:config |
|
(pyenv-mode))) |
|
;; Disable elpy default virtualenv (use the pyenv one) |
|
(setq elpy-rpc-virtualenv-path 'current) |
|
|
|
;; Enable autopep8 |
|
(use-package py-autopep8 |
|
:ensure t) |
|
|
|
(add-hook 'elpy-mode-hook 'py-autopep8-enable-on-save) |
|
;; Enable flake8 - requires flake8 in your path so use pyenv/global pip install |
|
(add-hook 'python-mode-hook '(lambda () |
|
(setq flycheck-python-flake8-executable "flake8") |
|
(flycheck-select-checker 'python-flake8) |
|
(flycheck-mode t))) |
|
;; Activate pyenv automatically if a .python-version is supplied |
|
(if (executable-find "pyenv") |
|
(add-hook 'python-mode-hook 'pyenv-activate-current-project)) |
|
|
|
;; Use microsoft's python language server |
|
(add-hook 'python-mode-hook (lambda () (lsp-python-enable))) |
|
(use-package lsp-python-ms |
|
:ensure t |
|
:init (setq lsp-python-ms-auto-install-server t) |
|
:hook (python-mode . (lambda () |
|
(require 'lsp-python-ms) |
|
(lsp)))) ; or lsp-deferred |
|
;; Python testing helpers |
|
(use-package python-pytest |
|
:ensure t)
|
|
|