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

Set up problems with python-lsp-ruff #1003

Closed
Martin15135215 opened this issue Oct 19, 2023 · 5 comments
Closed

Set up problems with python-lsp-ruff #1003

Martin15135215 opened this issue Oct 19, 2023 · 5 comments

Comments

@Martin15135215
Copy link

Description

I want to use python-lsp-ruff, instead of the default linter for python.

Reproduce

I use MX Linux 23. It's based on Debian 12.

Pipenv installed with sudo nala install pipenv

This is the content of my Pipfile:

[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
numpy = "~=1.24.4"
ifcopenshell = "*"
lark = "*"

[dev-packages]
jupyterlab = "*"
jupyterlab-quarto = "*"
jupyterlab-lsp = "*"
python-lsp-ruff = "*"
nbqa = "*"
pylsp-mypy = "*"
nbdev = "*"
black = "*"

[requires]
python_version = "3.11"

Install this with pipenv install --dev

Do this step

1. (Optional, IPython users only) to improve the performance of autocompletion,

image

and this step

1. (Optional, Linux/OSX-only) As a security measure by default Jupyter server only allows

image

start jupyer lab with pipenv run jupyter lab or pipenv shell and then jupyter lab

and then go to Advanced Settings Editor

https://github.com/jupyter-lsp/jupyterlab-lsp/blob/5a8686067bdeeb1f8ce5bc108d7fd047809b0f80/README.md?plain=1#L192C99-L192C123

image

Expected behavior

I would expect that pydocstyle was disabled, and ruff enabled, however I don't see that:

image

Context

  • Operating System and version: Mx Linux 23 (Debian 12)
  • Browser and version: Librewolf 118
  • JupyterLab version: 4.0.7
  • Language server and version: python-lsp-ruff version 1.5.3
Required: installed server extensions
➤ jupyter server extension list
Config dir: /home/USER/.jupyter

Config dir: /home/USER/.local/share/virtualenvs/project-cao8W2n7/etc/jupyter
jupyter_lsp enabled
- Validating jupyter_lsp...
Package jupyter_lsp took 0.0071s to import
A _jupyter_server_extension_points function was not found in jupyter_lsp. Instead, a _jupyter_server_extension_paths function was found and will be used for now. This function name will be deprecated in future releases of Jupyter Server.
jupyter_lsp 2.2.0 OK
jupyter_server_terminals enabled
- Validating jupyter_server_terminals...
Package jupyter_server_terminals took 0.0034s to import
jupyter_server_terminals 0.4.4 OK
jupyterlab enabled
- Validating jupyterlab...
Package jupyterlab took 0.0471s to import
jupyterlab 4.0.7 OK
notebook_shim enabled
- Validating notebook_shim...
Package notebook_shim took 0.0000s to import
A _jupyter_server_extension_points function was not found in notebook_shim. Instead, a _jupyter_server_extension_paths function was found and will be used for now. This function name will be deprecated in future releases of Jupyter Server.
notebook_shim OK

Config dir: /usr/local/etc/jupyter

Required: installed lab extensions
➤ jupyter labextension list
JupyterLab v4.0.7
/home/USER/local/share/virtualenvs/project-cao8W2n7/share/jupyter/labextensions
        jupyterlab-quarto v0.2.8 enabled OK (python, jupyterlab-quarto)
        jupyterlab_pygments v0.2.2 enabled  X (python, jupyterlab_pygments)
        @jupyter-widgets/jupyterlab-manager v5.0.9 enabled OK (python, jupyterlab_widgets)
        @jupyter-lsp/jupyterlab-lsp v5.0.0 enabled OK (python, jupyterlab-lsp)

The following extensions are outdated:
jupyterlab_pygments

Consider checking if an update is available for these packages.

Disabled extensions:
@jupyterlab/completer-extension:base-service
@jupyterlab/fileeditor-extension:language-server
@jupyterlab/lsp-extension:settings
@jupyterlab/notebook-extension:language-server

Troubleshoot Output
➤ jupyter troubleshoot
$PATH:
        /home/USER/.local/share/virtualenvs/project-cao8W2n7/bin
        /home/USER/.cargo/bin
        /usr/local/bin
        /usr/bin
        /bin
        /usr/local/games
        /usr/games
        /home/USER/.local/bin
        /home/USER/.local/bin

sys.path:
/home/USER/.local/share/virtualenvs/project-cao8W2n7/bin
/usr/lib/python311.zip
/usr/lib/python3.11
/usr/lib/python3.11/lib-dynload
/home/USER/.local/share/virtualenvs/project-cao8W2n7/lib/python3.11/site-packages
/media/python/project

sys.executable:
/home/USER/.local/share/virtualenvs/project-cao8W2n7/bin/python

sys.version:
3.11.2 (main, Mar 13 2023, 12:18:29) [GCC 12.2.0]

platform.platform():
Linux-6.1.0-13-amd64-x86_64-with-glibc2.36

which -a jupyter:
/home/USER/.local/share/virtualenvs/project-cao8W2n7/bin/jupyter

pip list:
Package Version Editable project location
------------------------- ------------ ------------------------------------------------------------------------
anyio 4.0.0
argon2-cffi 23.1.0
argon2-cffi-bindings 21.2.0
arrow 1.3.0
asttokens 2.4.0
astunparse 1.6.3
async-lru 2.0.4
attrs 23.1.0
autopep8 2.0.4
Babel 2.13.0
backcall 0.2.0
beautifulsoup4 4.12.2
black 23.10.0
bleach 6.1.0
cattrs 23.1.2
certifi 2023.7.22
cffi 1.16.0
charset-normalizer 3.3.0
click 8.1.7
comm 0.1.4
debugpy 1.8.0
decorator 5.1.1
defusedxml 0.7.1
docstring-to-markdown 0.13
execnb 0.1.5
executing 2.0.0
fastcore 1.5.29
fastjsonschema 2.18.1
fqdn 1.5.1
ghapi 1.0.4
idna 3.4
ifcopenshell 0.7.0.231018
ipykernel 6.25.2
ipython 8.16.1
ipywidgets 8.0.4
isoduration 20.11.0
jedi 0.19.1
Jinja2 3.1.2
json5 0.9.14
jsonpointer 2.4
jsonschema 4.19.1
jsonschema-specifications 2023.7.1
jupyter_client 8.4.0
jupyter_core 5.4.0
jupyter-events 0.8.0
jupyter-lsp 2.2.0
jupyter_server 2.8.0
jupyter_server_terminals 0.4.4
jupyterlab 4.0.7
jupyterlab-lsp 5.0.0
jupyterlab-pygments 0.2.2
jupyterlab-quarto 0.2.8
jupyterlab_server 2.25.0
jupyterlab-widgets 3.0.9
lark 1.1.7
lsprotocol 2023.0.0b1
MarkupSafe 2.1.3
matplotlib-inline 0.1.6
mistune 3.0.2
mypy 1.6.1
mypy-extensions 1.0.0
nbclient 0.8.0
nbconvert 7.9.2
nbdev 2.3.13
nbformat 5.9.2
nbqa 1.7.0
nest-asyncio 1.5.8
notebook_shim 0.2.3
numpy 1.24.4
overrides 7.4.0
packaging 23.2
pandocfilters 1.5.0
parso 0.8.3
pathspec 0.11.2
pexpect 4.8.0
pickleshare 0.7.5
pip 23.3
platformdirs 3.11.0
pluggy 1.3.0
prometheus-client 0.17.1
prompt-toolkit 3.0.39
psutil 5.9.6
ptyprocess 0.7.0
pure-eval 0.2.2
pycodestyle 2.11.1
pycparser 2.21
Pygments 2.16.1
pylsp-mypy 0.6.7
python-dateutil 2.8.2
python-json-logger 2.0.7
python-lsp-jsonrpc 1.1.2
python-lsp-ruff 1.5.3
python-lsp-server 1.8.2
PyYAML 6.0.1
pyzmq 25.1.1
referencing 0.30.2
requests 2.31.0
rfc3339-validator 0.1.4
rfc3986-validator 0.1.1
rpds-py 0.10.6
ruff 0.0.292
Send2Trash 1.8.2
setuptools 68.2.2
six 1.16.0
sniffio 1.3.0
soupsieve 2.5
stack-data 0.6.3
terminado 0.17.1
tinycss2 1.2.1
tokenize-rt 5.2.0
tomli 2.0.1
tornado 6.3.3
traitlets 5.11.2
types-python-dateutil 2.8.19.14
typing_extensions 4.8.0
ujson 5.8.0
uri-template 1.3.0
urllib3 2.0.7
watchdog 3.0.0
wcwidth 0.2.8
webcolors 1.13
webencodings 0.5.1
websocket-client 1.6.4
wheel 0.41.2
widgetsnbextension 4.0.9

@krassowski
Copy link
Member

Thank for opening the issue! There are two problems:

  1. You have a typo, in the lines disabling pycodestyle and pyflakes, your code says pyls but it should be pylsp
  2. Recent versions of ruff do not work with jupyterlab-lsp because they sniff based on file extension rather than content; I would treat it as a bug in python-lsp-ruff rather than ruff itself, because in the LSP protocol language has a meaning but extension does not, so python-lsp-ruff should instruct ruff to expect a python file even if it comes with .ipynb suffix Break in compatibility with jupyterlab-lsp + python-lsp-ruff since 0.0.285 astral-sh/ruff#6847 (comment)

@krassowski
Copy link
Member

My reading of the issue is that downgrading ruff to a version older than 0.0.285 should make it work for now (while you have 0.0.292).

@Martin15135215
Copy link
Author

Thanks for the comprehensive answer:

  1. I did correct that typo and did restart Jupyter lab and did restart the kernel. However, there are still hints from pycodestyle. See image:

image

@Martin15135215
Copy link
Author

  1. I updated my Pipfile:
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
numpy = "~=1.24.4"
ifcopenshell = "*"
lark = "*"



[dev-packages]
jupyterlab = "*"
jupyterlab-quarto = "*"
jupyterlab-lsp = "*"
nbqa = "*"
pylsp-mypy = "*"
nbdev = "*"
black = "*"
python-lsp-ruff = "==1.5.3"
ruff = "==0.0.284"

[requires]
python_version = "3.11"

Now there are hints in jupyter from ruff. However i am confused with this blog post here https://astral.sh/blog/ruff-v0.1.0#a-growing-feature-set with Jupyter notebook support. What about there lsp? See https://github.com/astral-sh/ruff-lsp

  1. Other question: How can i get mypy in jupyer running? I installed pylsp-mypy

@krassowski
Copy link
Member

Closing as python-lsp/python-lsp-ruff#59 was merged and I can confirm that latest versions of ruff and python-lsp-ruff work well with jupyterlab-lsp:

image

$ pip list | grep ruff
python-lsp-ruff                2.0.0
ruff                           0.1.6

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