You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use file modification times for dirty working directory timestamps
When setuptools-scm encounters a dirty working directory, it now uses
the latest modification time of changed files instead of falling back
to the current timestamp. This provides more meaningful version
timestamps during local development.
Changes:
- Added get_dirty_tag_date() method to Git and Mercurial working directory classes
- Enhanced timestamp logic in parsing functions to prioritize file mtimes
- Updated documentation to explain new timestamp behavior
- Maintains backward compatibility with clean repository behavior
The logic flow is now:
1. Try to get node_date from HEAD commit
2. If that fails AND working directory is dirty, use latest file mtime
3. Only fall back to datetime.now() as last resort
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
303
+
1.**Automatic Discovery**: When building source distributions (`python -m build --sdist`), setuptools automatically calls the `setuptools-scm` file finder
304
+
2.**SCM Integration**: The file finder queries your SCM (Git/Mercurial) for all tracked files
305
+
3.**Inclusion**: All tracked files are automatically included in the sdist
310
306
311
307
#### Controlling file inclusion
312
308
313
-
**Using MANIFEST.in**: You can still use `MANIFEST.in` to override the automatic behavior:
309
+
**To exclude unwanted files:**
314
310
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
311
+
1.**Use `MANIFEST.in`** to exclude specific files/patterns:
3.**Use `.hgignore`** or **Mercurial archive configuration** (for Mercurial repositories)
327
325
328
-
**Example of what gets included automatically**:
326
+
#### Troubleshooting
329
327
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
328
+
**Problem: Unwanted files in my package**
329
+
-✅ **Solution**: Add exclusions to `MANIFEST.in`
330
+
-✅ **Alternative**: Use Git/Mercurial archive configuration
333
331
334
-
#### Troubleshooting
332
+
**Problem: Missing files in package**
333
+
- ✅ **Check**: Are the files tracked in your SCM?
334
+
- ✅ **Solution**: `git add` missing files or override with `MANIFEST.in`
335
335
336
-
**Too many files in your sdist?**
336
+
**Problem: File finder not working**
337
+
- ✅ **Check**: Is setuptools-scm installed in your build environment?
338
+
- ✅ **Check**: Are you in a valid SCM repository?
337
339
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
-
```
340
+
### Timestamps for Local Development Versions
345
341
346
-
**Files missing from your sdist?**
342
+
!!! info "Improved Timestamp Behavior"
347
343
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
-
```
344
+
When your working directory has uncommitted changes (dirty), setuptools-scm now uses the **actual modification time of changed files** instead of the current time for local version schemes like `node-and-date`.
345
+
346
+
**Before**: Dirty working directories always used current time (`now`)
347
+
**Now**: Uses the latest modification time of changed files, falling back to current time only if no changed files are found
348
+
349
+
This provides more stable and meaningful timestamps that reflect when you actually made changes to your code.
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.
353
+
1.**Clean repository**: Uses commit timestamp from SCM
354
+
2.**Dirty repository**: Uses latest modification time of changed files
355
+
3.**Fallback**: Uses current time if no modification times can be determined
358
356
359
-
`MANIFEST.in` may still be used: anything defined there overrides the hook.
360
-
This is mostly useful to exclude files tracked in your SCM from packages,
361
-
although in principle it can be used to explicitly include non-tracked files too.
0 commit comments