Skip to content
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

fix: skip precompiling if using Bazel-builtin PyRuntimeInfo #2394

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ A brief description of the categories of changes:

{#v0-0-0-fixed}
### Fixed
* Nothing yet
* (precompiling) Skip precompiling (instead of erroring) if the legacy
`@bazel_tools//tools/python:autodetecting_toolchain` is being used
([#2364](https://github.com/bazelbuild/rules_python/issues/2364)).

{#v0-0-0-added}
### Added
Expand Down
11 changes: 7 additions & 4 deletions python/private/common_bazel.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,13 @@ def _precompile(ctx, src, *, use_pycache):

stem = src.basename[:-(len(src.extension) + 1)]
if use_pycache:
if not target_toolchain.pyc_tag:
# This is most likely because of a "runtime toolchain", i.e. the
# autodetecting toolchain, or some equivalent toolchain that can't
# assume to know the runtime Python version at build time.
if not hasattr(target_toolchain, "pyc_tag") or not target_toolchain.pyc_tag:
# This is likely one of two situations:
# 1. The pyc_tag attribute is missing because it's the Bazel-builtin
# PyRuntimeInfo object.
# 2. It's a "runtime toolchain", i.e. the autodetecting toolchain,
# or some equivalent toolchain that can't assume to know the
# runtime Python version at build time.
# Instead of failing, just don't generate any pyc.
return None
pyc_path = "__pycache__/{stem}.{tag}.pyc".format(
Expand Down