Skip to content

feat: expose interpreter files-to-run on PyRuntimeInfo#3795

Open
jsun-splunk wants to merge 1 commit into
bazel-contrib:mainfrom
jsun-splunk:jsun-files-to-run
Open

feat: expose interpreter files-to-run on PyRuntimeInfo#3795
jsun-splunk wants to merge 1 commit into
bazel-contrib:mainfrom
jsun-splunk:jsun-files-to-run

Conversation

@jsun-splunk
Copy link
Copy Markdown

@jsun-splunk jsun-splunk commented May 22, 2026

Rules that execute a py_runtime interpreter in an action need the interpreter executable together with its runfiles metadata. The existing PyRuntimeInfo fields identify the interpreter file and runtime files, but do not preserve the target's FilesToRunProvider for executable interpreter targets.

Add PyRuntimeInfo.interpreter_files_to_run for runtimes created from an executable interpreter target, and validate that direct provider construction keeps the FilesToRunProvider executable aligned with the interpreter field. Direct file interpreters and platform runtimes continue to leave this field unset, preserving existing py_runtime behavior.

Document the new public provider field and add focused analysis-test coverage for executable, file-only, platform, and invalid constructor cases.

One example is rules_pycross wheel building with an in-build executable Python runtime. pycross needs to run the selected Python interpreter in an action, but PyRuntimeInfo previously exposed only the interpreter File and runtime files, not the interpreter target's FilesToRunProvider. For executable in-build runtimes, the FilesToRunProvider is the Bazel-native handle that carries both the executable and the runfiles metadata needed to stage it as an action tool. Exposing it lets pycross consume the runtime interpreter directly for wheel-build actions instead of reconstructing or approximating the interpreter's runtime closure from separate fields.

Copy link
Copy Markdown
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 the interpreter_files_to_run field to PyRuntimeInfo, allowing action consumers to execute an in-build runtime interpreter along with its runfiles. The changes include updates to the py_runtime rule to populate this field when an executable target is provided, validation logic to ensure consistency between the interpreter and its runfiles provider, and comprehensive tests to verify the new functionality and error handling. I have no feedback to provide.

@jsun-splunk
Copy link
Copy Markdown
Author

@rickeylev, @aignas - any chance of a review?

Rules that execute a py_runtime interpreter in an action need the interpreter executable together with its runfiles metadata. The existing PyRuntimeInfo fields identify the interpreter file and runtime files, but do not preserve the target's FilesToRunProvider for executable interpreter targets.

Add PyRuntimeInfo.interpreter_files_to_run for runtimes created from an executable interpreter target, and validate that direct provider construction keeps the FilesToRunProvider executable aligned with the interpreter field. Direct file interpreters and platform runtimes continue to leave this field unset, preserving existing py_runtime behavior.

Document the new public provider field and add focused analysis-test coverage for executable, file-only, platform, and invalid constructor cases.
# keep py_runtime's file-only behavior and not populate
# interpreter_files_to_run. Rule targets have OutputGroupInfo; direct
# file targets do not.
is_file_target = OutputGroupInfo not in interpreter
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Could this key off interpreter_file.is_source instead of the OutputGroupInfo check? The case you're guarding against is really a source file — that's the only non-executable input with a files_to_run.executable — and is_source doesnt rely on which providers Bazel attaches to rule vs
file targets.

if _is_singleton_depset(interpreter_di.files):
interpreter_file = interpreter_di.files.to_list()[0]

if is_file_target and interpreter_file:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Is it worth noting somewhere that source-file interpreter now takes this path instead of the executable branch?

eg. py_runtime(interpreter = ...) pointing at a downloaded/extracted file @python_x86_64//:bin/python3 rather than a *_binary

This used to hit the executable branch and pick up the runfiles.merge/runtime_files expansion, and now skip it.

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.

2 participants