Use the project virtualenv for the Python IDE
This commit is contained in:
parent
46cdf13182
commit
2a90ef5c0d
3 changed files with 29 additions and 3 deletions
|
|
@ -126,8 +126,29 @@
|
|||
("C-c C-p" . flymake-goto-prev-error)
|
||||
("C-c C-l" . flymake-show-diagnostics-buffer)))
|
||||
|
||||
(use-package pyvenv)
|
||||
|
||||
(defun find-venv ()
|
||||
"Try to find a .venv/ directory in the current project"
|
||||
(require 'f)
|
||||
(let ((basedir (f-traverse-upwards
|
||||
(lambda (path)
|
||||
(let ((venv-path (f-expand ".venv" path)))
|
||||
(f-exists? venv-path))))))
|
||||
(when basedir (f-expand ".venv" basedir))))
|
||||
|
||||
(defun load-python-env ()
|
||||
"Set up the Python IDE in the current project"
|
||||
(interactive)
|
||||
(let ((venv-dir (find-venv)))
|
||||
(if venv-dir
|
||||
(progn
|
||||
(pyvenv-activate venv-dir)
|
||||
(lsp))
|
||||
(pyvenv-deactivate))))
|
||||
|
||||
(use-package python
|
||||
:bind (:map python-mode-map
|
||||
("C-c C-p" . nil)
|
||||
("C-c C-l" . nil))
|
||||
:hook ((python-mode . lsp)))
|
||||
:hook ((python-mode . load-python-env)))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue