Skip to content

Commit

Permalink
Fixed #1819: Occasional inconsistency with multiple src paths.
Browse files Browse the repository at this point in the history
  • Loading branch information
timothycrosley committed Nov 9, 2021
1 parent dbd1842 commit ca08411
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
5 changes: 3 additions & 2 deletions isort/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,13 +458,14 @@ def __init__(
if "src_paths" not in combined_config:
combined_config["src_paths"] = (path_root / "src", path_root)
else:
src_paths: Set[Path] = set()
src_paths: List[Path] = []
for src_path in combined_config.get("src_paths", ()):
full_paths = (
path_root.glob(src_path) if "*" in str(src_path) else [path_root / src_path]
)
for path in full_paths:
src_paths.add(path)
if not path in src_paths:
src_paths.append(path)

combined_config["src_paths"] = tuple(src_paths)

Expand Down
44 changes: 44 additions & 0 deletions tests/unit/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1345,3 +1345,47 @@ def test_multiple_configs(capsys, tmpdir):
_, err = capsys.readouterr()

assert f"{str(file6)} Imports are incorrectly sorted and/or formatted" in err


def test_multiple_src_paths(tmpdir, capsys):
"""
Ensure that isort has consistent behavior with multiple source paths
"""

tests_module = tmpdir / "tests"
app_module = tmpdir / "app"

tests_module.mkdir()
app_module.mkdir()

pyproject_toml = tmpdir / "pyproject.toml"
pyproject_toml.write_text(
"""
[tool.isort]
profile = "black"
src_paths = ["app", "tests"]
auto_identify_namespace_packages = false
""",
"utf-8",
)
file = tmpdir / "file.py"
file.write_text(
"""
from app.something import something
from tests.something import something_else
""",
"utf-8",
)

for _ in range(10): # To ensure isort has consistent results in multiple runs
main.main([str(tmpdir), "--verbose"])
out, _ = capsys.readouterr()

assert (
file.read()
== """
from app.something import something
from tests.something import something_else
"""
)
assert "from-type place_module for tests.something returned FIRSTPARTY" in out

0 comments on commit ca08411

Please sign in to comment.