Skip to content
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

[python] [emacs] [flycheck] [ruff] unclear issue with diagnostics provider #597

Open
ltrojan opened this issue Sep 16, 2024 · 1 comment

Comments

@ltrojan
Copy link

ltrojan commented Sep 16, 2024

Screenshot from 2024-09-16 09-49-53
I'm encountering an issue where the flycheck creates a host of errors that seems to be related to the way the lsp checker interprets the errors from what appears to be the ruff linter

you can see a screenshow of my emacs window with the error

I'm pasting my emacs init.el file below

If anyone could point me in the right direction on how to fix this and whether this is just a configuration issue or an actual bug triggered by an unusual configuration, that'd be much appreciated...

(setq inhibit-splash-screen t)
(setq-default indent-tabs-mode nil)
;; (setq package-check-signature nil)

(require 'package)
(setq
 package-archives
 '(
   ("gnu" . "https://elpa.gnu.org/packages/")
   ("melpa" . "https://melpa.org/packages/")))
(package-initialize)

(unless (package-installed-p 'use-package)
  (package-install 'use-package))

(use-package pyvenv
  :ensure t
  :config
  ;; Enable pyvenv-mode whenever a python file is opened
  (add-hook 'python-mode-hook 'pyvenv-mode))
(defun my/poetry-find-and-activate ()
  "Automatically find and activate the Poetry virtual environment for the project."
  (interactive)
  (message "attempting to load venv")
  (let ((venv (string-trim (shell-command-to-string "poetry env info --path"))))
    (if (file-exists-p venv)
        (pyvenv-activate venv)
      (message (concat venv "No virtualenv found for this project")))))
(add-hook 'python-mode-hook 'my/poetry-find-and-activate)


(use-package flycheck
  :ensure t
  :init (global-flycheck-mode))
(use-package company
  :ensure t
  :hook (lsp-mode . company-mode))
(use-package treemacs
  :ensure t
  :defer t)
(use-package ivy
  :ensure t
  :defer t
  :config
  (ivy-mode 1))

(use-package lsp-mode
  :ensure t
  :init
  (setq lsp-keymap-prefix "C-c l")
  ;; :commands lsp
  :hook (
         (python-mode . lsp-deferred)
         (lsp-mode . lsp-enable-which-key-integration))
  :config
  (setq lsp-prefer-flymake t))         ;; Disable `flymake`



(use-package lsp-ui
  :ensure t
  :hook (lsp-mode . lsp-ui-mode)
  :commands lsp-ui-mode)
(use-package lsp-ivy
  :ensure t
  :commands lsp-ivy-workspace-symbol)
(use-package lsp-treemacs
  :ensure t
  :commands lsp-treemacs-errors-list)


(use-package dap-mode
  :ensure t)
(use-package dap-python
  )



;;(add-hook 'python-mode-hook
;;          (lambda () (setq flycheck-disabled-checkers '(lsp))))


(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(package-selected-packages '(gnu-elpa-keyring-update use-package)))
(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 )
@ltrojan ltrojan changed the title [python] [flycheck] [ruff] unclear issue with diagnostics provider, flycheck and ruff [python] [emacs] [flycheck] [ruff] unclear issue with diagnostics provider Sep 16, 2024
@doolio
Copy link
Contributor

doolio commented Oct 10, 2024

Unsure if I can help as I use eglot rather than lsp-mode. However, a couple of points.

  1. You probably don't want flymake and flycheck enabled at the same time.
(setq lsp-prefer-flymake t))         ;; Disable `flymake`

This suggests you enable flymake rather than disable it and you prefer it presumably over flycheck.

  1. Your pyproject.toml also seems incorrect.

    • You list python-lsp-ruff under poetry dependencies.
    • You list python as a poetry dependency. I appreciate it is a python project manager but does python have to be listed here?
    • If you are using ruff then isort and black are probabaly unnecessary.
    • In addition ruff is a dependency of python-lsp-ruff so shouldn't need to be listed separately.
    • I don't understand why you have a separate table for emacs dependencies when none of those are dependencies of emacs.
  2. You make no mention of how you have installed python-lsp-server. You probably want to install it once and make it available to all your projects rather than install it for each project. If so I suggest you install with pipx for your own user which will make it available globally.

3a. First install pipx either through your system package manager in the usual way or with pip as follows:

python3 -m pip install --user pipx

3b. Use pipx to install python-lsp-server into an isolated virtual environment with pylsp made available globally

python3 -m pipx install python-lsp-server

3c. Use pipx to inject python-lsp-ruff into the same isolated virtual environment as python-lsp-server making ruff (and pylsp) globally available

python3 -m pipx inject --include-deps python-lsp-server python-lsp-ruff

3d. Use pipx to inject pylsp-mypy into the same isolated virtual environment as python-lsp-server making mypy etc. globally available

python3 -m pipx inject --include-deps python-lsp-server pylsp-mypy
  1. I suggest looking into direnv rather than pyvenv. Packages to integrate with Emacs exist. I use envrc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants