Skip to content

Commit ca08411

Browse files
Fixed #1819: Occasional inconsistency with multiple src paths.
1 parent dbd1842 commit ca08411

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

isort/settings.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,13 +458,14 @@ def __init__(
458458
if "src_paths" not in combined_config:
459459
combined_config["src_paths"] = (path_root / "src", path_root)
460460
else:
461-
src_paths: Set[Path] = set()
461+
src_paths: List[Path] = []
462462
for src_path in combined_config.get("src_paths", ()):
463463
full_paths = (
464464
path_root.glob(src_path) if "*" in str(src_path) else [path_root / src_path]
465465
)
466466
for path in full_paths:
467-
src_paths.add(path)
467+
if not path in src_paths:
468+
src_paths.append(path)
468469

469470
combined_config["src_paths"] = tuple(src_paths)
470471

tests/unit/test_main.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,3 +1345,47 @@ def test_multiple_configs(capsys, tmpdir):
13451345
_, err = capsys.readouterr()
13461346

13471347
assert f"{str(file6)} Imports are incorrectly sorted and/or formatted" in err
1348+
1349+
1350+
def test_multiple_src_paths(tmpdir, capsys):
1351+
"""
1352+
Ensure that isort has consistent behavior with multiple source paths
1353+
"""
1354+
1355+
tests_module = tmpdir / "tests"
1356+
app_module = tmpdir / "app"
1357+
1358+
tests_module.mkdir()
1359+
app_module.mkdir()
1360+
1361+
pyproject_toml = tmpdir / "pyproject.toml"
1362+
pyproject_toml.write_text(
1363+
"""
1364+
[tool.isort]
1365+
profile = "black"
1366+
src_paths = ["app", "tests"]
1367+
auto_identify_namespace_packages = false
1368+
""",
1369+
"utf-8",
1370+
)
1371+
file = tmpdir / "file.py"
1372+
file.write_text(
1373+
"""
1374+
from app.something import something
1375+
from tests.something import something_else
1376+
""",
1377+
"utf-8",
1378+
)
1379+
1380+
for _ in range(10): # To ensure isort has consistent results in multiple runs
1381+
main.main([str(tmpdir), "--verbose"])
1382+
out, _ = capsys.readouterr()
1383+
1384+
assert (
1385+
file.read()
1386+
== """
1387+
from app.something import something
1388+
from tests.something import something_else
1389+
"""
1390+
)
1391+
assert "from-type place_module for tests.something returned FIRSTPARTY" in out

0 commit comments

Comments
 (0)