Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
b15a070
disable build_python_zip
rickeylev Feb 7, 2026
31b5a3d
add some error reporting
rickeylev Feb 8, 2026
22cf202
tag the tool_build_data genrule as manual so that it runs as part of …
rickeylev Feb 8, 2026
84a7f8f
Merge branch 'main' of https://github.com/bazel-contrib/rules_python …
rickeylev Feb 8, 2026
4d10302
try IO way of writing file from gemini
rickeylev Feb 8, 2026
7673610
ignore cleanup error on windows
rickeylev Feb 9, 2026
9c64f99
Merge branch 'main' of https://github.com/bazel-contrib/rules_python …
rickeylev Feb 9, 2026
050bbe9
debugging of why file is missing
rickeylev Feb 9, 2026
44ae114
remove extra sys import
rickeylev Feb 9, 2026
f1b373c
debug logic
rickeylev Feb 9, 2026
5108ea7
fix syntax
rickeylev Feb 9, 2026
fe7c47a
recurse symlnks
rickeylev Feb 9, 2026
74992d7
remove recurse symlinks arg
rickeylev Feb 9, 2026
c2e4927
enable bootstrap debug for pyconsole gen
rickeylev Feb 9, 2026
a63ee89
add more debugging
rickeylev Feb 9, 2026
fd4434b
print manifest lines
rickeylev Feb 9, 2026
7cbb490
fix var name
rickeylev Feb 9, 2026
295f840
force build_runfile_links to true
rickeylev Feb 14, 2026
c4642fc
Merge branch 'main' of https://github.com/bazel-contrib/rules_python …
rickeylev Feb 14, 2026
f8d37d0
grant everyone read, see if it works around permission error
rickeylev Feb 14, 2026
e37f7bd
try to fix label resolution
rickeylev Feb 14, 2026
9b1a481
Set internal attribute for py_test too
rickeylev Feb 14, 2026
64abc06
clean up build_runfile_links transition
rickeylev Feb 15, 2026
f81b664
add missing command_line_option directory
rickeylev Feb 15, 2026
7e49984
fix reconfig transition logic
rickeylev Feb 15, 2026
72671c9
try enable_runfiles=true, add sys py test
rickeylev Feb 15, 2026
e081548
try tomake work with enable_runfiles=false
rickeylev Feb 15, 2026
2164baf
fix func name
rickeylev Feb 15, 2026
04ef9af
add open r arg, add missing distribution target
rickeylev Feb 15, 2026
e6a57fd
add debug logic
rickeylev Feb 15, 2026
bb9dcdf
add utf8-sig logic, more debug
rickeylev Feb 15, 2026
6d41092
fix stage2 bootstrap path rendering
rickeylev Feb 15, 2026
0eda191
try to normpath, i guess?
rickeylev Feb 15, 2026
060991c
strip to remove trailing newline
rickeylev Feb 15, 2026
daa8769
encode to ut8
rickeylev Feb 15, 2026
ebc6ed8
use decode, not encode, on bytes object
rickeylev Feb 15, 2026
dc97151
manifest lookup of interpreter
rickeylev Feb 15, 2026
254c712
less debugging
rickeylev Feb 15, 2026
c66503b
add some debugging
rickeylev Feb 15, 2026
fa3d3fb
fix syntax
rickeylev Feb 15, 2026
bc954c2
return the found value, duh
rickeylev Feb 15, 2026
a721a9e
add notes
rickeylev Feb 15, 2026
1f72425
transition enable_runfiles
rickeylev Feb 15, 2026
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: 4 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,7 @@ common --incompatible_python_disallow_native_rules
common --incompatible_no_implicit_file_export

build --lockfile_mode=update

# See issue 3567. Disable implicit python zip creation.
common --build_python_zip=false
common --@rules_python//python/config_settings:build_python_zip=false
1 change: 1 addition & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ filegroup(
"internal_dev_deps.bzl",
"internal_dev_setup.bzl",
"version.bzl",
"//command_line_option:distribution",
"//python:distribution",
"//tools:distribution",
],
Expand Down
28 changes: 28 additions & 0 deletions command_line_option/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Aliases for Bazel builtin //command_line_option psuedo-targets
#
# These are alias to use with `py_binary.config_settings` that are treated
# as aliases for `//command_line_option:XXX` psuedo-targets.

package(
default_visibility = ["//visibility:public"],
)

# todo: add docs, xref with config_settings
# rules_python target, config_setting processing code converts it to the
# Bazel-builtin //command_line_label:build_runfile_links psuedo-target
alias(
name = "build_runfile_links",
actual = "//python:none",
)

# todo: add docs
alias(
name = "enable_runfiles",
actual = "//python:none",
)

filegroup(
name = "distribution",
srcs = glob(["**"]),
visibility = ["//:__subpackages__"],
)
4 changes: 4 additions & 0 deletions examples/build_file_generation/.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ build --enable_runfiles
common --noenable_bzlmod
common --enable_workspace
common --incompatible_python_disallow_native_rules

# See issue 3567. Disable implicit python zip creation.
common --build_python_zip=false
common --@rules_python//python/config_settings:build_python_zip=false
4 changes: 4 additions & 0 deletions examples/bzlmod/.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@ test --test_output=errors --enable_runfiles
# Windows requires these for multi-python support:
build --enable_runfiles
common:bazel7.x --incompatible_python_disallow_native_rules

# See issue 3567. Disable implicit python zip creation.
common --build_python_zip=false
common --@rules_python//python/config_settings:build_python_zip=false
4 changes: 4 additions & 0 deletions examples/multi_python_versions/.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ build --enable_runfiles

coverage --java_runtime_version=remotejdk_11
common:bazel7.x --incompatible_python_disallow_native_rules

# See issue 3567. Disable implicit python zip creation.
common --build_python_zip=false
common --@rules_python//python/config_settings:build_python_zip=false
7 changes: 7 additions & 0 deletions examples/pip_parse/.bazelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# https://docs.bazel.build/versions/main/best-practices.html#using-the-bazelrc-file
try-import %workspace%/user.bazelrc
common --incompatible_python_disallow_native_rules

# See issue 3567. Disable implicit python zip creation.
common --build_python_zip=false
common --@rules_python//python/config_settings:build_python_zip=false

# Windows makes use of runfiles for some rules
##common --enable_runfiles
4 changes: 4 additions & 0 deletions examples/pip_parse_vendored/.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ build --enable_runfiles
common --noenable_bzlmod
common --enable_workspace
common --incompatible_python_disallow_native_rules

# See issue 3567. Disable implicit python zip creation.
common --build_python_zip=false
common --@rules_python//python/config_settings:build_python_zip=false
4 changes: 4 additions & 0 deletions examples/pip_repository_annotations/.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ common --noenable_bzlmod
common --enable_workspace
common --legacy_external_runfiles=false
common --incompatible_python_disallow_native_rules

# See issue 3567. Disable implicit python zip creation.
common --build_python_zip=false
common --@rules_python//python/config_settings:build_python_zip=false
4 changes: 4 additions & 0 deletions gazelle/.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@ build --@rules_python//python/config_settings:incompatible_default_to_explicit_i
build --enable_runfiles

common:bazel7.x --incompatible_python_disallow_native_rules

# See issue 3567. Disable implicit python zip creation.
common --build_python_zip=false
common --@rules_python//python/config_settings:build_python_zip=false
4 changes: 4 additions & 0 deletions gazelle/examples/bzlmod_build_file_generation/.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ common:bazel7.x --incompatible_python_disallow_native_rules
# rules_python code. In the BCR presubmits, this override is removed
# and the bazel_dep version of rules_python is used.
common --override_module=rules_python=../../../

# See issue 3567. Disable implicit python zip creation.
common --build_python_zip=false
common --@rules_python//python/config_settings:build_python_zip=false
8 changes: 8 additions & 0 deletions python/private/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,14 @@ config_setting(
},
)

alias(
name = "what_os",
actual = select({
"@platforms//os:windows": "@platforms//os:windows",
"//conditions:default": "@platforms//os:linux",
}),
)

alias(
name = "debugger_if_target_config",
actual = select({
Expand Down
18 changes: 17 additions & 1 deletion python/private/attributes.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,18 @@ particular CPU, or defining a custom setting that `select()` uses elsewhere
to pick between `pip.parse` hubs. See the [How to guide on multiple
versions of a library] for a more concrete example.

:::{important}
Labels with package `command_line_option` are handled specially: they are treated
as aliases for the Bazel-builtin `//command_line_option:<name>` psuedo-targets.

e.g. `@foo//command_line_option:NAME` will attempt to transition
the Bazel-builtin `//command_line_option:NAME` setting.

See the {obj}`@rules_python//command_line_option` package for some predefined
aliases, or define your own by putting them in your own `command_line_option`
directory.
:::

:::{note}
These values are transitioned on, so will affect the analysis graph and the
associated memory overhead. The more unique configurations in your overall
Expand All @@ -426,7 +438,11 @@ def apply_config_settings_attr(settings, attr):
{type}`dict[str, object]` the input `settings` value.
"""
for key, value in attr.config_settings.items():
settings[str(key)] = value
if key.package == "command_line_option":
str_key = "//command_line_option:" + key.name
else:
str_key = str(key)
settings[str_key] = value
return settings

AGNOSTIC_EXECUTABLE_ATTRS = dicts.add(
Expand Down
28 changes: 20 additions & 8 deletions python/private/build_data_writer.ps1
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
$OutputPath = $env:OUTPUT

Add-Content -Path $OutputPath -Value "TARGET $env:TARGET"
Add-Content -Path $OutputPath -Value "CONFIG_MODE $env:CONFIG_MODE"
Add-Content -Path $OutputPath -Value "STAMPED $env:STAMPED"
$Lines = @(
"TARGET $env:TARGET",
"CONFIG_MODE $env:CONFIG_MODE",
"STAMPED $env:STAMPED"
)

$VersionFilePath = $env:VERSION_FILE
if (-not [string]::IsNullOrEmpty($VersionFilePath)) {
Get-Content -Path $VersionFilePath | Add-Content -Path $OutputPath
if (-not [string]::IsNullOrEmpty($VersionFilePath) -and (Test-Path $VersionFilePath)) {
$Lines += Get-Content -Path $VersionFilePath
}

$InfoFilePath = $env:INFO_FILE
if (-not [string]::IsNullOrEmpty($InfoFilePath)) {
Get-Content -Path $InfoFilePath | Add-Content -Path $OutputPath
if (-not [string]::IsNullOrEmpty($InfoFilePath) -and (Test-Path $InfoFilePath)) {
$Lines += Get-Content -Path $InfoFilePath
}

# Use .NET to write file to avoid PowerShell encoding/locking quirks
# We use UTF8 without BOM for compatibility with how the bash script writes (and
# what consumers expect).
$Utf8NoBom = New-Object System.Text.UTF8Encoding $False
[System.IO.File]::WriteAllLines($OutputPath, $Lines, $Utf8NoBom)

$Acl = Get-Acl $OutputPath
$AccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule("Everyone", "Read", "Allow")
$Acl.SetAccessRule($AccessRule)
Set-Acl $OutputPath $Acl

exit 0
7 changes: 6 additions & 1 deletion python/private/common_labels.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,20 @@ labels = struct(
ADD_SRCS_TO_RUNFILES = str(Label("//python/config_settings:add_srcs_to_runfiles")),
BOOTSTRAP_IMPL = str(Label("//python/config_settings:bootstrap_impl")),
BUILD_PYTHON_ZIP = str(Label("//python/config_settings:build_python_zip")),
# NOTE: Special target; see definition for details.
BUILD_RUNFILE_LINKS = str(Label("//command_line_option:build_runfile_links")),
DEBUGGER = str(Label("//python/config_settings:debugger")),
# NOTE: Special target; see definition for details.
ENABLE_RUNFILES = str(Label("//command_line_option:enable_runfiles")),
EXEC_TOOLS_TOOLCHAIN = str(Label("//python/config_settings:exec_tools_toolchain")),
PIP_ENV_MARKER_CONFIG = str(Label("//python/config_settings:pip_env_marker_config")),
NONE = str(Label("//python:none")),
PIP_ENV_MARKER_CONFIG = str(Label("//python/config_settings:pip_env_marker_config")),
PIP_WHL = str(Label("//python/config_settings:pip_whl")),
PIP_WHL_GLIBC_VERSION = str(Label("//python/config_settings:pip_whl_glibc_version")),
PIP_WHL_MUSLC_VERSION = str(Label("//python/config_settings:pip_whl_muslc_version")),
PIP_WHL_OSX_ARCH = str(Label("//python/config_settings:pip_whl_osx_arch")),
PIP_WHL_OSX_VERSION = str(Label("//python/config_settings:pip_whl_osx_version")),
PLATFORMS_OS_WINDOWS = str(Label("@platforms//os:windows")),
PRECOMPILE = str(Label("//python/config_settings:precompile")),
PRECOMPILE_SOURCE_RETENTION = str(Label("//python/config_settings:precompile_source_retention")),
PYC_COLLECTION = str(Label("//python/config_settings:pyc_collection")),
Expand Down
6 changes: 4 additions & 2 deletions python/private/py_binary_macro.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
"""Implementation of macro-half of py_binary rule."""

load(":py_binary_rule.bzl", py_binary_rule = "py_binary")
load(":py_executable.bzl", "convert_legacy_create_init_to_int")
load(":py_executable.bzl", "common_executable_macro_kwargs_setup")

_PLATFORMS_OS_WINDOWS = str(Label("@platforms//os:windows"))

def py_binary(**kwargs):
py_binary_macro(py_binary_rule, **kwargs)

def py_binary_macro(py_rule, **kwargs):
convert_legacy_create_init_to_int(kwargs)
common_executable_macro_kwargs_setup(kwargs)
py_rule(**kwargs)
3 changes: 3 additions & 0 deletions python/private/py_console_script_gen.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ def _py_console_script_gen_impl(ctx):
mnemonic = "PyConsoleScriptBinaryGen",
progress_message = "Generating py_console_script_binary main: %{label}",
executable = ctx.executable._tool,
env = {
"RULES_PYTHON_BOOTSTRAP_VERBOSE": "1",
},
)

return [DefaultInfo(
Expand Down
34 changes: 30 additions & 4 deletions python/private/py_executable.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -768,10 +768,7 @@ def _create_stage1_bootstrap(
}

if stage2_bootstrap:
subs["%stage2_bootstrap%"] = "{}/{}".format(
ctx.workspace_name,
stage2_bootstrap.short_path,
)
subs["%stage2_bootstrap%"] = runfiles_root_path(ctx, stage2_bootstrap.short_path)
template = runtime.bootstrap_template
subs["%shebang%"] = runtime.stub_shebang
elif not ctx.files.srcs:
Expand Down Expand Up @@ -1771,6 +1768,30 @@ def _create_run_environment_info(ctx, inherited_environment):
inherited_environment = inherited_environment,
)

def add_config_setting_default_build_runfiles_links(kwargs):
config_settings = kwargs.get("config_settings", None)
if config_settings == None:
config_settings = {}

# NOTE: This code runs in loading phase within the context of the caller.
# Label() must be used to resolve repo names within rules_python's
# context to avoid unknown repo name errors.
default = select({
labels.PLATFORMS_OS_WINDOWS: {
labels.BUILD_RUNFILE_LINKS: "true",
labels.ENABLE_RUNFILES: "true",
},
"//conditions:default": {
labels.BUILD_RUNFILE_LINKS: "true",
},
})
config_settings = default | config_settings
kwargs["config_settings"] = config_settings

def common_executable_macro_kwargs_setup(kwargs):
convert_legacy_create_init_to_int(kwargs)
add_config_setting_default_build_runfiles_links(kwargs)

def _transition_executable_impl(settings, attr):
settings = dict(settings)
apply_config_settings_attr(settings, attr)
Expand All @@ -1780,6 +1801,7 @@ def _transition_executable_impl(settings, attr):

if attr.stamp != -1:
settings["//command_line_option:stamp"] = str(attr.stamp)

return settings

def create_executable_rule(*, attrs, **kwargs):
Expand Down Expand Up @@ -1833,10 +1855,14 @@ def create_executable_rule_builder(implementation, **kwargs):
inputs = TRANSITION_LABELS + [
labels.PYTHON_VERSION,
"//command_line_option:stamp",
"//command_line_option:build_runfile_links",
"//command_line_option:enable_runfiles",
],
outputs = TRANSITION_LABELS + [
labels.PYTHON_VERSION,
"//command_line_option:stamp",
"//command_line_option:build_runfile_links",
"//command_line_option:enable_runfiles",
],
),
**kwargs
Expand Down
4 changes: 2 additions & 2 deletions python/private/py_test_macro.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
# limitations under the License.
"""Implementation of macro-half of py_test rule."""

load(":py_executable.bzl", "convert_legacy_create_init_to_int")
load(":py_executable.bzl", "common_executable_macro_kwargs_setup")
load(":py_test_rule.bzl", py_test_rule = "py_test")

def py_test(**kwargs):
py_test_macro(py_test_rule, **kwargs)

def py_test_macro(py_rule, **kwargs):
convert_legacy_create_init_to_int(kwargs)
common_executable_macro_kwargs_setup(kwargs)
py_rule(**kwargs)
Loading