frymye · 2022-10-24 17:06
Hello. I've recently been trying to set up emacs to play nicely with python. The number of options is a bit overwhelming, but a lot of signs are pointing towards using lsp with pyright and lsp-ui. So that's what I've been doing, along with using pyvenv to choose my virtual environments. But I've noticed that I don't get any warnings if my lines are too long. I'm not sure why this is? Does it have to do with my settings, or is this not something lsp/pyright should catch?
pathemata · 2022-10-24 19:19
You want a style checker called flake8.
I use it with flymake (together with pyright via eglot).
Maybe you can set it up with flycheck (I think flycheck this is the default with lsp-mode).
frymye · 2022-10-24 19:34
This is part of what's confusing me. When I verify my flycheck setup, it looks like I can use either lsp or flake8 as my checker, but not both? Aren't these doing different things?
lianacrossk7n · 2022-10-24 20:05
you can use both via checker chain (https://www.flycheck.org/en/latest/user/syntax-checkers.html#configuring-checker-chains) but there's a workaround needed for lsp
[https://github.com/flycheck/flycheck/issues/1762#issuecomment-750458442](https://github.com/flycheck/flycheck/issues/1762#issuecomment-750458442)
For posterity:
yyoncho:
>As a side note, I think that we will be fine with a solution using advices in case you don't agree on the obarray change, here it is a bit more concise version.
(defvar-local my/flycheck-local-cache nil)
(defun my/flycheck-checker-get (fn checker property)
(or (alist-get property (alist-get checker my/flycheck-local-cache))
(funcall fn checker property)))
(advice-add 'flycheck-checker-get :around 'my/flycheck-checker-get)
(add-hook 'lsp-managed-mode-hook
(lambda ()
(when (derived-mode-p 'sh-mode)
(setq my/flycheck-local-cache '((lsp . ((next-checkers . (sh-posix-bash)))))))))
frymye · 2022-10-24 20:23
Do I understand correctly that eglot is an alternative to lsp that won't require such workarounds?
lianacrossk7n · 2022-10-24 20:32
eglot is an alternative to lsp but it requires a similar workaround:
https://github.com/joaotavora/eglot/issues/268
> Sometimes, in python-mode, this leads to duplicated diagnostics. So, by default, Eglot uses only the eglot-flymake-backend and supresses the others.
I use something like:
```
(setq python-flymake-command '("flake8" "-"))
(add-hook 'eglot-managed-mode-hook
(lambda ()
(when (derived-mode-p 'python-mode)
(add-hook 'flymake-diagnostic-functions 'python-flymake nil t))))
```
lianacrossk7n · 2022-10-24 20:44
Also as pathemata mentioned: lsp-mode uses flycheck (3rd party) and eglot uses flymake (built in)
I haven't tried using both at the same time but letting the lsp client use it's default and you configure extra checkers with the other one might a workaround that isn't a workaround.
frymye · 2022-10-25 09:25
I couldn't actually get this to work with the lsp checker. I see flake8 as second in the chain but I don't seem to actually be getting flake8 warnings. But the python-pyright checker seems to be working with flake8 as second in the chain.
So now I'm confused about the difference between lsp and python-pyright. Both are using pyright in my case.
lianacrossk7n · 2022-10-27 18:25
I don't use flycheck and I'm not sure how to troubleshoot it.
A new thread to garner help from flycheck users might be something to consider.