Skip to content

chore: better bootstrap logging#3608

Open
rickeylev wants to merge 1 commit intobazel-contrib:mainfrom
rickeylev:chore.bootstrap.logging
Open

chore: better bootstrap logging#3608
rickeylev wants to merge 1 commit intobazel-contrib:mainfrom
rickeylev:chore.bootstrap.logging

Conversation

@rickeylev
Copy link
Collaborator

@rickeylev rickeylev commented Feb 18, 2026

Adds additional logging in the python bootstrap.

@gemini-code-assist
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 significantly enhances the robustness and debuggability of the Python bootstrap mechanism, particularly addressing cross-platform compatibility issues. It introduces more verbose logging to provide deeper insights into the bootstrap's execution flow and improves error messages for clearer problem identification. Furthermore, it includes crucial fixes for Windows environments, ensuring correct file encoding, path handling, and permissions during the build data generation and consumption processes.

Highlights

  • Enhanced Bootstrap Logging: Added more verbose logging statements within the Python bootstrap process to provide deeper insights into execution flow and variable states.
  • Improved Error Messages: The AssertionError message for a missing Python binary has been made more informative, including both expected and actual binary paths.
  • Windows Compatibility Fixes: Implemented several changes to improve compatibility on Windows, including robust file writing in PowerShell, correct path handling in Python, and better error reporting for build data.
  • Refactored Path Construction: Updated the py_executable.bzl file to use a dedicated runfiles_root_path utility for constructing the stage2 bootstrap path.

🧠 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.

Changelog
  • python/private/build_data_writer.ps1
    • Refactored file content collection into an array for batch writing.
    • Updated file writing to use .NET's System.IO.File::WriteAllLines with UTF8 without BOM for improved encoding and locking.
    • Added Test-Path checks before attempting to read VersionFilePath and InfoFilePath.
    • Applied read permissions for 'Everyone' to the output file using ACLs.
  • python/private/py_executable.bzl
    • Replaced direct string formatting for the stage2_bootstrap path with a call to the runfiles_root_path utility function.
  • python/private/python_bootstrap_template.txt
    • Added print_verbose statements for STAGE2_BOOTSTRAP, PYTHON_BINARY, PYTHON_BINARY_ACTUAL, IS_ZIPFILE, RECREATE_VENV_AT_RUNTIME, and WORKSPACE_NAME.
    • Added print_verbose statements for main_rel_path and runfiles root.
    • Modified the AssertionError message for a missing Python binary to include both PYTHON_BINARY and PYTHON_BINARY_ACTUAL.
  • python/private/stage2_bootstrap_template.py
    • Added a comment clarifying the need for Windows path conversion for BUILD_DATA_FILE.
    • Implemented Windows-specific path normalization and conversion (replacing '/' with '' and using os.path.normpath) for rlocation_path.
    • Changed file opening to use encoding='utf-8-sig' to correctly handle Windows Byte Order Mark (BOM).
    • Enhanced exception handling in get_build_data to add notes about the rlocation_path, file existence, and readability for debugging.
  • tests/pypi/whl_installer/wheel_installer_test.py
    • Modified the tearDown method to use shutil.rmtree(..., ignore_errors=True) to prevent errors during directory removal on Windows.
Activity
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

The pull request introduces helpful improvements to the bootstrap logging and error reporting, which will aid in debugging issues during Python binary execution. The refactoring of the Windows build data writer to use .NET APIs is a robust change. However, there is a critical regression in the stage 2 bootstrap where runfiles lookup keys are incorrectly normalized with backslashes on Windows, which will break lookups. Additionally, the error handling logic in the stage 2 bootstrap should be more defensive when the runfiles lookup fails.

Comment on lines 68 to 73
rlocation_path = self.BUILD_DATA_FILE
if is_windows():
rlocation_path = rlocation_path.replace("/", "\\")
path = runfiles.Create().Rlocation(rlocation_path)
if is_windows():
path = os.path.normpath(path)
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 runfiles library requires forward slashes for the lookup key (rlocation_path) on all platforms. Replacing them with backslashes on Windows will cause the lookup to fail because the manifest uses forward slashes and the library's internal logic expects them. Furthermore, os.path.normpath should only be called if the lookup returned a valid path.

Suggested change
rlocation_path = self.BUILD_DATA_FILE
if is_windows():
rlocation_path = rlocation_path.replace("/", "\\")
path = runfiles.Create().Rlocation(rlocation_path)
if is_windows():
path = os.path.normpath(path)
rlocation_path = self.BUILD_DATA_FILE
path = runfiles.Create().Rlocation(rlocation_path)
if path and is_windows():
path = os.path.normpath(path)

COVERAGE_INSTRUMENTED = "%coverage_instrumented%" == "1"

# runfiles-root-relative path to a file with binary-specific build information
# It uses forward slashes, so must be converted for proper usage on Windows.
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This comment is incorrect regarding the requirements of the runfiles library. The Rlocation method expects keys to be forward-slash separated, even on Windows, to match the logical paths in the runfiles manifest.

Comment on lines 78 to 84
except Exception as exc:
if hasattr(exc, "add_note"):
exc.add_note(f"runfiles lookup path: {rlocation_path}")
exc.add_note(f"exists: {os.path.exists(path)}")
can_read = os.access(path, os.R_OK)
exc.add_note(f"readable: {can_read}")
raise
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

If the runfiles lookup fails, path will be None. Calling os.path.exists(path) or os.access(path, ...) with None will raise a TypeError, which would mask the original error. The exception handling should safely check if path is not None before attempting to access the filesystem.

Suggested change
except Exception as exc:
if hasattr(exc, "add_note"):
exc.add_note(f"runfiles lookup path: {rlocation_path}")
exc.add_note(f"exists: {os.path.exists(path)}")
can_read = os.access(path, os.R_OK)
exc.add_note(f"readable: {can_read}")
raise
except Exception as exc:
if hasattr(exc, "add_note"):
exc.add_note(f"runfiles lookup path: {rlocation_path}")
if path is not None:
exc.add_note(f"resolved path: {path}")
exc.add_note(f"exists: {os.path.exists(path)}")
exc.add_note(f"readable: {os.access(path, os.R_OK)}")
else:
exc.add_note("resolved path: None (lookup failed)")
raise

@rickeylev rickeylev force-pushed the chore.bootstrap.logging branch 2 times, most recently from e364945 to 1ac813d Compare February 18, 2026 02:57
@rickeylev rickeylev force-pushed the chore.bootstrap.logging branch from 1ac813d to 2e00f57 Compare February 18, 2026 02:58
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

Comments