From 9c0ff4952bc3a2e8dc605e88815c6e5662b81f8d Mon Sep 17 00:00:00 2001 From: Timothy Crosley Date: Thu, 8 Oct 2020 05:11:22 -0700 Subject: [PATCH] Hotfix: Fixed #1546: Unstable (non-idempotent) behavior with certain src trees. --- CHANGELOG.md | 3 +++ isort/_version.py | 2 +- isort/place.py | 5 ++++- isort/settings.py | 14 +++++++++----- pyproject.toml | 2 +- tests/integration/test_projects_using_isort.py | 5 +++++ 6 files changed, 23 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 595033f32..02bb467f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ Changelog NOTE: isort follows the [semver](https://semver.org/) versioning standard. Find out more about isort's release policy [here](https://pycqa.github.io/isort/docs/major_releases/release_policy/). +### 5.6.1 [Hotfix] October 8, 2020 + - Fixed #1546: Unstable (non-idempotent) behavior with certain src trees. + ### 5.6.0 October 7, 2020 - Implemented #1433: Provide helpful feedback in case a custom config file is specified without a configuration. - Implemented #1494: Default to sorting imports within `.pxd` files. diff --git a/isort/_version.py b/isort/_version.py index a1e2271ea..a23647501 100644 --- a/isort/_version.py +++ b/isort/_version.py @@ -1 +1 @@ -__version__ = "5.6.0" +__version__ = "5.6.1" diff --git a/isort/place.py b/isort/place.py index c85cf83b6..aaf954aa8 100644 --- a/isort/place.py +++ b/isort/place.py @@ -117,7 +117,10 @@ def _is_namespace_package(path: Path, src_extensions: FrozenSet[str]) -> bool: init_file = path / "__init__.py" if not init_file.exists(): filenames = [ - filename for filename in path.iterdir() if filename.suffix.lstrip(".") in src_extensions + filepath + for filepath in path.iterdir() + if filepath.suffix.lstrip(".") in src_extensions + or filepath.name.lower() in ("setup.cfg", "pyproject.toml") ] if filenames: return False diff --git a/isort/settings.py b/isort/settings.py index e80a989dc..158aa36ca 100644 --- a/isort/settings.py +++ b/isort/settings.py @@ -182,7 +182,7 @@ class _Config: directory: str = "" profile: str = "" honor_noqa: bool = False - src_paths: FrozenSet[Path] = frozenset() + src_paths: Tuple[Path, ...] = tuple() old_finders: bool = False remove_redundant_aliases: bool = False float_to_top: bool = False @@ -401,11 +401,15 @@ def __init__( path_root = Path(combined_config.get("directory", project_root)).resolve() path_root = path_root if path_root.is_dir() else path_root.parent if "src_paths" not in combined_config: - combined_config["src_paths"] = frozenset((path_root, path_root / "src")) + combined_config["src_paths"] = (path_root / "src", path_root) else: - combined_config["src_paths"] = frozenset( - path_root / path for path in combined_config.get("src_paths", ()) - ) + src_paths: List[Path] = [] + for src_path in combined_config.get("src_paths", ()): + full_path = path_root / src_path + if full_path not in src_paths: + src_paths.append(full_path) + + combined_config["src_paths"] = tuple(src_paths) if "formatter" in combined_config: import pkg_resources diff --git a/pyproject.toml b/pyproject.toml index 8831e38c2..81d45cc27 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,7 +3,7 @@ line-length = 100 [tool.poetry] name = "isort" -version = "5.6.0" +version = "5.6.1" description = "A Python utility / library to sort Python imports." authors = ["Timothy Crosley "] license = "MIT" diff --git a/tests/integration/test_projects_using_isort.py b/tests/integration/test_projects_using_isort.py index 95f256b29..d39b942b3 100644 --- a/tests/integration/test_projects_using_isort.py +++ b/tests/integration/test_projects_using_isort.py @@ -140,3 +140,8 @@ def test_pyramid(tmpdir): def test_products_zopetree(tmpdir): git_clone("https://github.com/jugmac00/Products.ZopeTree.git", tmpdir) run_isort([str(tmpdir)]) + + +def test_dobby(tmpdir): + git_clone("https://github.com/rocketDuck/dobby.git", tmpdir) + run_isort([str(tmpdir / "tests"), str(tmpdir / "src")])