Skip to content

Commit b070402

Browse files
fix #1115: explicitly document file finder behaviour
1 parent f62c605 commit b070402

File tree

5 files changed

+136
-0
lines changed

5 files changed

+136
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
- reintroduce Python 3.9 entrypoints shim for compatibility
2121
- fix #1136: update customizing.md to fix missing import
2222
- fix #1001: document the missing version schemes and add examples in the docs
23+
- fix #1115: explicitly document file finder behaviour
2324

2425
## v8.3.1
2526

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ files that are managed by the SCM
1717
Unwanted files must be excluded via `MANIFEST.in`
1818
or [configuring Git archive][git-archive-docs].
1919

20+
> **⚠️ Important:** Installing setuptools-scm automatically enables a file finder that includes **all SCM-tracked files** in your source distributions. This can be surprising if you have development files tracked in Git/Mercurial that you don't want in your package. Use `MANIFEST.in` to exclude unwanted files. See the [documentation] for details.
21+
2022
## `pyproject.toml` usage
2123

2224
The preferred way to configure [setuptools-scm] is to author

docs/config.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,66 @@ Callables or other Python objects have to be passed in `setup.py` (via the `use_
152152

153153

154154

155+
## automatic file inclusion
156+
157+
!!! warning "Setuptools File Finder Integration"
158+
159+
`setuptools-scm` automatically registers a setuptools file finder that includes all SCM-tracked files in source distributions. This behavior is **always active** when setuptools-scm is installed, regardless of whether you use it for versioning.
160+
161+
**How it works:**
162+
163+
`setuptools-scm` provides a `setuptools.file_finders` entry point that:
164+
165+
1. Automatically discovers SCM-managed files (Git, Mercurial)
166+
2. Includes them in source distributions (`python -m build --sdist`)
167+
3. Works for `include_package_data = True` in package building
168+
169+
**Entry point registration:**
170+
```toml
171+
[project.entry-points."setuptools.file_finders"]
172+
setuptools_scm = "setuptools_scm._file_finders:find_files"
173+
```
174+
175+
**Files included by default:**
176+
- All files tracked by Git (`git ls-files`)
177+
- All files tracked by Mercurial (`hg files`)
178+
- Includes: source code, documentation, tests, config files, etc.
179+
- Excludes: untracked files, files in `.gitignore`/`.hgignore`
180+
181+
**Controlling inclusion:**
182+
183+
Use `MANIFEST.in` to override the automatic behavior:
184+
185+
```text title="MANIFEST.in"
186+
# Exclude development files
187+
exclude .pre-commit-config.yaml
188+
exclude tox.ini
189+
global-exclude *.pyc __pycache__/
190+
191+
# Exclude entire directories
192+
prune docs/
193+
prune testing/
194+
195+
# Include non-SCM files
196+
include data/important.json
197+
```
198+
199+
**Debugging file inclusion:**
200+
201+
```bash
202+
# List files that will be included
203+
python -m setuptools_scm ls
204+
205+
# Build and inspect sdist contents
206+
python -m build --sdist
207+
tar -tzf dist/package-*.tar.gz
208+
```
209+
210+
!!! note "Cannot be disabled"
211+
212+
The file finder cannot be disabled through configuration - it's automatically active when setuptools-scm is installed. If you need to disable it completely, you must remove setuptools-scm from your build environment (which also means you can't use it for versioning).
213+
214+
155215
## api reference
156216

157217
### constants

docs/index.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ files that are managed by the SCM
1010
Unwanted files must be excluded via `MANIFEST.in`
1111
or [configuring Git archive][git-archive-docs].
1212

13+
!!! warning "Automatic File Inclusion Behavior"
14+
15+
**Important:** Simply installing `setuptools-scm` as a build dependency will automatically enable its file finder, which includes **all SCM-tracked files** in your source distributions. This happens even if you're not using setuptools-scm for versioning.
16+
17+
- ✅ **Expected**: All Git/Mercurial tracked files will be included in your sdist
18+
- ⚠️ **Surprise**: This includes development files, configs, tests, docs, etc.
19+
- 🛠️ **Control**: Use `MANIFEST.in` to exclude unwanted files
20+
21+
See the [File Finder Documentation](usage.md#file-finders-hook-makes-most-of-manifestin-unnecessary) for details.
22+
1323
[git-archive-docs]: usage.md#builtin-mechanisms-for-obtaining-version-numbers
1424

1525
## Basic usage

docs/usage.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,12 @@ be kept in version control. It's strongly recommended to be put into gitignore.
285285

286286
### File finders hook makes most of `MANIFEST.in` unnecessary
287287

288+
!!! warning "Automatic File Inclusion"
289+
290+
**`setuptools-scm` automatically provides a setuptools file finder by default.** This means that when you install setuptools-scm, it will automatically include **all SCM-tracked files** in your source distributions (sdist) without requiring a `MANIFEST.in` file.
291+
292+
This automatic behavior can be surprising if you're not expecting it. The file finder is active as soon as setuptools-scm is installed in your build environment.
293+
288294
`setuptools-scm` implements a [file_finders] entry point
289295
which returns all files tracked by your SCM.
290296
This eliminates the need for a manually constructed `MANIFEST.in` in most cases where this
@@ -293,6 +299,63 @@ would be required when not using `setuptools-scm`, namely:
293299
* To ensure all relevant files are packaged when running the `sdist` command.
294300
* When using [include_package_data] to include package data as part of the `build` or `bdist_wheel`.
295301

302+
#### How it works
303+
304+
The file finder integration works through setuptools' plugin system:
305+
306+
1. **Entry Point Registration**: setuptools-scm registers itself as a file finder via the `setuptools.file_finders` entry point
307+
2. **Automatic Discovery**: When setuptools builds a source distribution, it automatically calls setuptools-scm to get the list of files
308+
3. **SCM Integration**: setuptools-scm queries your SCM (Git, Mercurial) to get all tracked files
309+
4. **File Inclusion**: All SCM-tracked files are automatically included in the sdist
310+
311+
#### Controlling file inclusion
312+
313+
**Using MANIFEST.in**: You can still use `MANIFEST.in` to override the automatic behavior:
314+
315+
- **Exclude files**: Use `global-exclude` or `exclude` to remove files that are SCM-tracked but shouldn't be in the package
316+
- **Include additional files**: Use `include` to add files that aren't SCM-tracked
317+
318+
```text title="MANIFEST.in"
319+
# Exclude development files
320+
exclude *.nix
321+
exclude .pre-commit-config.yaml
322+
global-exclude *.pyc
323+
324+
# Include additional files not in SCM
325+
include data/special-file.dat
326+
```
327+
328+
**Example of what gets included automatically**:
329+
330+
- All files tracked by Git/Mercurial in your repository
331+
- Includes source code, data files, documentation, etc.
332+
- Excludes untracked files and files ignored by your SCM
333+
334+
#### Troubleshooting
335+
336+
**Too many files in your sdist?**
337+
338+
1. Check what's being included: `python -m setuptools_scm ls`
339+
2. Use `MANIFEST.in` to exclude unwanted files:
340+
```text
341+
exclude development-file.txt
342+
global-exclude *.log
343+
prune unnecessary-directory/
344+
```
345+
346+
**Files missing from your sdist?**
347+
348+
1. Ensure files are tracked by your SCM: `git add` or `hg add`
349+
2. For non-SCM files, add them via `MANIFEST.in`:
350+
```text
351+
include important-file.txt
352+
recursive-include data *.json
353+
```
354+
355+
**Disable automatic file finding** (not recommended):
356+
357+
If you need to completely disable setuptools-scm's file finder (not recommended), you would need to uninstall setuptools-scm from your build environment and handle versioning differently.
358+
296359
`MANIFEST.in` may still be used: anything defined there overrides the hook.
297360
This is mostly useful to exclude files tracked in your SCM from packages,
298361
although in principle it can be used to explicitly include non-tracked files too.

0 commit comments

Comments
 (0)