mirror of
https://github.com/doomemacs/doomemacs.git
synced 2025-12-06 02:30:33 -08:00
feat(python): add uv virtual environment support
This commit is contained in:
parent
ead254e152
commit
beed37ad83
5 changed files with 47 additions and 0 deletions
|
|
@ -30,6 +30,8 @@ This module adds [[https://www.python.org/][Python]] support to Doom Emacs.
|
||||||
support via [[https://python-poetry.org/][Poetry]].
|
support via [[https://python-poetry.org/][Poetry]].
|
||||||
- +pyenv ::
|
- +pyenv ::
|
||||||
Enable Python virtual environment support via [[https://github.com/pyenv/pyenv][pyenv]]
|
Enable Python virtual environment support via [[https://github.com/pyenv/pyenv][pyenv]]
|
||||||
|
- +uv ::
|
||||||
|
Enable Python virtual environment support via [[https://github.com/astral-sh/uv][uv]]
|
||||||
- +pyright ::
|
- +pyright ::
|
||||||
Add support for the pyright LSP server (requires [[doom-module:+lsp]]).
|
Add support for the pyright LSP server (requires [[doom-module:+lsp]]).
|
||||||
- +tree-sitter ::
|
- +tree-sitter ::
|
||||||
|
|
@ -44,6 +46,7 @@ This module adds [[https://www.python.org/][Python]] support to Doom Emacs.
|
||||||
- [[doom-package:pip-requirements]]
|
- [[doom-package:pip-requirements]]
|
||||||
- [[doom-package:poetry]] if [[doom-module:+poetry]]
|
- [[doom-package:poetry]] if [[doom-module:+poetry]]
|
||||||
- [[doom-package:pyenv]]
|
- [[doom-package:pyenv]]
|
||||||
|
- [[doom-package:uv-mode]] if [[doom-module:+uv]]
|
||||||
- [[doom-package:pyimport]]
|
- [[doom-package:pyimport]]
|
||||||
- [[doom-package:py-isort]]
|
- [[doom-package:py-isort]]
|
||||||
- [[doom-package:python-pytest]]
|
- [[doom-package:python-pytest]]
|
||||||
|
|
@ -74,6 +77,7 @@ This module has no hard requirements, but softly depends on:
|
||||||
- [[doom-package:py-isort]] requires [[https://github.com/timothycrosley/isort][isort]] to be installed: ~pip install isort~
|
- [[doom-package:py-isort]] requires [[https://github.com/timothycrosley/isort][isort]] to be installed: ~pip install isort~
|
||||||
- Python virtual environments install instructions at:
|
- Python virtual environments install instructions at:
|
||||||
- [[https://github.com/pyenv/pyenv][pyenv]]
|
- [[https://github.com/pyenv/pyenv][pyenv]]
|
||||||
|
- [[https://github.com/astral-sh/uv][uv]]
|
||||||
- [[https://conda.io/en/latest/][Conda]]
|
- [[https://conda.io/en/latest/][Conda]]
|
||||||
- [[https://python-poetry.org/][Poetry]]
|
- [[https://python-poetry.org/][Poetry]]
|
||||||
- [[https://pipenv.readthedocs.io/en/latest/][pipenv]]
|
- [[https://pipenv.readthedocs.io/en/latest/][pipenv]]
|
||||||
|
|
|
||||||
26
modules/lang/python/autoload/uv.el
Normal file
26
modules/lang/python/autoload/uv.el
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
;;; lang/python/autoload/uv.el -*- lexical-binding: t; -*-
|
||||||
|
;;;###if (modulep! +uv)
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(defvar +uv--project nil)
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(defun +python-uv-mode-set-auto-h ()
|
||||||
|
"Set uv-mode virtualenv from buffer-local variable."
|
||||||
|
(when (memq major-mode '(python-mode python-ts-mode))
|
||||||
|
(when (not (local-variable-p '+uv--project))
|
||||||
|
(make-local-variable '+uv--project)
|
||||||
|
(setq +uv--project (+python-uv-read-project-from-file)))
|
||||||
|
(if +uv--project
|
||||||
|
(uv-mode-set)
|
||||||
|
(uv-mode-unset))))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(defun +python-uv-read-project-from-file ()
|
||||||
|
"Read uv project root from .venv directory presence."
|
||||||
|
(when-let (root-path (projectile-locate-dominating-file default-directory ".venv"))
|
||||||
|
(let ((venv-path (expand-file-name ".venv" root-path)))
|
||||||
|
(if (file-directory-p venv-path)
|
||||||
|
root-path
|
||||||
|
(message "uv: .venv directory not found in `%s'." root-path)
|
||||||
|
nil))))
|
||||||
|
|
@ -216,6 +216,17 @@
|
||||||
(add-hook 'doom-switch-buffer-hook #'+python-pyenv-mode-set-auto-h))
|
(add-hook 'doom-switch-buffer-hook #'+python-pyenv-mode-set-auto-h))
|
||||||
|
|
||||||
|
|
||||||
|
(use-package! uv-mode
|
||||||
|
:when (modulep! +uv)
|
||||||
|
:after python
|
||||||
|
:config
|
||||||
|
(when (executable-find "uv")
|
||||||
|
(uv-mode +1))
|
||||||
|
(add-hook! '(python-mode-local-vars-hook python-ts-mode-local-vars-hook)
|
||||||
|
#'+python-uv-mode-set-auto-h)
|
||||||
|
(add-hook 'doom-switch-buffer-hook #'+python-uv-mode-set-auto-h))
|
||||||
|
|
||||||
|
|
||||||
(use-package! conda
|
(use-package! conda
|
||||||
:when (modulep! +conda)
|
:when (modulep! +conda)
|
||||||
:after python
|
:after python
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,10 @@
|
||||||
(unless (split-string (shell-command-to-string "pyenv versions --bare") "\n" t)
|
(unless (split-string (shell-command-to-string "pyenv versions --bare") "\n" t)
|
||||||
(warn! "No versions of python are available via pyenv, did you forget to install one?"))))
|
(warn! "No versions of python are available via pyenv, did you forget to install one?"))))
|
||||||
|
|
||||||
|
(when (modulep! +uv)
|
||||||
|
(unless (executable-find "uv")
|
||||||
|
(warn! "Couldn't find uv in your PATH")))
|
||||||
|
|
||||||
(when (modulep! +conda)
|
(when (modulep! +conda)
|
||||||
(unless (executable-find "conda")
|
(unless (executable-find "conda")
|
||||||
(warn! "Couldn't find conda in your PATH")))
|
(warn! "Couldn't find conda in your PATH")))
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,8 @@
|
||||||
(package! pyvenv :pin "31ea715f2164dd611e7fc77b26390ef3ca93509b")
|
(package! pyvenv :pin "31ea715f2164dd611e7fc77b26390ef3ca93509b")
|
||||||
(when (modulep! +pyenv)
|
(when (modulep! +pyenv)
|
||||||
(package! pyenv-mode :pin "364bddb8f0c8ec022796210d8d3625a520e984b0"))
|
(package! pyenv-mode :pin "364bddb8f0c8ec022796210d8d3625a520e984b0"))
|
||||||
|
(when (modulep! +uv)
|
||||||
|
(package! uv-mode :pin "7e7f9b90832210b65823c3d58e3255cd164394b7"))
|
||||||
(when (modulep! +conda)
|
(when (modulep! +conda)
|
||||||
(package! conda :pin "8a1a934a2de576d4158b1b12329be4f5be931a4a"))
|
(package! conda :pin "8a1a934a2de576d4158b1b12329be4f5be931a4a"))
|
||||||
(when (modulep! +poetry)
|
(when (modulep! +poetry)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue