emacs-lsp / lsp-pyright

lsp-mode :heart: pyright
https://emacs-lsp.github.io/lsp-pyright
GNU General Public License v3.0
291 stars 25 forks source link

How to set PYTHONPATH for python shell based on project root? #91

Open orlandini opened 8 months ago

orlandini commented 8 months ago

Hello, I am using pyright and I am currently able to detect my (sub)project root by means of a .projectile file in the desired directory. In this way, pyright finds all my modules as expected.

Now, I would like to start a python shell with the project root directory prepended to my existing PYTHONPATH.

I've found a way to change the working directory of the python interpreter:

(defun my-run-python ()
  (interactive)
  (let ((default-directory (or (projectile-project-root) default-directory)))
    (call-interactively #'run-python)))

However, this is not the behaviour I intended. I just would like to prepend (projectile-project-root) to the PYTHONPATH seen by the python interpreter when called through run-python whenever I am in a project using pyright. Perhaps using lsp-pyright-extra-paths would be useful, but I am not an expert in Lisp.

Best regards and thank you in advance,

Francisco