Skip to content

Conversation

rickeylev
Copy link
Collaborator

When files overlap between packages, and dist-info directories are present, it results in a prefix list like foo foo-bar foo/bar. When sorted as raw strings, hyphen sorts before slash, so the continuity of path prefixes is violated and they are grouped separately. An error then occurs because both foo/ and foo/bar are created, but the latter is a sub-path of the former.

To fix, change the sort key to a tuple of path components. This makes foo foo-bar foo/bar sort as (foo,) (foo, bar), (foo-bar, ), resulting in the correct order.

Fixes #3204

When files overlap between packages, and dist-info directories are
present, it results in a prefix list like `foo foo-bar foo/bar`.
When sorted as raw strings, hyphen sorts before slash, so the continuity
of path prefixes is violated and they are grouped separately. An error
then occurs because both `foo/` and `foo/bar` are created, but the
latter is a sub-path of the former.

To fix, change the sort key to a tuple of path components. This makes
`foo foo-bar foo/bar` sort as `(foo,) (foo, bar), (foo-bar, )`,
resulting in the correct order.

Fixes bazel-contrib#3204
@rickeylev rickeylev requested a review from aignas as a code owner October 9, 2025 20:08
Copy link
Contributor

Summary of Changes

Hello @rickeylev, 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 addresses a critical bug in the virtual environment path grouping logic that caused incorrect ordering of paths, especially when dist-info directories were involved. The fix involves a fundamental change to the sorting key, moving from raw string comparison to a component-based comparison. This ensures that paths are grouped hierarchically and correctly, preventing errors that arise from misordered sub-paths and improving the robustness of virtual environment management.

Highlights

  • Sorting Logic Fix: The core issue of incorrect virtual environment path grouping, particularly when dist-info directories were present, has been resolved. Previously, raw string sorting led to foo-bar being ordered before foo/bar, disrupting hierarchical path continuity.
  • Updated Sorting Key: The sorting mechanism for venv_path entries has been updated. Instead of sorting by the raw string, entries are now sorted by a tuple of their path components (e.g., ('foo',), ('foo', 'bar'), ('foo-bar',)), ensuring correct hierarchical ordering.
  • Test Case Enhancement: A new test entry for a-1.0.dist-info was added to the _test_conflict_merging_impl function in app_files_building_tests.bzl. This addition specifically validates the fix for the dist-info directory sorting problem.
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 fixes a bug in how virtual environment path entries are grouped by changing the sorting key. Instead of sorting raw paths as strings, it now sorts them based on their path components. This correctly groups paths with common prefixes, like foo and foo/bar, before other paths like foo-bar, preventing errors when creating venv symlinks. The change is logical and is accompanied by a new test case that validates the fix. My only suggestion is to improve the comment to make the sorting logic clearer for future maintenance.

@aignas aignas added this pull request to the merge queue Oct 10, 2025
Merged via the queue into bazel-contrib:main with commit 33fd322 Oct 10, 2025
4 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.

Using venvs_site_packages=yes results in overlapping action output paths error
2 participants