|
1 | 1 | import json |
2 | 2 | import logging |
3 | | -import sys |
4 | 3 | from pathlib import PurePath |
5 | 4 | from subprocess import PIPE, Popen, SubprocessError |
6 | 5 |
|
7 | 6 | from pylsp import hookimpl, lsp |
8 | 7 | from pylsp._utils import find_parents |
9 | 8 | from pylsp.workspace import Document, Workspace |
10 | 9 |
|
11 | | -# Use built-in tomllib for python>=3.11 |
12 | | -if sys.version_info >= (3, 11): |
13 | | - try: |
14 | | - import tomllib |
15 | | - except ImportError: |
16 | | - import tomli as tomllib |
17 | | -else: |
18 | | - import tomli as tomllib |
19 | | - |
20 | 10 | log = logging.getLogger(__name__) |
21 | 11 |
|
22 | 12 | UNNECESSITY_CODES = { |
@@ -187,6 +177,8 @@ def build_args(document: Document, options: dict) -> list: |
187 | 177 | args = ["--quiet"] |
188 | 178 | # Use the json formatting for easier evaluation |
189 | 179 | args.extend(["--format=json"]) |
| 180 | + # Do not attempt to fix -> returns file instead of diagnostics |
| 181 | + args.extend(["--no-fix"]) |
190 | 182 |
|
191 | 183 | # Convert per-file-ignores dict to right format |
192 | 184 | per_file_ignores = options.pop("per-file-ignores") |
@@ -230,36 +222,38 @@ def load_config(workspace: Workspace, document: Document) -> dict: |
230 | 222 | config = workspace._config |
231 | 223 | _settings = config.plugin_settings("ruff", document_path=document.path) |
232 | 224 |
|
233 | | - # Default values are given by ruff |
234 | | - settings = { |
235 | | - "config": _settings.get("config", None), |
236 | | - "exclude": _settings.get("exclude", None), |
237 | | - "executable": _settings.get("executable", "ruff"), |
238 | | - "ignore": _settings.get("ignore", None), |
239 | | - "line-length": _settings.get("lineLength", None), |
240 | | - "per-file-ignores": _settings.get("perFileIgnores", None), |
241 | | - "select": _settings.get("select", None), |
242 | | - } |
243 | | - |
244 | 225 | pyproject_file = find_parents( |
245 | 226 | workspace.root_path, document.path, ["pyproject.toml"] |
246 | 227 | ) |
247 | 228 |
|
248 | | - # Load config from pyproject file if it exists |
| 229 | + # Check if pyproject is present, ignore user settings if toml exists |
249 | 230 | if pyproject_file: |
250 | | - try: |
251 | | - log.debug(f"Found pyproject file: {str(pyproject_file[0])}") |
252 | | - |
253 | | - with open(str(pyproject_file[0]), "rb") as pyproject_toml: |
254 | | - toml_dict = tomllib.load(pyproject_toml) |
255 | | - |
256 | | - toml_config = toml_dict.get("tool", {}).get("ruff", {}) |
257 | | - |
258 | | - # Update settings with local project settings |
259 | | - for key, value in toml_config.items(): |
260 | | - settings[key] = value |
| 231 | + log.debug( |
| 232 | + f"Found pyproject file: {str(pyproject_file[0])}, " |
| 233 | + + "skipping pylsp config." |
| 234 | + ) |
| 235 | + |
| 236 | + # Leave config to pyproject.toml |
| 237 | + settings = { |
| 238 | + "config": None, |
| 239 | + "exclude": None, |
| 240 | + "executable": _settings.get("executable", "ruff"), |
| 241 | + "ignore": None, |
| 242 | + "line-length": None, |
| 243 | + "per-file-ignores": None, |
| 244 | + "select": None, |
| 245 | + } |
261 | 246 |
|
262 | | - except (tomllib.TOMLDecodeError, OSError) as e: |
263 | | - log.warning(f"Failed loading {str(pyproject_file)}: {e}") |
| 247 | + else: |
| 248 | + # Default values are given by ruff |
| 249 | + settings = { |
| 250 | + "config": _settings.get("config", None), |
| 251 | + "exclude": _settings.get("exclude", None), |
| 252 | + "executable": _settings.get("executable", "ruff"), |
| 253 | + "ignore": _settings.get("ignore", None), |
| 254 | + "line-length": _settings.get("lineLength", None), |
| 255 | + "per-file-ignores": _settings.get("perFileIgnores", None), |
| 256 | + "select": _settings.get("select", None), |
| 257 | + } |
264 | 258 |
|
265 | 259 | return settings |
0 commit comments