Skip to content

Improve pyproject_versions.py with version coherence checking#905

Merged
benoit-cty merged 7 commits into
masterfrom
copilot/fix-904
Sep 20, 2025
Merged

Improve pyproject_versions.py with version coherence checking#905
benoit-cty merged 7 commits into
masterfrom
copilot/fix-904

Conversation

Copilot AI commented Jul 13, 2025

Copy link
Copy Markdown
Contributor

Enhanced the .github/pyproject_versions.py script to address version coherence issues and prevent manual version bumps that forget to use bumpver.

Problem

The original issue identified a need to check version coherence between files managed by bumpver to avoid manual bumps that forget to use the proper versioning tool. The three files that should always have synchronized versions are:

  • codecarbon/_version.py
  • docs/edit/conf.py
  • pyproject.toml

Solution

Added comprehensive version coherence checking functionality:

New Features

  • Version coherence validation: Automatically checks that all three bumpver-managed files have consistent versions
  • New CLI option: --check_coherence for standalone coherence validation
  • Automatic prevention: All operations now validate version coherence before proceeding
  • Clear error reporting: Detailed messages identify which files have inconsistent versions

Key Functions Added

def get_version_from_file(filepath: str, pattern: str) -> str:
    """Extract version from a file using regex patterns"""

def get_all_versions() -> dict:
    """Read versions from all three bumpver-managed files"""

def check_version_coherence() -> bool:
    """Validate version consistency across files"""

Usage Examples

# Check version coherence only
python .github/pyproject_versions.py --check_coherence

# Normal operations now include automatic coherence checking
python .github/pyproject_versions.py --replace True

Error Prevention

When versions are inconsistent, the script now:

  • Displays clear error messages showing which files have different versions
  • Prevents operations that could lead to further inconsistencies
  • Guides users to use 'bumpver' for consistent version updates

Example output for inconsistent versions:

✗ Version coherence check failed! Versions are inconsistent:
  pyproject.toml [tool.bumpver] current_version: 3.0.3
  codecarbon/_version.py __version__: 3.0.4
  docs/edit/conf.py release: 3.0.3

Please use 'bumpver' to update versions consistently across all files.

Backward Compatibility

  • All existing functionality preserved
  • CI workflows continue to work unchanged
  • Fixed existing bug in --only_package_version output (was referencing wrong variable)

The improvements ensure that version coherence is maintained across all bumpver-managed files and help prevent the manual version update issues described in the original issue.

Fixes #904.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Improve pyproject_versions.py Improve pyproject_versions.py with version coherence checking Jul 13, 2025
Copilot AI requested a review from benoit-cty July 13, 2025 14:53
@benoit-cty benoit-cty marked this pull request as ready for review September 10, 2025 06:55

@SaboniAmine SaboniAmine left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks Benoît!

Comment thread .github/pyproject_versions.py Outdated
@benoit-cty benoit-cty merged commit 6546c74 into master Sep 20, 2025
11 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

Development

Successfully merging this pull request may close these issues.

Improve pyproject_versions.py

3 participants