Skip to content

Conversation

@ohmayr
Copy link
Contributor

@ohmayr ohmayr commented Jan 15, 2026

This PR is generated using Ruff based formatting (implemented in .generator/cli.py). nox -s format within the Synthtool was disabled for this run.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @ohmayr, 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 modernizes the project's Python code hygiene by migrating from black and isort to the faster and more efficient ruff formatter. The core logic for this transition resides in the code generation pipeline, ensuring that all newly generated and existing Python code adheres to the new formatting standards. Additionally, a performance tracking mechanism has been integrated to monitor the efficiency of various generation steps.

Highlights

  • Ruff Integration: The project now utilizes Ruff for all Python code formatting and import sorting, replacing the previous black and isort tools. This change is managed within the .generator/cli.py script, which now invokes ruff check --select I --fix and ruff format during post-processing.
  • Performance Logging: New performance tracking capabilities have been introduced in .generator/cli.py via a @track_time decorator, allowing for measurement of execution times for key functions within the generation process. This is enabled by setting the ENABLE_PERF_LOGS environment variable.
  • Dependency Updates: The .generator/requirements.in file has been updated to remove black and isort and add ruff, reflecting the change in formatting tools.
  • Extensive Formatting Changes: Numerous Python files across the google-cloud-vision package have undergone significant reformatting, including import reordering, adjustments to type hinting, and string literal changes (e.g., "..." to u"..."), all applied automatically by Ruff.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

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.

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 PR introduces ruff for code formatting and adds performance tracking. While the move to ruff is a positive step for consistency and performance, there are a few critical issues to address. A significant breaking change has been introduced by removing the ImageAnnotatorClient helper class in google/cloud/vision_v1/__init__.py, which eliminates several convenience methods. This pattern appears to be repeated in other versioned __init__.py files and needs to be reverted. Additionally, the script for running ruff in .generator/cli.py dangerously silences all errors. I've provided suggestions to handle these errors more safely. Lastly, there are some minor stylistic changes, like the addition of u prefixes to strings, which are unnecessary for a Python 3 codebase and could be configured in ruff.

I am having trouble creating individual review comments. Click here to see my feedback.

packages/google-cloud-vision/google/cloud/vision_v1/init.py (212-215)

critical

This change removes the ImageAnnotatorClient helper class, which was decorated with @add_single_feature_methods. This is a significant breaking change as it removes several helper methods (e.g., face_detection, label_detection) from the client that users might be depending on. Since this pull request is focused on formatting, this removal seems unintentional and should be reverted.

.generator/cli.py (397-421)

high

The ruff commands are executed with check=False and both stdout and stderr are redirected to DEVNULL. This approach will silently ignore any formatting errors or other issues ruff might encounter, potentially leading to partially formatted or unformatted code being committed. A safer approach would be to let subprocess.run raise an exception on failure and handle it, allowing for proper error logging.

        subprocess.run(
            [
                "ruff", "check", 
                "--select", "I",               # Only run Import sorting rules
                "--fix",                       # Auto-fix them
                "--line-length=88",            # Match Black default
                "--known-first-party=google",  # Prevent 'google' moving to 3rd party block
                output
            ],
            check=True,
        )

        # STEP B: Format Code (like black)
        subprocess.run(
            [
                "ruff", "format", 
                "--line-length=88",            # Match Black default
                output
            ],
            check=True,
        )

packages/google-cloud-vision/docs/conf.py (84-86)

medium

The u prefix for string literals is redundant in Python 3.3+ and has no effect. While it's not harmful, it adds unnecessary visual noise to the code. It would be best to configure ruff to avoid adding these prefixes to maintain code clarity, especially since this project targets modern Python versions.

project = "google-cloud-vision"
copyright = "2025, Google, LLC"
author = "Google APIs"

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.

1 participant