Skip to content

Remove empty default build tree left behind by bdist_wheel - #5308

Open
CAOShurong wants to merge 1 commit into
pypa:mainfrom
CAOShurong:codex/5134-clean-build-tree
Open

CAOShurong wants to merge 1 commit into
pypa:mainfrom
CAOShurong:codex/5134-clean-build-tree

Conversation

@CAOShurong

Copy link
Copy Markdown

Summary

Fixes #5134 (the build/bdist.* leftover part — the separate egg-info question discussed in that issue is out of scope here).

With the default options, a wheel build leaves an empty directory chain behind:

$ python -m build --wheel
$ tree -d
.
├── build
│   └── bdist.win-amd64   <-- empty
└── dist

The cause: bdist_wheel removes only its own scratch directory (bdist_dir = build/bdist.<plat>/wheel), so the parent directories it created along the way survive as empty shells.

Change

After removing bdist_dir, prune directories that are still empty walking up the default chain ([build] build_basebdist.<plat>). The pruning stops at the first non-empty directory and is guarded on both sides:

  • a user-supplied --bdist-dir (anything other than the default <bdist_base>/wheel) is never touched;
  • a customized [build] build_base disables pruning entirely.

A non-empty build/ containing real artifacts (e.g. from build_ext) is preserved as before.

Testing

  • New tests in setuptools/tests/test_bdist_wheel.py:
    • test_bdist_base_removed_when_empty: default build leaves no build/ behind (verified RED without the fix: 1 failed);
    • test_bdist_base_preserved_when_not_empty (parametrized): custom --bdist-dir, plus stale file / subdirectory left inside the base — never removed.
  • Full suite: 32 passed, 2 skipped on current main.
  • End-to-end reproduction of the issue scenario with python -m build --wheel: before the fix build/ + build/bdist.win-amd64 remain; after the fix only dist/ remains.

With the default options a wheel build leaves an empty 'build/bdist.*'
chain behind because bdist_wheel removes only its own scratch directory.
Prune any directories that are still empty along the *default* chain
(build_base -> bdist.plat -> wheel) after removing bdist_dir, so
'python -m build --wheel' no longer litters the project root with an
empty 'build/' tree (pypa#5134).

User-supplied --bdist-dir values and a customized [build] build_base are
never touched.
@mergify

mergify Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] build --wheel leaves unnecessary files

1 participant