Skip to content

implement documentation fixups #1153

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jul 26, 2025

Conversation

RonnyPfannschmidt
Copy link
Contributor

@RonnyPfannschmidt RonnyPfannschmidt commented Jul 24, 2025

closes #1001
closes #1115
closes #1099

anger addressing 1022 due to errors

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
Create get_latest_file_mtime() helper function in scm_workdir.py to eliminate
code duplication across Git, Mercurial, and hybrid implementations.

Changes:
- Added get_latest_file_mtime() function to scm_workdir.py
- Updated GitWorkdir.get_dirty_tag_date() to use shared helper
- Updated HgWorkdir.get_dirty_tag_date() to use shared helper
- Updated GitWorkdirHgClient.get_dirty_tag_date() to use shared helper
- Removed duplicated mtime calculation logic from all implementations
- Cleaned up unused imports (datetime/timezone in hg_git.py)

This improves maintainability and ensures consistent behavior across
all VCS implementations.
Break down the complex get_meta method into smaller, focused helper methods
to improve readability and reduce cyclomatic complexity below the linting
threshold.

Changes:
- Extract _get_node_info() for getting node/tags/date from hg log
- Extract _get_branch_info() for getting branch/dirty status
- Extract _get_node_date() for determining appropriate node date
- Extract _is_initial_node() for checking empty repository state
- Extract _create_initial_meta() for creating initial repository metadata
- Extract _parse_tags() for filtering and processing tags
- Extract _get_version_from_tags() for converting tags to versions
- Extract _get_distance_based_version() for distance-based versioning
- Fix type safety by properly handling None from tag_to_version

Each helper method has a single responsibility and clear documentation.
The main get_meta method now has a clear, linear flow that's easy to follow.
Complexity reduced from 11 to under the 10 threshold.
@RonnyPfannschmidt RonnyPfannschmidt merged commit 5f517fa into pypa:main Jul 26, 2025
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant