Giter Club home page Giter Club logo

Comments (3)

zealinux avatar zealinux commented on June 14, 2024 1
;; (add-hook! python-mode
;;   (setq lsp-pyright-extra-paths (vector (pdm-get-packages-path)))
;;   (setq lsp-pyright-auto-search-paths (pdm-get-python-executable))
;;   (setq lsp-pyright-venv-path (pdm-get-python-executable))
;;   (require 'lsp-pyright)
;;   (lsp)) ; or lsp-deferred

(use-package lsp-pyright
  :ensure t
  :hook (python-mode . (lambda ()
                         (setq lsp-pyright-extra-paths (vector (pdm-get-packages-path)))
                         (setq lsp-pyright-auto-search-paths (pdm-get-python-executable))
                         (setq lsp-pyright-venv-path (pdm-get-python-executable))
                          (require 'lsp-pyright)
                          (lsp))))  ; or lsp-deferred

from lsp-pyright.

dev590t avatar dev590t commented on June 14, 2024

I use doom emacs. It use a different mecanism to add package than classic emacs.

After reconfigure ~/.doom.d/init.el with (python +lsp +pyright +pyenv +poetry +cython) . And install the packages in .venv. lsp-pyright can automatically find the package and the interpreter in .venv without any additional configuration.

Thanks you for your answer

from lsp-pyright.

worldofgeese avatar worldofgeese commented on June 14, 2024

@dev590t and others who stumble upon this, @zealinux's code sample is correct for any Emacs distro other than Doom. To make it compatible with Doom, one just needs to add a ! after use-package. Here's what a complete, working example looks like with a very lightly altered function from @Lin1995 incorporating a change from @tihuang02 given in this discussion:

(defun linw1995/pdm-get-python-executable (&optional dir)
    (let ((pdm-get-python-cmd "pdm info --python"))
      (string-trim
       (shell-command-to-string
        (if dir
            (concat "cd "
                    dir
                    " && "
                    pdm-get-python-cmd)
          pdm-get-python-cmd)))))

(defun linw1995/pdm-get-packages-path (&optional dir)
  (let ((pdm-get-packages-cmd "pdm info --packages"))
    (concat (string-trim
             (shell-command-to-string
              (if dir
                  (concat "cd "
                          dir
                          " && "
                          pdm-get-packages-cmd)
                pdm-get-packages-cmd)))
            "/lib")))

(use-package lsp-pyright
  :ensure t
  :hook (python-mode . (lambda ()
                         (setq lsp-pyright-extra-paths (vector (pdm-get-packages-path)))
                         (setq lsp-pyright-auto-search-paths (pdm-get-python-executable))
                         (setq lsp-pyright-venv-path (pdm-get-python-executable))
                          (require 'lsp-pyright)
                          (lsp)))) 

@frostming, @zealinux's solution is a great code sample that gets PDM using PEP 582 working with Pyright in Emacs.

Many thanks to @zealinux for his generous offering ❤️

from lsp-pyright.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.