Skip to content

Commit 316ec94

Browse files
fix: ignore build dir automatically (#916)
See #914. --------- Signed-off-by: Henry Schreiner <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent f43f047 commit 316ec94

File tree

5 files changed

+18
-1
lines changed

5 files changed

+18
-1
lines changed

src/scikit_build_core/build/_file_processor.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def each_unignored_file(
3232
starting_path: Path,
3333
include: Sequence[str] = (),
3434
exclude: Sequence[str] = (),
35+
build_dir: str = "",
3536
) -> Generator[Path, None, None]:
3637
"""
3738
Runs through all non-ignored files. Must be run from the root directory.
@@ -50,9 +51,20 @@ def each_unignored_file(
5051
if p != Path(".gitignore")
5152
}
5253

54+
exclude_build_dir = build_dir.format(
55+
cache_tag="*",
56+
wheel_tag="*",
57+
build_type="*",
58+
state="*",
59+
)
60+
61+
exclude_lines = (
62+
[*EXCLUDE_LINES, exclude_build_dir] if exclude_build_dir else EXCLUDE_LINES
63+
)
64+
5365
user_exclude_spec = pathspec.GitIgnoreSpec.from_lines(list(exclude))
5466
global_exclude_spec = pathspec.GitIgnoreSpec.from_lines(global_exclude_lines)
55-
builtin_exclude_spec = pathspec.GitIgnoreSpec.from_lines(EXCLUDE_LINES)
67+
builtin_exclude_spec = pathspec.GitIgnoreSpec.from_lines(exclude_lines)
5668

5769
include_spec = pathspec.GitIgnoreSpec.from_lines(include)
5870

src/scikit_build_core/build/_pathutil.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def packages_to_file_mapping(
4141
include: Sequence[str],
4242
src_exclude: Sequence[str],
4343
target_exclude: Sequence[str],
44+
build_dir: str,
4445
) -> dict[str, str]:
4546
"""
4647
This will output a mapping of source files to target files.
@@ -55,6 +56,7 @@ def packages_to_file_mapping(
5556
source_dir,
5657
include=include,
5758
exclude=src_exclude,
59+
build_dir=build_dir,
5860
):
5961
rel_path = filepath.relative_to(source_dir)
6062
target_path = platlib_dir / package_dir / rel_path

src/scikit_build_core/build/sdist.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ def build_sdist(
154154
Path(),
155155
include=settings.sdist.include,
156156
exclude=settings.sdist.exclude,
157+
build_dir=settings.build_dir,
157158
)
158159
)
159160
for filepath in paths:

src/scikit_build_core/build/wheel.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ def _build_wheel_impl_impl(
467467
include=settings.sdist.include,
468468
src_exclude=settings.sdist.exclude,
469469
target_exclude=settings.wheel.exclude,
470+
build_dir=settings.build_dir,
470471
)
471472

472473
if not editable:

tests/test_editable_unit.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ def test_navigate_editable_pkg(editable_package: EditablePackage, virtualenv: VE
141141
include=[],
142142
src_exclude=[],
143143
target_exclude=[],
144+
build_dir="",
144145
)
145146
assert mapping == {
146147
str(Path("pkg/__init__.py")): str(pkg_dir / "__init__.py"),

0 commit comments

Comments
 (0)