Skip to content

Commit 590cecc

Browse files
authored
Merge pull request #4 from aci2n/allow_known_section_config
Allow configuration for known sections
2 parents deb5f47 + d4ce8c9 commit 590cecc

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

pylsp_isort/plugin.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from typing import Any, Dict, Generator, Optional, TypedDict, Union
55

66
import isort
7+
from isort.settings import KNOWN_PREFIX
78
from pylsp import hookimpl
89
from pylsp.config.config import Config
910
from pylsp.workspace import Document
@@ -89,7 +90,7 @@ def isort_config(
8990

9091
defined_args = set(getattr(isort.Config, "__dataclass_fields__", {}).keys())
9192
for key, value in settings.items():
92-
if key in defined_args:
93+
if key in defined_args or key.startswith(KNOWN_PREFIX):
9394
config_kwargs[key] = value
9495
else:
9596
unsupported_kwargs[key] = value

tests/test_plugin.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,20 @@ def test_run_isort(text, settings, expected):
7272
isort.Config(profile="black"),
7373
False,
7474
),
75+
(
76+
{
77+
"sections": ["FUTURE", "SECTION_A", "SECTION_B"],
78+
"known_section_a": ["module_a"],
79+
"known_section_b": ["module_b"],
80+
},
81+
None,
82+
isort.Config(
83+
sections=["FUTURE", "SECTION_A", "SECTION_B"],
84+
known_section_a=["module_a"],
85+
known_section_b=["module_b"],
86+
),
87+
True,
88+
),
7589
],
7690
)
7791
def test_isort_config(settings, target_path, expected, check_sources):

0 commit comments

Comments
 (0)