From 9a4da5fe559db5701e6364c1e8911c8fde75695e Mon Sep 17 00:00:00 2001 From: Timothy Crosley Date: Mon, 28 Sep 2020 22:55:17 -0700 Subject: [PATCH 1/4] Add Pyramid project to isort integration tests --- tests/integration/test_projects_using_isort.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/integration/test_projects_using_isort.py b/tests/integration/test_projects_using_isort.py index 325498860..2dd5ee62c 100644 --- a/tests/integration/test_projects_using_isort.py +++ b/tests/integration/test_projects_using_isort.py @@ -127,3 +127,11 @@ def test_attrs(tmpdir): def test_datadog_integrations_core(tmpdir): git_clone("https://github.com/DataDog/integrations-core.git", tmpdir) run_isort([str(tmpdir)]) + + +def test_pyramid(tmpdir): + git_clone("https://github.com/Pylons/pyramid.git", tmpdir) + run_isort( + str(target_dir) + for target_dir in (tmpdir / "src" / "pyramid", tmpdir / "tests", tmpdir / "setup.py") + ) From a8da08a6cf3bff12ce1668c5f4f99710317e42f0 Mon Sep 17 00:00:00 2001 From: Timothy Crosley Date: Mon, 28 Sep 2020 23:03:19 -0700 Subject: [PATCH 2/4] Add unit test case for desired placement behavior --- tests/unit/test_place.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/unit/test_place.py b/tests/unit/test_place.py index cc231d5f5..b1159471f 100644 --- a/tests/unit/test_place.py +++ b/tests/unit/test_place.py @@ -20,3 +20,10 @@ def test_extra_standard_library(src_path): ) assert place_tester("os") == sections.STDLIB assert place_tester("hug") == sections.STDLIB + + +def test_no_standard_library_placement(): + assert place.module_with_reason( + "pathlib", config=Config(sections=["THIRDPARTY"], default_section="THIRDPARTY") + ) == ("THIRDPARTY", "Default option in Config or universal default.") + assert place.module("pathlib") == "STDLIB" From 012b080df9fce9e3d645680b94b8c18c092b1211 Mon Sep 17 00:00:00 2001 From: Timothy Crosley Date: Mon, 28 Sep 2020 23:04:04 -0700 Subject: [PATCH 3/4] Improve placement logic to ensure it takes into account the case where known leads to non existant section --- isort/place.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/isort/place.py b/isort/place.py index 34b2eeb86..117428aeb 100644 --- a/isort/place.py +++ b/isort/place.py @@ -54,7 +54,7 @@ def _known_pattern(name: str, config: Config) -> Optional[Tuple[str, str]]: module_names_to_check = (".".join(parts[:first_k]) for first_k in range(len(parts), 0, -1)) for module_name_to_check in module_names_to_check: for pattern, placement in config.known_patterns: - if pattern.match(module_name_to_check): + if placement in config.sections and pattern.match(module_name_to_check): return (placement, f"Matched configured known pattern {pattern}") return None From 1466a4bd03cce569da0eccdae43c9d2f10562203 Mon Sep 17 00:00:00 2001 From: Timothy Crosley Date: Mon, 28 Sep 2020 23:05:14 -0700 Subject: [PATCH 4/4] Mark Fixed #1505: Support case where known_SECTION points to a section not listed in sections. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 68d114f3a..6f40c3fde 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ Find out more about isort's release policy [here](https://pycqa.github.io/isort/ - Fixed #1482: pylama integration is not working correctly out-of-the-box. - Fixed #1492: --check does not work with stdin source. - Fixed #1499: isort gets confused by single line, multi-line style comments when using float-to-top. + - Fixed #1505: Support case where known_SECTION points to a section not listed in sections. ### 5.5.3 [Hotfix] September 20, 2020 - Fixed #1488: in rare cases isort can mangle `yield from` or `raise from` statements.