astral-sh / ruff-vscode

A Visual Studio Code extension with support for the Ruff linter.
Other
1.03k stars 52 forks source link

Improve logging in VSCode extension #526

Closed LaurensBosscher closed 1 month ago

LaurensBosscher commented 1 month ago

Hi,

Today I noticed that the version of Ruff that's used by the LSP and the version that we have installed in our .venvs do not seem to be in sync:

image

In order to debug this, I went to the Output -> Ruff screen and that shows following information:

image

It would be useful to add the following information:

In addition to the above, it seems that every time I press save it prints the following log lines:

image

dhruvmanila commented 1 month ago

Hi, thanks for opening this issue. Can you provide the following information:

I think some of this has been fixed and some has been released. Can you check if you're on the latest version of the VS Code extension (2024.30.0) ?

LaurensBosscher commented 1 month ago

Hi, thanks for opening this issue. Can you provide the following information:

  • Version of Ruff loaded
  • Location of settings that are applied (e.g path to pyproject.toml)
  • Relevant VSCode settings (e.g exclude, preview, etc)

I think some of this has been fixed and some has been released. Can you check if you're on the latest version of the VS Code extension (2024.30.0) ?

Of course!

Path to pyproject.toml is e.g:

/home/laurens/develop/savex/libraries/SharedModels/pyproject.toml

Which loads:

/home/laurens/develop/savex/pyproject.toml

We have multiple projects inside a mono-repo and open these projects in a VSCode Workspace.

Version + top of log: image

Version + noise: image

Ruff settings in root pyproject.toml:

[tool.ruff]
line-length = 120

exclude = [
    ".bzr",
    ".direnv",
    ".eggs",
    ".git",
    ".hg",
    ".mypy_cache",
    ".nox",
    ".pants.d",
    ".ruff_cache",
    ".svn",
    ".tox",
    ".venv",
    '.history',
    "__pypackages__",
    "_build",
    "buck-out",
    "build",
    "dist",
    "node_modules",
    "venv",
    "migrations",
    ".mypy_cache",
    "build",
    "snapshots",
]

fix = true

extend-include = ["*.ipynb"]

lint.unfixable = ["T201", "ERA001", "F401", "RUF100"]

# See: https://github.com/charliermarsh/ruff#supported-rules
lint.select = [
    "F",     # Pyflakes
    "E",     # pycodestyle Error
    "W",     # pycodestyle Warning
    "C90",   # mccabe
    "I",     # isort
    "D",     # pydocstyle
    "UP",    # pyupgrade
    "N",     # pep8-naming
    "YTT",   # flake8-2020
    "ASYNC", # flake8-async
    "ANN",   # flake8-annotations
    "S",     # flake8-bandit
    "BLE",   # flake8-blind-except
    "FBT",   # flake8-boolean-trap
    "B",     # flake8-bugbear
    "A",     # flake8-builtins
    "C4",    # flake8-comprehensions
    "T10",   # flake8-debugger
    "DJ",    # flake8-django
    "EM",    # flake8-errmsg
    "ISC",   # flake8-implicit-str-concat
    "ICN",   # flake8-import-conventions
    "T20",   # flake8-print
    "PYI",   # flake8-pyi
    "R",     # refactor
    "Q",     # flake8-quotes
    "RET",   # flake8-return
    "SLF",   # flake8-self
    "PT",    # flake8-pytest-style
    "SIM",   # flake8-simplify
    "TID",   # flake8-tidy-imports
    "ARG",   # flake8-unused-arguments
    "DTZ",   # flake8-datetimez
    "ERA",   # eradicate
    "PD",    # pandas-vet
    "PGH",   # pygrep-hooks
    "PLC",   # Pylint Convention
    "PLE",   # Pylint Error
    "PLR",   # Pylint Refactor
    "PLW",   # Pylint Warning
    "PIE",   # flake8-pie
    "COM",   # flake8-commas
    "INP",   # flake8-no-pep420
    "EXE",   # flake8-executable
    "TCH",   # flake8-type-checking
    "ARG",   # flake8-unused-arguments
    "TRY",   # tryceratops
    "PTH",   # flake8-use-pathlib
    "RUF",   # Ruff-specific rules
    "RSE",   # flake8-raise
    "SLOT",  # flake8-slots
    "TD",    # flake8-todos
    "FLY",   # flynt
    "NPY",   # NumPy-specific rules
    "PERF",  # Perflint
    "G",     # flake8-logging-format
    "PL",    # Pylint
    "FURB",  # refurb
]

lint.ignore = [
    'E501',   # Line length violation
    'ISC001', # Conflicts with formatter
    'EXE002', # The file is executable but no shebang is present
    "COM812", # Trailing comma missing
    "D100",   # D10* = Do not enforce docstrings
    "D101",
    "D102",
    "D103",
    "D104",
    "D105",
    "D106",
    "D107",
    "G004",   # Logging statement uses f-string (Todo(L.Bosscher): it would be good to fix this but lets do that in a different PR.
    "N802",   # PEP8 capitalisation, disable so we can have e.g NAV_
    "N803",   # PEP8 capitalisation
    "N806",   # PEP8 capitalisation
    "DTZ005", # The use of `datetime.datetime.now()` without `tz` argument is not allowed
    "D211",   # NoBlankLinesBeforeClass
    "D212",   # Multi-line docstring summary should start at the first line
    "D203",   # 1 blank line required before class docstring 
    "D400",   # First line should end with a period
    "EM101",  # Exception must not use a string literal, assign to variable first
    "ANN101", # Missing type annotation for `...` in method, covered by MyPy
    "RUF012", # Mutable class attributes should be annotated with `typing.ClassVar`
    "TD003",  # Missing issue link on the line following this TODO
]

extend-exclude = [".venv", "notebooks", "docker"]

target-version = "py312"

[tool.ruff.lint.flake8-tidy-imports.banned-api]
"pandas.read_sql".msg = "Use the appropriate method in connector_ids_database (or create a new one) to query the database"
"pandas.read_sql_query".msg = "Use the appropriate method in connector_ids_database (or create a new one) to query the database"
"pandas.DataFrame.to_sql".msg = "Use the appropriate method in connector_ids_database (or create a new one) to query the database"
"pandas.to_sql".msg = "Use the appropriate method in connector_ids_database (or create a new one) to query the database"
"sqlalchemy".msg = "Use the appropriate method in connector_ids_database (or create a new one) to query the database"
"xbbg".msg = "Use the appropriate method in market_data to query data vendors (including Bloomberg)"

[tool.ruff.lint.isort]
required-imports = ["from __future__ import annotations"]

[tool.ruff.lint.per-file-ignores]
"*test*.py" = [
    "S101",    # Asserts allowed in tests...
    "S",       # We don't care about security in tests
    "N999",    # Invalid module name
    "INP001",  # File `` is part of an implicit namespace package. Add an `__init__.py`
    "ANN001",  # Missing type annotation for function argument
    "ANN002",  # Missing type annotation for `**args`
    "ANN003",  # Missing type annotation for `**kwargs`
    "ANN201",  # Missing return type annotation for public function
    "TRY003",  # Avoid specifying long messages outside the exception class
    "ARG",     # Unused function args -> fixtures nevertheless are functionally relevant...
    "FBT",     # Don't care about booleans as positional arguments in tests, e.g. via @pytest.mark.parametrize()
    "PLR2004", # Magic value used in comparison, ...
    "S311",    # Standard pseudo-random generators are not suitable for cryptographic purposes
]

Version of Ruff in the virtual env: image

Vscode settings: image

Let me know if there's anything else I can provide!

dhruvmanila commented 1 month ago

There are couple of PRs which have improved the logging on main (#509, #511, #512). You can see in the "Test plan" of those PRs the messages that will be emitted now which includes the ruff binary used, how it was discovered and the version of the binary as well.

Regarding the warnings that you're seeing in the following screenshot:

In order to debug this, I went to the Output -> Ruff screen and that shows following information:

image

This should be fixed in the latest Ruff version via https://github.com/astral-sh/ruff/pull/12252.

We're going to be releasing a new version of the VS Code extension soon. I'd appreciate if you can try it with the latest version then and check if you're facing the same problems.

LaurensBosscher commented 1 month ago

There are couple of PRs which have improved the logging on main (#509, #511, #512). You can see in the "Test plan" of those PRs the messages that will be emitted now which includes the ruff binary used, how it was discovered and the version of the binary as well.

Regarding the warnings that you're seeing in the following screenshot:

In order to debug this, I went to the Output -> Ruff screen and that shows following information: image

This should be fixed in the latest Ruff version via astral-sh/ruff#12252.

We're going to be releasing a new version of the VS Code extension soon. I'd appreciate if you can try it with the latest version then and check if you're facing the same problems.

I've just updated VSCode and this is looking pretty good now! Thanks for your work and much appreciated, this will make debugging issues a lot easier.

image

It does still show the pandas noise, but this is not a huge issue.

dhruvmanila commented 1 month ago

It does still show the pandas noise, but this is not a huge issue.

That's fixed in https://github.com/astral-sh/ruff/pull/11590, you might want to upgrade the ruff version. It's recommended to use 0.5.3 to use the native server as it's marked as stable in that version.