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-p" . flymake-goto-prev-error)
|
||||||
("C-c C-l" . flymake-show-diagnostics-buffer)))
|
("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
|
(use-package python
|
||||||
:bind (:map python-mode-map
|
:bind (:map python-mode-map
|
||||||
("C-c C-p" . nil)
|
("C-c C-p" . nil)
|
||||||
("C-c C-l" . nil))
|
("C-c C-l" . nil))
|
||||||
:hook ((python-mode . lsp)))
|
:hook ((python-mode . load-python-env)))
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,7 @@ htop \
|
||||||
ibus-mozc \
|
ibus-mozc \
|
||||||
keepassxc \
|
keepassxc \
|
||||||
mpv \
|
mpv \
|
||||||
python3-flake8 \
|
python3-venv
|
||||||
python3-pylsp \
|
|
||||||
sway \
|
sway \
|
||||||
swayidle \
|
swayidle \
|
||||||
swaylock \
|
swaylock \
|
||||||
|
|
|
||||||
6
.local/bin/make-venv
Executable file
6
.local/bin/make-venv
Executable file
|
|
@ -0,0 +1,6 @@
|
||||||
|
#! /usr/bin/sh
|
||||||
|
|
||||||
|
python3 -m venv .venv
|
||||||
|
. .venv/bin/activate
|
||||||
|
pip install 'python-lsp-server[all]'
|
||||||
|
pip install -e .
|
||||||
Loading…
Add table
Add a link
Reference in a new issue