Skip to content

Commit adf34bf

Browse files
authored
fix: follow symlinks when making SDists (#362)
Fixing #359. --------- Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
1 parent aaa01af commit adf34bf

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

src/scikit_build_core/build/_file_processor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def each_unignored_file(
4141
exclude_spec = pathspec.GitIgnoreSpec.from_lines(exclude_lines)
4242
include_spec = pathspec.GitIgnoreSpec.from_lines(include)
4343

44-
for dirpath, _, filenames in os.walk(str(starting_path)):
44+
for dirpath, _, filenames in os.walk(str(starting_path), followlinks=True):
4545
all_paths = (Path(dirpath) / fn for fn in filenames)
4646
paths = (
4747
p

tests/test_file_processor.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
from __future__ import annotations
2+
3+
import sys
4+
from pathlib import Path
5+
6+
import pytest
7+
8+
from scikit_build_core.build._file_processor import each_unignored_file
9+
10+
11+
@pytest.mark.skipif(
12+
sys.version_info < (3, 8) and sys.platform.startswith("win"),
13+
reason="Python 3.8+ required for symlinks on Windows",
14+
)
15+
@pytest.mark.skipif(
16+
sys.implementation.name == "pypy" and sys.platform.startswith("win"),
17+
reason="PyPy on Windows does not support symlinks",
18+
)
19+
def test_on_each_with_symlink(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
20+
"""
21+
Test that each_unignored_file() does not follow symlinks.
22+
"""
23+
monkeypatch.chdir(tmp_path)
24+
# Set up a gitignore
25+
gitignore = Path(".gitignore")
26+
gitignore.write_text("/hidden_dir")
27+
# Create a directory with a symlink to a file in the same directory
28+
dir = Path("dir")
29+
dir.mkdir()
30+
file1 = dir / "file"
31+
file1.write_text("content")
32+
file2 = dir / "link"
33+
file2.symlink_to("file")
34+
hidden_dir = Path("hidden_dir")
35+
hidden_dir.mkdir()
36+
hidden_file = hidden_dir / "file2"
37+
hidden_file.write_text("content2")
38+
exposed_symlink = dir / "exposed_symlink"
39+
exposed_symlink.symlink_to("../hidden_dir")
40+
41+
if (
42+
sys.platform.startswith("win")
43+
and not exposed_symlink.joinpath("file2").is_file()
44+
):
45+
pytest.skip("Windows symlink support not available")
46+
47+
# Test that each_unignored_file() follows the symlink
48+
assert sorted(each_unignored_file(Path("."))) == [
49+
gitignore,
50+
exposed_symlink / "file2",
51+
file1,
52+
file2,
53+
]

0 commit comments

Comments
 (0)