From ec62bcd3bacdd77114ab09a0c60e3d4c6227f61a Mon Sep 17 00:00:00 2001 From: Mattias Bengtsson Date: Thu, 21 Sep 2023 08:46:04 +0200 Subject: [PATCH] env: Python version lookup improvements (#666) * env/python: Avoid pipenv package dependency Since `pipenv-project-p` just boils down to a simple `locate-dominating-file` avoid depending on it for finding `pipenv` repositories. This helps users that uses `pipenv` but doesn't use https://github.com/pwalsh/pipenv.el See: https://github.com/pwalsh/pipenv.el/blob/master/pipenv.el#L367-L369 * env/python: Find python via direnv If pipenv and pyenv fails, try to find python via direnv. --- doom-modeline-env.el | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/doom-modeline-env.el b/doom-modeline-env.el index 7ab369fa..825f5465 100644 --- a/doom-modeline-env.el +++ b/doom-modeline-env.el @@ -202,14 +202,25 @@ PARSER should be a function for parsing COMMAND's output line-by-line, to ;;;###autoload (autoload 'doom-modeline-env-setup-python "doom-modeline-env") (doom-modeline-def-env python :hooks '(python-mode-hook python-ts-mode-hook) - :command (lambda () (cond ((and (fboundp 'pipenv-project-p) - (pipenv-project-p)) + :command (lambda () (cond ((and (executable-find "pipenv") + (locate-dominating-file default-directory "Pipfile")) (list "pipenv" "run" (or doom-modeline-env-python-executable python-shell-interpreter "python") "--version")) ((executable-find "pyenv") (list "pyenv" "version-name")) + ((and (executable-find "direnv") + (locate-dominating-file default-directory ".envrc")) + (list "bash" + "-c" + ;; Direnv unfortunately writes crao on stderr + ;; so we need to pipe that to /dev/null + (format "'direnv exec %s %s --version 2>/dev/null'" + default-directory + (or doom-modeline-env-python-executable + python-shell-interpreter + "python")))) ((list (or doom-modeline-env-python-executable python-shell-interpreter "python")