Skip to content
Snippets Groups Projects
Commit dc9f328c authored by Liu Miao's avatar Liu Miao
Browse files

more complete python configurations

parent 35b549fe
No related branches found
No related tags found
No related merge requests found
;;; prog-python.el --- Configuration for python.
;;; Commentary:
;;; Code: ;;; Code:
(defvar python/pyvenv-modes nil)
(defun python/pyenv-executable-find (command) (defun python/pyvenv-set-local-virtualenv ()
"Find executable taking pyenv shims into account." "Set pyvenv virtualenv from \".venv\" by looking in parent directories."
()) (interactive)
(defun python/execute-file (args) (let ((root-path (locate-dominating-file default-directory ".venv")))
"Execute a python script in a shell." (when root-path
(interactive "P") (let ((file-path (expand-file-name ".venv" root-path)))
(let ((universal-argument t) (cond ((file-directory-p file-path)
(compile-command (format "%s %s"))))) (pyvenv-activate file-path)
(message "Activated local virtualenv"))
(t (message ".venv is not a directory")))))))
(use-package importmagic (use-package python
:defer t :defer t
:ensure t :ensure nil
:diminish importmagic-mode :after flycheck
:init :mode "\\.py\\'"
(add-hook 'python-mode-hook 'importmagic-mode)) :custom
(python-indent-offset 4)
(flycheck-python-pycompile-executable "python3")
:config
(setq python-shell-interpreter "python3"))
(use-package pipenv (use-package lsp-pyright
:defer t
:ensure t :ensure t
:init :hook (python-mode . (lambda () (require 'lsp-pyright)))
(add-hook 'python-mode-hook #'pyvenv-tracking-mode)) :init (when (executable-find "python3")
(setq lsp-pyright-python-executable-cmd "python3")))
(use-package yapfify (use-package yapfify
:ensure t :ensure t
:defer t :defer t
:hook (python-mode . yapf-mode)) :hook (python-mode . yapf-mode))
(use-package python (use-package pyvenv
:defer t) :ensure t
:init
(add-hook 'python-mode-hook #'pyvenv-tracking-mode)
(add-to-list 'python/pyvenv-modes 'python-mode)
;; Set for auto active virtual env
(dolist (m python/pyvenv-modes)
(add-hook (intern (format "%s-hook" m))
'python/pyvenv-set-local-virtualenv())))
(provide 'prog-python) (provide 'prog-python)
;;; prog-python.el ends here ;;; prog-python.el ends here
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment