Skip to content

Match dotfiles in sdist include/exclude glob patterns - #805

Open
aopv wants to merge 1 commit into
pypa:mainfrom
aopv:fix-sdist-glob-dotfiles-746
Open

Match dotfiles in sdist include/exclude glob patterns#805
aopv wants to merge 1 commit into
pypa:mainfrom
aopv:fix-sdist-glob-dotfiles-746

Conversation

@aopv

@aopv aopv commented Jul 9, 2026

Copy link
Copy Markdown

Summary

Sdist include and exclude patterns were expanded using the stdlib glob module. glob's wildcards do not match files whose names start with a dot, so a recursive pattern such as:

[tool.flit.sdist]
exclude = ["**/*.swp"]

failed to exclude editor swap files like .foo.py.swp from the sdist, even though the docs advertise recursive ** support. As reported in #746, an explicit full path to a dotfile did exclude it, but a ** glob pattern did not, because glob skips dotfiles by default.

Fix

flit_core/flit_core/sdist.py now expands the patterns with pathlib.Path.glob instead of glob.glob(..., recursive=True). Path.glob matches dotfiles by default and preserves the same recursive ** semantics (including matching entries in the base directory). This deliberately avoids glob's include_hidden keyword, which is only available on Python 3.11+, so the fix works on flit_core's minimum supported Python (3.8).

Tests / Verification

  • Extended the inclusion sample fixture with a hidden file doc/subdir/.hidden.swp and an exclude entry doc/**/*.swp, and added an assertion to test_include_exclude that the dotfile is excluded.
  • Confirmed the new assertion fails on the unpatched code (the dotfile was still included) and passes after the fix.
  • Ran the full flit_core test suite (flit_core/tests_core/) plus the top-level tests/test_sdist.py: all green (218 passed, 1 pre-existing skip).
  • Added a doc/history.rst entry.

Disclosure: prepared with AI assistance; reviewed and verified locally.

The sdist include/exclude patterns were expanded with the stdlib glob
module, whose wildcards do not match files whose names start with a dot.
As a result a recursive pattern such as ``exclude = ["**/*.swp"]`` failed
to exclude editor swap files like ``.foo.py.swp`` from the sdist.

Expand the patterns with pathlib.Path.glob instead, which matches
dotfiles by default and keeps the same recursive ``**`` semantics. This
avoids glob's include_hidden option, which is only available on Python
3.11+, so it works on flit_core's minimum supported Python (3.8).

Fixes pypa#746.
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.

1 participant