Setting pylsp.plugins.jedi.environment dynamically in workspace function failing #1030
-
Hey all! I'm migrating my configuration over from I have many Python projects I work on, almost all of which use Poetry for managing dependencies. Poetry maintains its own virtual environments transparently to the user, but you can get the location via the command (defun locate-venv (dir)
"Find a poetry venv."
;;poetry env info -p
(let ((stdout-buffer (generate-new-buffer "tmp-poetry-stdout"))
(default-directory dir))
(unwind-protect
(let
((exit-status
(condition-case
nil
(call-process "poetry" nil (list stdout-buffer nil) nil "env" "info" "-p")
(file-missing nil))))
(if (eq exit-status 0)
(progn
(with-current-buffer stdout-buffer
(string-trim (buffer-string))))))
(kill-buffer stdout-buffer))))
(setq-default eglot-workspace-configuration
(lambda (&rest args)
(let ((venv-directory (locate-venv default-directory)))
(message "Located venv: %s" venv-directory)
'((:pylsp .
(:plugins
(:jedi_completion (:fuzzy t))
(:jedi (:environment venv-directory))
(:pydocstyle (:enabled nil))
(:pycodestyle (:enabled nil))
(:mccabe (:enabled nil))
(:pyflakes (:enabled nil))
(:flake8 (:enabled t))
(:black (:enabled t)))))))) The error I'm seeing is as follows:
I did see a similar question asked for configuring pyright in #967 but I lack the fluency in elisp to fully understand and translate that over to my setup. Is there something obvious I'm missing? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 3 replies
-
Indeed this seems to be mostly down to Elisp problems. Try this
And avoid setting |
Beta Was this translation helpful? Give feedback.
-
Solved by @joaotavora in the comments section here! #1030 (reply in thread) I'm reposting the solution here so that Github will show it as the top accepted answer. (setq-default eglot-workspace-configuration
(lambda (&rest args)
(let ((venv-directory (locate-venv default-directory)))
(message "Located venv: %s" venv-directory)
`((:pylsp .
(:plugins
(:jedi_completion (:fuzzy t)
:jedi (:environment ,venv-directory)
:pydocstyle (:enabled nil)
:pycodestyle (:enabled nil)
:mccabe (:enabled nil)
:pyflakes (:enabled nil)
:flake8 (:enabled t)
:black (:enabled t)))))))) |
Beta Was this translation helpful? Give feedback.
-
Thanks a lot for this thread. I finally got pylsp to guess my poetry env correctly! |
Beta Was this translation helpful? Give feedback.
-
Wooop! it took me waaaay to long to accomplish this, I should have just googled sooner but I was being stubborn. Regarding the directory-local nature of configs... In my case I'm doing the same as OP except using the If I create a |
Beta Was this translation helpful? Give feedback.
Solved by @joaotavora in the comments section here! #1030 (reply in thread)
I'm reposting the solution here so that Github will show it as the top accepted answer.