This commit is contained in:
Damian Barabonkov 2025-12-02 22:05:13 +00:00 committed by GitHub
commit 4b9d50cc05
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 54 additions and 2 deletions

View file

@ -29,7 +29,11 @@ This module adds [[https://www.python.org/][Python]] support to Doom Emacs.
Enable Python packaging, dependency management, and virtual environment Enable Python packaging, dependency management, and virtual environment
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]]. Cannot be used together
with [[doom-module:+uv]].
- +uv ::
Enable Python virtual environment support via [[https://github.com/astral-sh/uv][uv]]. Cannot be used together
with [[doom-module:+pyenv]].
- +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 +48,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 +79,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]]

View 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))))

View file

@ -89,7 +89,7 @@
(setq-local flycheck-python-pylint-executable "pylint") (setq-local flycheck-python-pylint-executable "pylint")
(setq-local flycheck-python-flake8-executable "flake8")))) (setq-local flycheck-python-flake8-executable "flake8"))))
;; Affects pyenv and conda ;; Affects pyenv, uv and conda
(when (modulep! :ui modeline) (when (modulep! :ui modeline)
(advice-add #'pythonic-activate :after-while #'+modeline-update-env-in-all-windows-h) (advice-add #'pythonic-activate :after-while #'+modeline-update-env-in-all-windows-h)
(advice-add #'pythonic-deactivate :after #'+modeline-clear-env-in-all-windows-h)) (advice-add #'pythonic-deactivate :after #'+modeline-clear-env-in-all-windows-h))
@ -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

View file

@ -12,6 +12,9 @@
(fboundp 'python-ts-mode)) (fboundp 'python-ts-mode))
"Can't find `python-ts-mode'; Emacs 29.1+ is required") "Can't find `python-ts-mode'; Emacs 29.1+ is required")
(assert! (not (and (modulep! +pyenv) (modulep! +uv)))
"The +pyenv and +uv flags cannot be used together")
(if (not (or (executable-find "python") (if (not (or (executable-find "python")
(executable-find "python3"))) (executable-find "python3")))
(error! "Couldn't find python in your PATH") (error! "Couldn't find python in your PATH")
@ -26,6 +29,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")))

View file

@ -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)