Use poetry to manage virtualenvs

This commit is contained in:
Ohad Livne 2025-06-04 22:45:14 +03:00
parent b4bf1d5c6d
commit fcb9cc02f9
Signed by: libohad-dev
GPG key ID: 34FDC68B51191A4D
5 changed files with 22 additions and 28 deletions

View file

@ -138,25 +138,15 @@
("C-c C-p" . flycheck-previous-error) ("C-c C-p" . flycheck-previous-error)
("C-c C-l" . flycheck-list-errors))) ("C-c C-l" . flycheck-list-errors)))
(use-package pyvenv) ; Requires poetry to be installed
(use-package poetry)
(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 () (defun load-python-env ()
"Set up the Python IDE in the current project" "Set up the Python IDE in the current project"
(interactive) (interactive)
(let ((venv-dir (find-venv))) (progn
(when venv-dir (poetry-venv-workon)
(progn (lsp)))
(pyvenv-activate venv-dir)
(lsp)))))
(defun symbols-at-point () (defun symbols-at-point ()
(let* ((lsp--document-symbols-request-async t) (let* ((lsp--document-symbols-request-async t)

View file

@ -21,7 +21,6 @@ network-manager \
pipx \ pipx \
postfix \ postfix \
pulseaudio-utils \ pulseaudio-utils \
python3-venv
sway \ sway \
swayidle \ swayidle \
swaylock \ swaylock \
@ -32,8 +31,12 @@ xournalpp \
" "
PIPX_PKGS="\ PIPX_PKGS="\
poetry \
yt-dlp \ yt-dlp \
" "
sudo DEBIAN_FRONTEND=noninteractive apt-get install --yes ${DEB_PKGS} sudo DEBIAN_FRONTEND=noninteractive apt-get install --yes ${DEB_PKGS}
pipx install ${PIPX_PKGS} for pkg in ${PIPX_PKGS};
do
pipx install "${pkg}"
done

11
.local/bin/init-venv Executable file
View file

@ -0,0 +1,11 @@
#! /usr/bin/sh
poetry add \
--group dev \
black \
isort \
'python-lsp-server[rope]' \
ruff-lsp
poetry add \
--group test \
coverage

View file

@ -1,11 +0,0 @@
#! /usr/bin/sh
python3 -m venv .venv
. .venv/bin/activate
pip install \
black \
coverage \
isort \
'python-lsp-server[rope]' \
ruff-lsp
pip install -e .

View file

@ -32,4 +32,5 @@ export QT_IM_MODULE="fcitx"
export XMODIFIERS="@im=fcitx" export XMODIFIERS="@im=fcitx"
export BORG_REPO="/media/backup/" export BORG_REPO="/media/backup/"
export BORG_PASSCOMMAND="cat ${HOME}/.keys/borg-passphrase.txt" export BORG_PASSCOMMAND="cat ${HOME}/.keys/borg-passphrase.txt"
export PYTHON_KEYRING_BACKEND="keyring.backends.null.Keyring"
. "$HOME/.cargo/env" . "$HOME/.cargo/env"