Skip to content

Conversation

Kangyan-Zhou
Copy link
Collaborator

@Kangyan-Zhou Kangyan-Zhou commented Oct 18, 2025

The script previously failed to update pyproject_xpu.toml and pyproject_cpu.toml because it used simple string replacement that only worked when files contained the exact current version.

This ensures all platform-specific pyproject files stay synchronized regardless of their current version state.

Tested in #11802

The script previously failed to update pyproject_xpu.toml and
pyproject_cpu.toml because it used simple string replacement that
only worked when files contained the exact current version.

Changes:
- Update replace_in_file() to use regex for TOML files, matching
  the version field pattern instead of exact version string
- Add validation at end of bump_version() to verify all files were
  updated correctly, failing if any file doesn't contain new version
- Keep backward compatibility for non-TOML files

This ensures all platform-specific pyproject files stay synchronized
regardless of their current version state.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copy link
Contributor

Summary of Changes

Hello @Kangyan-Zhou, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the reliability of the version bumping script by introducing more robust handling for TOML configuration files. It specifically addresses an issue where the script failed to update pyproject files if their existing version string didn't precisely match the expected old_version. The update incorporates regular expressions for TOML files to ensure flexible version matching and adds a critical post-update validation step to confirm that all target files have been correctly updated, thereby ensuring consistent version synchronization across the codebase.

Highlights

  • Improved TOML File Version Bumping: The replace_in_file function has been updated to use regular expressions for .toml files. This change allows the script to correctly update the version field in TOML files, even if their current version string does not exactly match the old_version parameter, addressing previous failures with pyproject_xpu.toml and pyproject_cpu.toml.
  • Added Version Update Validation: A new validation step has been introduced at the end of the bump_version function. This step verifies that all specified files successfully contain the new_version after the update, and the script will exit with an error if any file fails this check, ensuring data integrity.
  • Maintained Backward Compatibility: The changes ensure that simple string replacement logic is still used for non-TOML files, preserving existing functionality while enhancing handling for TOML-specific version fields.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@Kangyan-Zhou Kangyan-Zhou changed the title Fix version bump script to handle TOML files with outdated versions [WIP] Fix version bump script to handle TOML files with outdated versions Oct 18, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request enhances the version bumping script to correctly handle TOML files and adds validation to ensure all specified files are updated. The changes include using regex for TOML files to match the version field and adding a validation step to verify that all files contain the new version after the update. This ensures that platform-specific pyproject files stay synchronized regardless of their current version state.

continue # Skip non-existent files (already warned above)

content = file_abs.read_text()
if new_version not in content:
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The validation check if new_version not in content: is too simple. It's possible that the new_version string appears elsewhere in the file. It would be more robust to use a regex to specifically check the version field in the TOML file, similar to how it's done in replace_in_file function.

if file_abs.suffix == ".toml":
    pattern = r'(version\s*=\s*)(["']?)([^"'\n]+)(["']?)'
    if not re.search(pattern, content.replace(new_version, rf"\g<1>{new_version}\g<2>")):
        failed_files.append(file_rel)
        print(f"✗ {file_rel} does not contain version {new_version}")
else:
    if new_version not in content:
        failed_files.append(file_rel)
        print(f"✗ {file_rel} does not contain version {new_version}")

# For TOML files, use regex to match version field regardless of current value
if file_path.suffix == ".toml":
# Match: version = "X.Y.Z..." (with optional quotes and whitespace)
pattern = r'(version\s*=\s*["\'])([^"\']+)(["\'])'
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The regex pattern r'(version\s*=\s*[""])([^""]+)([""])' could be improved to be more robust. Currently, it only matches double or single quotes but might fail if the TOML file has a different quote style or no quotes at all. Consider allowing no quotes or other quote types (e.g., single quotes).

pattern = r'(version\s*=\s*)(["']?)([^"'\n]+)(["']?)'

if file_path.suffix == ".toml":
# Match: version = "X.Y.Z..." (with optional quotes and whitespace)
pattern = r'(version\s*=\s*["\'])([^"\']+)(["\'])'
new_content = re.sub(pattern, rf"\g<1>{new_version}\g<3>", content)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The substitution rf"\g<1>{new_version}\g<3>" assumes that the quotes are always present in the original string. If the TOML file does not have quotes around the version, this substitution will add them. It would be better to preserve the original quoting style (or lack thereof).

new_content = re.sub(pattern, rf"\g<1>{new_version}\g<2>", content)

failed_files = []
for file_rel in files_to_update:
file_abs = repo_root / file_rel
if not file_abs.exists():
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The continue statement skips non-existent files, but this might hide potential issues. It would be better to log a warning or error message to inform the user that a file specified for update does not exist. This can help in debugging configuration issues.

if not file_abs.exists():
    print(f"Warning: File {file_rel} does not exist, skipping validation.")
    continue  # Skip non-existent files (already warned above)

@Kangyan-Zhou Kangyan-Zhou changed the title [WIP] Fix version bump script to handle TOML files with outdated versions Fix version bump script to handle TOML files with outdated versions Oct 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants