 (use-package lsp-pyright
   :after (lsp-mode)
   :config
+  (add-hook 'python-mode-hook
+            (lambda ()
+              (when (python-use-poetry-p)
+                (setq-local lsp-pyright-python-executable-cmd (concat (python-poetry-virtualenv-path) "/bin/python"))
+                (setq-local lsp-pyright-venv-path (python-poetry-virtualenv-path)))))
+
   (let ((client (gethash 'pyright lsp-clients)))
     (setf (lsp--client-major-modes client) nil)
     (setf (lsp--client-activation-fn client)

                 t))
      (python-isort-on-save-mode 1))))

(add-hook 'python-mode-hook
          (lambda ()
            ;; Set `python-shell-interpreter'
            (when (python-use-poetry-p)
              (make-local-variable 'python-shell-interpreter)
              (setf python-shell-interpreter
                    (with-temp-buffer
                      (if (condition-case err
                              (zerop (call-process "poetry" nil t nil "run" "which" "python"))
                            (error (message "%s" (error-message-string err)) nil))
                          (string-trim (buffer-string))
                        nil))))

            (with-eval-after-load 'dap-python
              (setf dap-python-executable python-shell-interpreter))

  :config
  (setf flycheck-pylintrc `("pylintrc" ".pylintrc" "pyproject.toml" "setup.cfg"
                            ,(or (getenv "PYLINTRC")
                                 (expand-file-name
                                  (concat (or (and (getenv "XDG_CONFIG_HOME")
                                                   (file-name-as-directory (getenv "XDG_CONFIG_HOME")))
                                              "~/.config/")
                                          "pylintrc")))
                            "/etc/pylintrc"))

  (setf flycheck-flake8rc `(".flake8" "setup.cfg" "tox.ini"
                            ,(expand-file-name
                              (concat
                               (or (and (getenv "XDG_CONFIG_HOME")
                                        (file-name-as-directory (getenv "XDG_CONFIG_HOME")))
                                   "~/.config/")
                               "flake8"))))

  (setf flycheck-python-mypy-config `("mypy.ini" ".mypy.ini" "pyproject.toml" "setup.cfg"
                                      ,(concat (expand-file-name
