Skip to content

Commit deb5f47

Browse files
committed
Update configuration priority.
1 parent a5ded4d commit deb5f47

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ These are the valid configuration keys:
1818
- `pylsp.plugins.isort.enabled`: boolean to enable/disable the plugin. `true` by default.
1919
- `pylsp.plugins.isort.*`: any other key-value pair under `pylsp.plugins.isort` is passed to `isort.settings.Config`. See the [reference](https://pycqa.github.io/isort/reference/isort/settings.html#config) for details.
2020

21-
Note that any configurations passed to isort via `pylsp` will override the settings in a config file, such as `pyproject.toml`.
21+
Note that any configurations passed to isort via `pylsp` are ignored when isort detects a config file, such as `pyproject.toml`.

pylsp_isort/plugin.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,19 @@ def isort_config(
103103
else:
104104
config_kwargs["settings_path"] = os.path.abspath(settings["settings_path"])
105105
elif target_path:
106-
config_kwargs["settings_path"] = os.path.abspath(target_path)
107-
if not os.path.isdir(config_kwargs["settings_path"]):
108-
config_kwargs["settings_path"] = os.path.dirname(
109-
config_kwargs["settings_path"]
106+
settings_path = os.path.abspath(target_path)
107+
if not os.path.isdir(settings_path):
108+
settings_path = os.path.dirname(settings_path)
109+
110+
_, found_settings = isort.settings._find_config(settings_path)
111+
if found_settings:
112+
logger.info(
113+
"Found a config file: `%s`, skipping given settings.",
114+
found_settings["source"],
110115
)
116+
config_kwargs = {}
117+
118+
config_kwargs["settings_path"] = settings_path
111119

112120
logger.debug("config_kwargs=%r", config_kwargs)
113121
if unsupported_kwargs:

tests/test_plugin.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ def test_run_isort(text, settings, expected):
6666
isort.Config(profile="black"),
6767
False,
6868
),
69+
(
70+
{"profile": "django"},
71+
__file__,
72+
isort.Config(profile="black"),
73+
False,
74+
),
6975
],
7076
)
7177
def test_isort_config(settings, target_path, expected, check_sources):

0 commit comments

Comments
 (0)