summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimothy Crosley <timothy.crosley@gmail.com>2020-02-16 23:05:12 -0800
committerTimothy Crosley <timothy.crosley@gmail.com>2020-02-16 23:05:12 -0800
commitdf6bf35e8d6da1ca1cb46906b2bd277930fb33ef (patch)
tree5940afd20c9d048fafbc5e625b7c3fde94c726ab
parent85af5fa8921642edc661099c8e2afdd7e14dc170 (diff)
downloadisort-issue/830-editorconfig-section.tar.gz
Fix issue #830: Improve compatibility with editor config, including *.{ sectionsissue/830-editorconfig-section
-rw-r--r--isort/settings.py14
-rw-r--r--tests/test_isort.py2
2 files changed, 13 insertions, 3 deletions
diff --git a/isort/settings.py b/isort/settings.py
index 9cdd6c77..8df49461 100644
--- a/isort/settings.py
+++ b/isort/settings.py
@@ -56,12 +56,13 @@ CONFIG_SOURCES: Tuple[str, ...] = (
"tox.ini",
".editorconfig",
)
+
CONFIG_SECTIONS: Dict[str, Tuple[str, ...]] = {
".isort.cfg": ("settings", "isort"),
"pyproject.toml": ("tool.isort",),
"setup.cfg": ("isort", "tool:isort"),
"tox.ini": ("isort", "tool:isort"),
- ".editorconfig": ("*", "*.py", "**.py"),
+ ".editorconfig": ("*", "*.py", "**.py", "*.{py}"),
}
FALLBACK_CONFIG_SECTIONS: Tuple[str, ...] = ("isort", "tool:isort", "tool.isort")
FALLBACK_CONFIGS: Tuple[str, ...]
@@ -426,7 +427,16 @@ def _get_config_data(file_path: str, sections: Iterable[str]) -> Dict[str, Any]:
config = configparser.ConfigParser(strict=False)
config.read_file(config_file)
for section in sections:
- if config.has_section(section):
+ if section.startswith("*.{") and section.endswith("}"):
+ extension = section[len("*.{") : -1]
+ for config_key in config.keys():
+ if config_key.startswith("*.{") and config_key.endswith("}"):
+ if extension in map(
+ lambda text: text.strip(), config_key[len("*.{") : -1].split(",")
+ ):
+ settings.update(config.items(config_key))
+
+ elif config.has_section(section):
settings.update(config.items(section))
if settings:
diff --git a/tests/test_isort.py b/tests/test_isort.py
index 8a53973c..7f6d399a 100644
--- a/tests/test_isort.py
+++ b/tests/test_isort.py
@@ -25,7 +25,7 @@ except ImportError:
toml = None
TEST_DEFAULT_CONFIG = """
-[*.py]
+[*.{py,pyi}]
max_line_length = 120
indent_style = space
indent_size = 4