Skip to content

Conversation

@janwinkler1
Copy link
Contributor

  • Enables using pyproject.toml as single source of truth for Python version via
    python.defaults(pyproject_toml=...) and pip.default(pyproject_toml=...).

  • Creates python_version_from_pyproject repository for BUILD file usage:

load("@python_version_from_pyproject//:version.bzl", "PYTHON_VERSION")
compile_pip_requirements(python_version = PYTHON_VERSION, ...)
  • Makes config_settings optional in pip.default(). Previously, users had
    to pass an empty list (config_settings = []) even when not using platform-specific
    configurations. Now it can be omitted entirely when not needed.

Changes:

  • Added pyproject_toml attribute to python.defaults() and pip.default()
  • Reads Python version from requires-python field (must be ==X.Y.Z format)
  • Made config_settings optional in pip.default() (was mandatory, even for empty lists)
  • Made python_version optional in pip.parse() when using pip.default(pyproject_toml=...)
  • Extracted version parsing to shared Python script for maintainability

Requirements:

  • requires-python = "==X.Y.Z" format in pyproject.toml
  • Python >=3.11 or tomli package on host system

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @janwinkler1, 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 significantly enhances the Python ecosystem's integration by introducing pyproject.toml as a primary source for defining Python versions within Bazel projects. It streamlines configuration by allowing python.defaults() and pip.default() to automatically infer the Python version from pyproject.toml, reducing redundancy and potential for discrepancies. Additionally, it improves the developer experience by making config_settings optional in pip.default() and providing a dedicated repository for accessing the pyproject.toml-defined Python version in BUILD files.

Highlights

  • Centralized Python Version Management: Introduced the pyproject_toml attribute to python.defaults() and pip.default(), enabling the Python version to be read directly from pyproject.toml's requires-python field. This establishes pyproject.toml as a single source of truth for Python versions across the project.
  • BUILD File Integration for Python Version: A new repository rule, python_version_from_pyproject, has been created. This rule generates a version.bzl file that exports the PYTHON_VERSION constant, allowing BUILD files to import and use the Python version defined in pyproject.toml without hardcoding it.
  • Simplified pip.default() Configuration: The config_settings attribute in pip.default() is now optional. Previously, users had to pass an empty list (config_settings = []) even when no platform-specific configurations were needed, but now it can be omitted entirely.
  • Flexible pip.parse() Usage: The python_version attribute in pip.parse() is now optional when pip.default(pyproject_toml=...) is used, as the version can be automatically inferred from the pyproject.toml file specified in the defaults.
  • Dedicated Version Extraction Logic: The logic for parsing and extracting the Python version from pyproject.toml has been moved into a shared Python script (pyproject_version_extractor.py), improving maintainability and reusability of the version parsing functionality.

🧠 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 pull request introduces a significant and valuable feature by enabling pyproject.toml as a single source of truth for Python versions in both python.defaults() and pip.default(). This enhancement greatly improves consistency and maintainability across projects. The implementation includes a new repository rule (pyproject_version_repo) and utility functions to extract and validate the Python version from pyproject.toml. Additionally, config_settings in pip.default() has been made optional, which is a good usability improvement. The changes are well-tested with dedicated integration and priority tests, ensuring the new functionality works as expected and respects the defined priority order for Python version resolution. The code is clean, well-documented, and adheres to best practices.

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