diff --git a/.config/emacs/init.el b/.config/emacs/init.el index 1a3c1fc..ccddb58 100644 --- a/.config/emacs/init.el +++ b/.config/emacs/init.el @@ -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))) diff --git a/.config/setup/01-install-packages.sh b/.config/setup/01-install-packages.sh index f194340..440cdbf 100755 --- a/.config/setup/01-install-packages.sh +++ b/.config/setup/01-install-packages.sh @@ -9,8 +9,7 @@ htop \ ibus-mozc \ keepassxc \ mpv \ -python3-flake8 \ -python3-pylsp \ +python3-venv sway \ swayidle \ swaylock \ diff --git a/.local/bin/make-venv b/.local/bin/make-venv new file mode 100755 index 0000000..802f75f --- /dev/null +++ b/.local/bin/make-venv @@ -0,0 +1,6 @@ +#! /usr/bin/sh + +python3 -m venv .venv +. .venv/bin/activate +pip install 'python-lsp-server[all]' +pip install -e .