-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Experiment: use ruff based code formatting #15466
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
base: main
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @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 Highlights
🧠 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 AssistThe 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
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 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
|
There was a problem hiding this 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)
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)
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)
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"
This PR is generated using Ruff based formatting (implemented in
.generator/cli.py).nox -s formatwithin the Synthtool was disabled for this run.