-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
emacs-lsp-booster doesn't work well with emacs-pet/pyvenv regarding python virtual environment #37
Comments
Thanks for the very detailed report. Going though your log, I think the different may come from this:
vs
This client notification sends the virtual env path to the server. If this step goes wrong, it may explain what you experienced. According to the log, when I don't think the |
No,
|
Thanks for your comment, I've CCed this issue to the author of pet, @jdtsmith would you like to share your workflow with |
In the end you just need to set |
When an empty hash table is sent in What do you see from How exactly do you enable |
Not special, magical step to enable
(use-package eglot-booster
:after eglot
:config (eglot-booster-mode))
|
I can't reproduce this issue on Emacs 30. All 3 packages works totally fine together. Are you able to reprod the same issue using the latest eglot from Elpa? You appear to be using the bundled eglot in Emacs 29. |
I encountered this problem again even though I've upgraded (defun ramsay/pyrightconfig-find-venv-directories (project-root)
"Find potential virtual environment directories for a project in PROJECT-ROOT."
(let* ((common-venv-names '(".venv" ".env" "venv" "env"))
(common-venv-locations (list project-root))
(potential-paths '()))
;; Check common locations in project root and home directory
(dolist (location common-venv-locations)
(dolist (name common-venv-names)
(let ((full-path (expand-file-name name location)))
(when (file-directory-p full-path)
(push full-path potential-paths)))))
;; Return found paths
(reverse potential-paths)))
(defun ramsay/pyrightconfig-suggest ()
"Interactively select a virtualenv and write pyrightconfig.json."
(interactive)
(let* ((project-root (or (vc-git-root default-directory)
default-directory))
(venv-paths (ramsay/pyrightconfig-find-venv-directories project-root))
(selected-venv
(completing-read
"Select virtual environment: "
(append venv-paths
;; Add option to specify custom path
'("[Custom path...]"))
nil t)))
(if (string= selected-venv "[Custom path...]")
;; If custom path selected, call original function
(call-interactively #'ramsay/pyrightconfig-write)
;; Otherwise use selected path
(ramsay/pyrightconfig-write selected-venv))))
;; Derived from https://robbmann.io/posts/emacs-eglot-pyrightconfig/
(defun ramsay/pyrightconfig-write (virtualenv)
"Write pyrightconfig.json for the given VIRTUALENV path."
(interactive "DEnv: ")
(let* ((venv-dir (tramp-file-local-name (file-truename virtualenv)))
(venv-file-name (directory-file-name venv-dir))
(venvPath (file-name-directory venv-file-name))
(venv (file-name-base venv-file-name))
(base-dir (vc-git-root default-directory))
(out-file (expand-file-name "pyrightconfig.json" base-dir))
(out-contents (json-encode (list :venvPath venvPath :venv venv))))
(with-temp-file out-file (insert out-contents)))) https://github.com/ramsayleung/emacs.d/blob/master/lisp/init-programming.el#L97-L144 |
I do something like that too, but I have eglot send it to pyright "over the wire" to keep all config in emacs. Something like: (defun my/eglot-workspace-config (server)
"A workspace config for pyright/basedpyright.
Note that some settings do not nest as you'd expect. Allows
dir-local special config variable `pyright-extra-paths' to be
added via `:extraPaths`.'"
(let ((config (list :python.analysis ; N.B. eglot does not consider :settings nested!
;; (list :diagnosticMode "openFilesOnly")
(list :stubPath
(expand-file-name "~/code/python/stubs/common")
;; :diagnosticMode "openFilesOnly"
)
;; recommended is TMI IMO
:basedpyright.analysis '(:typeCheckingMode "standard"))))
(hack-dir-local-variables-non-file-buffer)
(when (bound-and-true-p pyright-extra-paths)
(setf (plist-get (cadr config) :extraPaths)
(vconcat pyright-extra-paths)))
(when-let ((venv (simple-venv-find)) ; this command is local to my config
((not (eq venv 'none)))
(vp (file-name-directory venv))
(vn (file-name-nondirectory venv)))
(nconc config
(list :python `(;; :venvPath ,vp :venv ,vn
:pythonPath ,(simple-venv-interpreter venv)))))
config)) |
Hi, Thanks so much for this awsome project, it works well with all language servers along with
eglot
, except for python project with virtual environment in my case.I used to manage my virual environment with
https://github.com/jorgenschaefer/pyvenv
, then switch topet
later.But I've been struggled with
eglot-booster-mode
for a while, after I enableeglot-booster-mode
withpet
,eglot
fails to recognize all dependencies installed in the virtual environment.How to reproduce
pyright-language-server
is installed and in your PATHpython3 -m venv .venv source .venv/bin/activate pip install python-dotenv
init.el
Open the
![image](https://private-user-images.githubusercontent.com/14180681/400182904-44e91f07-a499-4fdd-9be2-19992525c9e2.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkxNzEwNTQsIm5iZiI6MTczOTE3MDc1NCwicGF0aCI6Ii8xNDE4MDY4MS80MDAxODI5MDQtNDRlOTFmMDctYTQ5OS00ZmRkLTliZTItMTk5OTI1MjVjOWUyLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTAlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjEwVDA2NTkxNFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTgyYzQyNWEzMjY5YWZkN2I5MWMzZDA5NGFkYmVhMDhkZjI3NWYyMTMxYjE3MTVhY2RiZjNlYmNmZTA3NDEwM2MmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.H-hUxfSj2B72kY-V5ddXiSqYLr2kObGfXbkjv99Jc7U)
poc.py
with(eglot-booster-mode)
enabled, flymake couldn't resolve thedotenv
packageReopen the
poc.py
with(eglot-booster-mode)
disabled, restarteglot
or restart emacs, flymake manages to resolve thedotenv
Logs
eglot-booster-mode
enabled:eglot-booster-mode
disabled:The text was updated successfully, but these errors were encountered: