-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path+python.el
More file actions
39 lines (32 loc) · 1.56 KB
/
+python.el
File metadata and controls
39 lines (32 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
;;; +python.el -*- lexical-binding: t; -*-
(after! python
(set-eglot-client! '(python-mode python-ts-mode) '("ty" "server")))
(defun uv-activate ()
"Activate Python environment managed by uv based on current project directory.
Looks for .venv directory in project root and activates the Python interpreter."
(interactive)
(let* ((project-root (project-root (project-current t)))
(venv-path (expand-file-name ".venv" project-root))
(python-path (expand-file-name
(if (eq system-type 'windows-nt)
"Scripts/python.exe"
"bin/python")
venv-path)))
(if (file-exists-p python-path)
(progn
;; Set Python interpreter path
(setq python-shell-interpreter python-path)
;; Update exec-path to include the venv's bin directory
(let ((venv-bin-dir (file-name-directory python-path)))
(setq exec-path (cons venv-bin-dir
(remove venv-bin-dir exec-path))))
;; Update PATH environment variable
(setenv "PATH" (concat (file-name-directory python-path)
path-separator
(getenv "PATH")))
;; Update VIRTUAL_ENV environment variable
(setenv "VIRTUAL_ENV" venv-path)
;; Remove PYTHONHOME if it exists
(setenv "PYTHONHOME" nil)
(message "Activated UV Python environment at %s" venv-path))
(error "No UV Python environment found in %s" project-root))))