-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
py_binary doesn't automatically pick a Python runtime matching the requested version #4815
Comments
@lberki can you take this please? |
A proper solution would probably involve allowing But in the meantime, a quicker and simpler solution would probably be to make the default behavior (where |
The proper fix for this bug is to implement Until that's implemented, the workaround is to dispatch to the system interpreters in a py_runtime(
name = "myruntime",
interpreter_path = select({
# Update paths as appropriate for your system.
"@bazel_tools//tools/python:PY2": "/usr/bin/python2",
"@bazel_tools//tools/python:PY3": "/usr/bin/python3",
}),
files = [],
) Then run your build with the flag |
This puts users on notice that even when they set the Python version correctly at loading/analysis time, the default behavior will still incorrectly use the same Python runtime for both PY2 and PY3 at execution time (bug #4815). This warning was requested by users and may save them some time and frustration until #4815 is fixed. RELNOTES: None PiperOrigin-RevId: 232880171
I could be totally missing something about how Python works here, so feel free to correct me. |
At the moment we don't bundle a specific standard Python interpreter with Bazel. We would need an interpreter for each platform that Bazel supports, and we'd have to worry about coordinating upgrades to this version. We don't tend to bundle tools with Bazel and its rule sets in other languages either, e.g. there's no gcc included in Bazel. However, as a user you can include a Python interpreter in your repo and reference it via a Having a workspace rule fetch a Python interpreter sounds like a reasonable feature off the top of my head. Created #7467. |
Ah yes, I didn't mean that bazel should ship an interpreter itself. Your plan for fetching it should work perfect for us, we have a lot of systems that don't necessarily have Python on them and would prefer avoiding any transient issues due to version skews. |
This is especially bad when building Python programs (or Subpar *.par's) for e.g. RaspberryPi. You build and copy your program, and then it barfs because it uses Python2 instead of 3 even though everything in the build tells it to use Python3. |
bazelbuild/bazel#4815 (comment) Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Baseline: 5935259 Cherry picks: + fe81b49: Support of using the absolute path profile for LLVM's Context Sensitive FDO + ce5e718: Demote OptionProcessor from globals + 3ed9d36: Properly wire up BES half-close. The lack thereof was a simple oversight. + 4ca768e: standardize graph output indentation with 2 spaces + aff189a: Make sure default Linux artifacts have an associated action, even when artifact names are altered. + 8c3b3fb: Failures early in package loading will now fail all --keep_going builds. + 123c68d: Warn in more cases of possible Python version mismatch in host config + 052167e: Add a non-strict autodetecting Python toolchain + 6ef6d87: Default java toolchain target + 50fa3ec: Fix problems with the non-strict Python toolchain + e2a626c: Automated rollback of commit bc6f7cb. + 6efc5b7: Treat existence of managed directories as a part of repository dirtiness. + 3a4be3c: Add /usr/local/bin to default PATH under strict action env + 5c1005c: Automated rollback of commit 536a166. Incompatible changes: - --incompatible_disable_objc_provider_resources no longer has effect. Use of deprecated resource fields on the Objc provider is now disallowed regardless of this flag. - deleted deprecated --experimental-remote-retry* flags, please use --remote_retries instead - flipped --incompatible_list_based_execution_strategy_selection flag to be true by default. See bazelbuild#7480 for details. - Octal integer literals in Starlark are required to start with "Oo". - The "native" module is no longer available in BUILD files, all its members can be accessed directly as global symbols. This can be temporarily reverted by providing --incompatible_disallow_native_in_build_file=false as a flag to Blaze. - The "native" module is no longer available in BUILD files, all its members can be accessed directly as global symbols. This can be temporarily reverted by providing --incompatible_disallow_native_in_build_file=false as a flag to Blaze. - Turn off binary style profile format. - The "native" module is no longer available in BUILD files, all its members can be accessed directly as global symbols. This can be temporarily reverted by providing --incompatible_disallow_native_in_build_f... - cleanup that affects user provided apple frameworks is now enabled by default. See bazelbuild#7944 for more info. - Python rules now determine the Python runtime using toolchains rather than `--python_top` and `--python_path`, which are deprecated. See [bazelbuild#7899](bazelbuild#7899) for information on declaring Python toolchains and migrating your code. As a side-benefit, this addresses [bazelbuild#4815](bazelbuild#4815) (incorrect interpreter version used) on non-Windows platforms. Note however that some builds break due to getting the version they asked for -- consider setting `python_version = "PY2"` on Python 2 targets and `--host_force_python=PY2` if any Python 2 targets are used in the host configuration. You can temporarily opt out of this change with `--incompatible_use_python_toolchains=false`. - Depsets can't be iterated over unless they're converted to lists using the .to_list() method. Use --incompatible_depset_is_not_iterable=false to temporarily restore the previous behaviour. New features: - Bash, runfiles: the copy-pasted init code of the Bash runfiles library is now shorter, see `tools/bash/runfiles/runfiles.bash`. The rlocation() implementation is the same. - Bash, runfiles: the copy-pasted init code of the Bash runfiles library is now shorter, see `tools/bash/runfiles/runfiles.bash`. The rlocation() implementation is the same. - Bash, runfiles: the copy-pasted init code of the Bash runfiles library is now shorter, see `tools/bash/runfiles/runfiles.bash`. To use the new init code, you need Bazel 0.27 or newer. The old (longer) init code still works. Important changes: - The `outputs` parameter of the `rule()` function is deprecated and attached to flag `--incompatible_no_rule_outputs_param`. Migrate rules to use `OutputGroupInfo` or `attr.output` instead. See bazelbuild#7977 for more info. - The --incompatible_disable_objc_library_resources flag is being removed. Please remove it from your configs as it otherwise will fail the build. - Add a generic additional_linker_inputs attribute on cc_binary rules. - Windows, C++ autoconfigure: BAZEL_VC and BAZEL_VS may now have quotes, so if you set these envvars' values in cmd.exe via TAB-completion then you no longer need to remove the surrounding quotes. - pkg_deb has new attributes: `config` and `templates` that can be used for integration with debconf - Allow cc_import() of a DLL with no interface library on Windows, used to document runtime dependencies. - All host-configured Python tools that are built for the wrong Python version will now emit a warning message when they exit with non-zero status. See bazelbuild#7899. - deprecated --remote_local_fallback_strategy. Use `--strategy=remote,local` instead. See bazelbuild#7480. - Introduce --incompatible_disable_native_android_rules flag - The Android desugaring actions now support a persistent worker mode for faster local build performance. Enable it with `--strategy=Desugar=worker`. - --incompatible_static_name_resolution_in_build_files is now enabled by default - --incompatible_disable_deprecated_attr_params is now enabled by default (bazelbuild#5818) - Repository containing autoconfigured C++ toolchain `@local_config_cc` has been split in 2 - see `local_config_cc_toolchains`. - --incompatible_string_join_requires_strings is now enabled by default - Flag --incompatible_new_actions_api is enabled by dewfault (bazelbuild#5825) - New flag `--incompatible_disallow_empty_glob`. See bazelbuild#8195 - --incompatible_no_kwargs_in_build_files is enabled by default - Incompatible flag `--incompatible_require_ctx_in_configure_features` has been flipped. See bazelbuild#7793 for more information. - `BAZEL_USE_XCODE_TOOLCHAIN=1` tells Bazel not to look for Xcode to decide whether to enable toolchains for Apple rules, but to assume Xcode is available. Can be also used when building on Darwin and no C++ or ObjC is being built, so there is no need to detect Xcode. - Android desugaring actions now use persistent workers by default. This has been measured to provide up to 20% reduction in build times. To disable it, use the `--strategy=Desugar=sandboxed` flag. See bazelbuild#8342 and bazelbuild#8427 for more details on local build speed optimization for Android apps. - Fixed an issue with Android builds where `--fat_apk_cpu` doesn't pack all selected shared libraries from `aar_import` targets into the APK. See [bazelbuild#8283](bazelbuild#8283). - Turn on --experimental_starlark_config_transitions by default for starlark transitions (see https://docs.bazel.build/versions/master/skylark/config.html#user- defined-transitions for more info) - Turn on --experimental_build_setting_api by default for starlark build settings (see https://docs.bazel.build/versions/master/skylark/config.html#user- defined-build-settings for more info) - Incompatible flag `--incompatible_dont_enable_host_nonhost_crosstool_features` has been flipped. See bazelbuild#7407 for more information. - Added support for Android NDK 19 and 20. - Flip --incompatible_no_support_tools_in_action_inputs - --remote_executor, --remote_cache or --bes_backend=someurl.com would be treated as grpcs://someurl.com, if the --incompatible_tls_enabled_removed flag enabled. See bazelbuild#8061 for details. - Add new options --cs_fdo_absolute_path= to support the absolute path profile for LLVM's context-sensitive FDO. - When `--incompatible_strict_action_env` is enabled, the default `PATH` now includes `/usr/local/bin`. - Turn on --experimental_build_setting_api by default for starlark build settings (see https://docs.bazel.build/versions/master/skylark/config.html#user- defined-build-settings for more info) This release contains contributions from many people at Google, as well as Alex Thompson, Andy Scott, Benjamin Peterson, David McNett, Drew Gassaway, Ira Shikhman, James deBoer, Jay Vercellone, Jingwen Chen, Josh Rosen, Keith Smiley, Laurent Le Brun, Lee Mracek, Marwan Tammam, Matt Passell, Michael Hackner, Michal Majcherski, Patrick Niklaus, Peter Mounce, Ricky Pai, Steeve Morin, szakmary, Takuto Ikuta, Vladimir Chebotarev, Yen-Chi Chen.
Baseline: 5935259 Cherry picks: + fe81b49: Support of using the absolute path profile for LLVM's Context Sensitive FDO + ce5e718: Demote OptionProcessor from globals + 3ed9d36: Properly wire up BES half-close. The lack thereof was a simple oversight. + 4ca768e: standardize graph output indentation with 2 spaces + aff189a: Make sure default Linux artifacts have an associated action, even when artifact names are altered. + 8c3b3fb: Failures early in package loading will now fail all --keep_going builds. + 123c68d: Warn in more cases of possible Python version mismatch in host config + 052167e: Add a non-strict autodetecting Python toolchain + 6ef6d87: Default java toolchain target + 50fa3ec: Fix problems with the non-strict Python toolchain + e2a626c: Automated rollback of commit bc6f7cb. + 6efc5b7: Treat existence of managed directories as a part of repository dirtiness. + 3a4be3c: Add /usr/local/bin to default PATH under strict action env + 5c1005c: Automated rollback of commit 536a166. Incompatible changes: - --incompatible_disable_objc_provider_resources no longer has effect. Use of deprecated resource fields on the Objc provider is now disallowed regardless of this flag. - deleted deprecated --experimental-remote-retry* flags, please use --remote_retries instead - flipped --incompatible_list_based_execution_strategy_selection flag to be true by default. See bazelbuild#7480 for details. - Octal integer literals in Starlark are required to start with "Oo". - The "native" module is no longer available in BUILD files, all its members can be accessed directly as global symbols. This can be temporarily reverted by providing --incompatible_disallow_native_in_build_file=false as a flag to Blaze. - The "native" module is no longer available in BUILD files, all its members can be accessed directly as global symbols. This can be temporarily reverted by providing --incompatible_disallow_native_in_build_file=false as a flag to Blaze. - Turn off binary style profile format. - The "native" module is no longer available in BUILD files, all its members can be accessed directly as global symbols. This can be temporarily reverted by providing --incompatible_disallow_native_in_build_f... - cleanup that affects user provided apple frameworks is now enabled by default. See bazelbuild#7944 for more info. - Python rules now determine the Python runtime using toolchains rather than `--python_top` and `--python_path`, which are deprecated. See [bazelbuild#7899](bazelbuild#7899) for information on declaring Python toolchains and migrating your code. As a side-benefit, this addresses [bazelbuild#4815](bazelbuild#4815) (incorrect interpreter version used) on non-Windows platforms. Note however that some builds break due to getting the version they asked for -- consider setting `python_version = "PY2"` on Python 2 targets and `--host_force_python=PY2` if any Python 2 targets are used in the host configuration. You can temporarily opt out of this change with `--incompatible_use_python_toolchains=false`. - Depsets can't be iterated over unless they're converted to lists using the .to_list() method. Use --incompatible_depset_is_not_iterable=false to temporarily restore the previous behaviour. New features: - Bash, runfiles: the copy-pasted init code of the Bash runfiles library is now shorter, see `tools/bash/runfiles/runfiles.bash`. The rlocation() implementation is the same. - Bash, runfiles: the copy-pasted init code of the Bash runfiles library is now shorter, see `tools/bash/runfiles/runfiles.bash`. The rlocation() implementation is the same. - Bash, runfiles: the copy-pasted init code of the Bash runfiles library is now shorter, see `tools/bash/runfiles/runfiles.bash`. To use the new init code, you need Bazel 0.27 or newer. The old (longer) init code still works. Important changes: - The `outputs` parameter of the `rule()` function is deprecated and attached to flag `--incompatible_no_rule_outputs_param`. Migrate rules to use `OutputGroupInfo` or `attr.output` instead. See bazelbuild#7977 for more info. - The --incompatible_disable_objc_library_resources flag is being removed. Please remove it from your configs as it otherwise will fail the build. - Add a generic additional_linker_inputs attribute on cc_binary rules. - Windows, C++ autoconfigure: BAZEL_VC and BAZEL_VS may now have quotes, so if you set these envvars' values in cmd.exe via TAB-completion then you no longer need to remove the surrounding quotes. - pkg_deb has new attributes: `config` and `templates` that can be used for integration with debconf - Allow cc_import() of a DLL with no interface library on Windows, used to document runtime dependencies. - All host-configured Python tools that are built for the wrong Python version will now emit a warning message when they exit with non-zero status. See bazelbuild#7899. - deprecated --remote_local_fallback_strategy. Use `--strategy=remote,local` instead. See bazelbuild#7480. - Introduce --incompatible_disable_native_android_rules flag - The Android desugaring actions now support a persistent worker mode for faster local build performance. Enable it with `--strategy=Desugar=worker`. - --incompatible_static_name_resolution_in_build_files is now enabled by default - --incompatible_disable_deprecated_attr_params is now enabled by default (bazelbuild#5818) - Repository containing autoconfigured C++ toolchain `@local_config_cc` has been split in 2 - see `local_config_cc_toolchains`. - --incompatible_string_join_requires_strings is now enabled by default - Flag --incompatible_new_actions_api is enabled by dewfault (bazelbuild#5825) - New flag `--incompatible_disallow_empty_glob`. See bazelbuild#8195 - --incompatible_no_kwargs_in_build_files is enabled by default - Incompatible flag `--incompatible_require_ctx_in_configure_features` has been flipped. See bazelbuild#7793 for more information. - `BAZEL_USE_XCODE_TOOLCHAIN=1` tells Bazel not to look for Xcode to decide whether to enable toolchains for Apple rules, but to assume Xcode is available. Can be also used when building on Darwin and no C++ or ObjC is being built, so there is no need to detect Xcode. - Android desugaring actions now use persistent workers by default. This has been measured to provide up to 20% reduction in build times. To disable it, use the `--strategy=Desugar=sandboxed` flag. See bazelbuild#8342 and bazelbuild#8427 for more details on local build speed optimization for Android apps. - Fixed an issue with Android builds where `--fat_apk_cpu` doesn't pack all selected shared libraries from `aar_import` targets into the APK. See [bazelbuild#8283](bazelbuild#8283). - Turn on --experimental_starlark_config_transitions by default for starlark transitions (see https://docs.bazel.build/versions/master/skylark/config.html#user- defined-transitions for more info) - Turn on --experimental_build_setting_api by default for starlark build settings (see https://docs.bazel.build/versions/master/skylark/config.html#user- defined-build-settings for more info) - Incompatible flag `--incompatible_dont_enable_host_nonhost_crosstool_features` has been flipped. See bazelbuild#7407 for more information. - Added support for Android NDK 19 and 20. - Flip --incompatible_no_support_tools_in_action_inputs - --remote_executor, --remote_cache or --bes_backend=someurl.com would be treated as grpcs://someurl.com, if the --incompatible_tls_enabled_removed flag enabled. See bazelbuild#8061 for details. - Add new options --cs_fdo_absolute_path= to support the absolute path profile for LLVM's context-sensitive FDO. - When `--incompatible_strict_action_env` is enabled, the default `PATH` now includes `/usr/local/bin`. - Turn on --experimental_build_setting_api by default for starlark build settings (see https://docs.bazel.build/versions/master/skylark/config.html#user- defined-build-settings for more info) This release contains contributions from many people at Google, as well as Alex Thompson, Andy Scott, Benjamin Peterson, David McNett, Drew Gassaway, Ira Shikhman, James deBoer, Jay Vercellone, Jingwen Chen, Josh Rosen, Keith Smiley, Laurent Le Brun, Lee Mracek, Marwan Tammam, Matt Passell, Michael Hackner, Michal Majcherski, Patrick Niklaus, Peter Mounce, Ricky Pai, Steeve Morin, szakmary, Takuto Ikuta, Vladimir Chebotarev, Yen-Chi Chen.
Baseline: daa8ae5 Cherry picks: + 61c7ffa: Automated rollback of commit 87388e2. + 898d7b6: Add test for repository overrides, conflicting with managed directories being added when Bazel server is already started. + c2001a4: Automated rollback of commit bbe47a1. + e67c961: Fix a non-determinism in create_embedded_tools.py. + 81aefe7: Remove unsupported cpu attribute from cc_toolchains. + 597e289: remote: made CombinedCache a composition of Disk and Http Cache + 942f7cf: C++: Fixes bug in C++ API with external repo aspects + 85a5a2b: Configure @androidsdk//:emulator_x86 and :emulator_arm to point to the unified emulator binary + 9835cb4: Automated rollback of commit 844e4e2. + c963ba2: Windows, Python: fix arg. esc. also in host config + a1ea487: Do not pre-cache changed files under managed directories + 7dc78cd: Add explicit execution and target constraints for autodiscovered cc t? + dd9ac13: Fix a bug when a relative path is used for the execution log + 0ff19c6: Fix StandaloneTestStrategy.appendStderr + 7f49531: Fix the autodetecting Python toolchain on Mac + ddce723: Avoid exporting PATH unnecessarily + 35dd05a: Allow Starlark rules to be able to use the `exec_compatible_with` Incompatible changes: - Flip --incompatible_windows_escape_jvm_flags to true. See bazelbuild#7486 - Flip --incompatible_windows_style_arg_escaping to true. See bazelbuild#7454 - --incompatible_windows_escape_jvm_flags is enabled by default, and the flag no longer exists - `--incompatible_no_output_attr_default` is enabled by default. - --incompatible_depset_union is enabled by default. - Python rules now determine the Python runtime using toolchains rather than `--python_top` and `--python_path`, which are deprecated. See [bazelbuild#7899](bazelbuild#7899) for information on declaring Python toolchains and migrating your code. As a side-benefit, this addresses bazelbuild#4815 (incorrect interpreter version used) on non-Windows platforms. You can temporarily opt out of this change with `--incompatible_use_python_toolchains=false`. - Python rules now determine the Python runtime using toolchains rather than `--python_top` and `--python_path`, which are deprecated. See bazelbuild#7899 for information on declaring Python toolchains and migrating your code. As a side-benefit, this addresses bazelbuild#4815 (incorrect interpreter version used) on non-Windows platforms. You can temporarily opt out of this change with `--incompatible_use_python_toolchains=false`. New features: - Windows, Python: the --incompatible_windows_escape_python_args flag (false by default) builds py_binary and py_test targets with correct command line argument escaping. - cquery supports --output=build Important changes: - Allow debugging C++ features logic. - The --ios_multi_cpus, --watchos_cpus, --macos_cpus and tvos_cpus are now additive. This means that you can now split the --ios_multi_cpus=arm64,armv7 into --ios_multi_cpus=arm64 and --ios_multi_cpus=armv7. - Generated Go protobufs now depend on //net/proto2/go:proto_gendeps instead of //net/proto2/go:proto - Add new options --cs_fdo_instrument and --cs_profile to support LLVM's context-sensitive FDO (CSFDO). - Bazel C++ compile/link Starlark API. Can be used with experimental flag --experimental_cc_skylark_api_enabled_packages=<package_path>,<pac kage_path2>. - `cc_toolchain.static_runtime_lib` and `cc_toolchain.dynamic_runtime_lib` are now exposed to Starlark. - New flag `--incompatible_no_kwargs_in_build_files`. See bazelbuild#8021 - struct.to_proto() converts dict into proto3 text message (map<,>). - Android resource conflicts will no longer be reported between a strong attr resource and a weak attr resource, if the weak attr does not have format specified. - Flag `--incompatible_static_name_resolution_in_build_files` is added. See bazelbuild#8022 - Add --incompatible_objc_framework_cleanup to control whether to enable some objc framework cleanup that changes the API. Specifically, the cleanup changes the objc provider API pertaining to frameworks. This change is expected to be transparent to most users unless they write their own Starlark rules to handle frameworks. See bazelbuild#7594 for details. - Added --incompatible_remove_binary_profile to disable the old binary profiles. Instead use the JSON profile format: https://docs.bazel.build/versions/master/skylark/performance.html# json-profile - Introducing --execution_log_binary_file and --execution_log_json_file that output a stable sorted execution log. They will offer a stable replacement to --experimental_execution_log_file. - Flag `--incompatible_disallow_old_octal_notation` is added. See //github.com/bazelbuild/issues/8059 - Removes the --incompatible_disable_genrule_cc_toolchain_dependency flag. - Android resource conflicts will no longer be reported between a strong attr resource and a weak attr resource, if the weak attr does not have format specified. - Incompatible flag `--incompatible_make_thinlto_command_lines_standalone` has been added. See bazelbuild#6791 for details. - objc_library does not support resource attributes any more. Please read bazelbuild#7594 for more info. - The `outputs` parameter of the `rule()` function is deprecated and attached to flag `--incompatible_no_rule_outputs_param`. Migrate rules to use `OutputGroupInfo` or `attr.output` instead. See bazelbuild#7977 for more info. - New platform_mappings ability to allow gradual flag to platforms/toolchains migration. See also bazelbuild#6426 - Added support for compiling against fully qualified R classes from aar_import dependencies. - --tls_enabled flag is deprecated. Please provide 'grpcs' as a scheme in the URLs if TLS should be used for a remote connection. - Adds incompatible_disallow_rule_execution_platform_constraints_allowed, which disallows the use of the "execution_platform_constraints_allowed" attribute when defining new rules. - Flag `--incompatible_restrict_named_params` is added. See bazelbuild#8147 for details. - The glob function has a new argument `allow_empty`. When set to False, the glob fails when it doesn't match anything. - Adds the "disable_whole_archive_for_static_lib" feature to allow turning off legacy_whole_archive for individual targets. - C++ Starlark API for compilation and linking is no longer whitelisted - Update visibility advice in build-style - --incompatible_disable_objc_provider_resources is now enabled by default. - Fixed an issue where some `py_runtime`s were incompatible with using `--build_python_zip` (bazelbuild#5104). - The `outputs` parameter of the `rule()` function is deprecated and attached to flag `--incompatible_no_rule_outputs_param`. Migrate rules to use `OutputGroupInfo` or `attr.output` instead. See bazelbuild#7977 for more info. This release contains contributions from many people at Google, as well as Benjamin Peterson, Brian Topping, clyang82, Dave Lee, George Gensure, Greg Estren, Greg, Guro Bokum, Keith Smiley, Max Vorobev, Michael Hackner, Robert Brown, Robert Sayre, Ryan Beasley, Yannic.
(This is a roll-forward of bazelbuild@bf66dc7.) This flips --incompatible_use_python_toolchains, which deprecates --python_top (and for the most part, --python_path). See bazelbuild#7899 for more on the change and migration procedure. Known downstream breakages are summarized [here](bazelbuild#7899 (comment)). Fixes bazelbuild#7899, fixes bazelbuild#7375, significant progress on bazelbuild#4815. RELNOTES[INC]: Python rules now determine the Python runtime using toolchains rather than `--python_top` and `--python_path`, which are deprecated. See [bazelbuild#7899](bazelbuild#7899) for information on declaring Python toolchains and migrating your code. As a side-benefit, this addresses [bazelbuild#4815](bazelbuild#4815) (incorrect interpreter version used) on non-Windows platforms. Note however that some builds break due to getting the version they asked for -- consider setting `python_version = "PY2"` on Python 2 targets and `--host_force_python=PY2` if any Python 2 targets are used in the host configuration. You can temporarily opt out of this change with `--incompatible_use_python_toolchains=false`. PiperOrigin-RevId: 250918912
We already emit a diagnostic message when the host config's Python version overrides a Python tool's normal version. This helps users know to add --host_force_python=PY2 to their bazelrc. Without it, all they'd see is a confusing Python stack trace. With this change, we also emit a diagnostic message when the target's python_version attribute is omitted and the user has not set --host_force_python=PY2. This covers the case where both the target and the host config default to PY3, but the target was really intended to be a Python 2 target. Previously, this case sometimes worked anyway due to bazelbuild#4815, but with Python toolchains enabled it breaks and we need to help the user understand the breakage. In all cases the diagnostic is still only printed when the target has non-zero exit code and is built in host config. See also bazelbuild#7899. Fixes bazelbuild#8549. RELNOTES: None PiperOrigin-RevId: 251496135
This toolchain works just like the standard autodetecting toolchain, except that if it falls back on the `python` command, it doesn't care what version that interpreter is. This allows users to opt into the legacy behavior of bazelbuild#4815 while still enabling Python toolchains. This is particularly useful for Mac users who do not have a Python 3 runtime installed. Naturally, such users can only have Python 2 code in their builds, but it's still possible that these Python targets get analyzed by Bazel as PY3. For example, the target author may have forgotten to set the `python_version = "PY2"` attribute, or the downstream user may have not added `--host_force_python=PY2` to their bazelrc. Previously this worked because under bazelbuild#4815 Bazel would just use Python 2 for PY3 targets. Strict version checking breaks these builds, but the new non-strict toolchain provides a workaround. Fixes bazelbuild#8547 RELNOTES: None PiperOrigin-RevId: 251535571
Baseline: 5935259 Cherry picks: + fe81b49: Support of using the absolute path profile for LLVM's Context Sensitive FDO + ce5e718: Demote OptionProcessor from globals + 3ed9d36: Properly wire up BES half-close. The lack thereof was a simple oversight. + 4ca768e: standardize graph output indentation with 2 spaces + aff189a: Make sure default Linux artifacts have an associated action, even when artifact names are altered. + 8c3b3fb: Failures early in package loading will now fail all --keep_going builds. + 123c68d: Warn in more cases of possible Python version mismatch in host config + 052167e: Add a non-strict autodetecting Python toolchain + 6ef6d87: Default java toolchain target + 50fa3ec: Fix problems with the non-strict Python toolchain + e2a626c: Automated rollback of commit bc6f7cb. + 6efc5b7: Treat existence of managed directories as a part of repository dirtiness. + 3a4be3c: Add /usr/local/bin to default PATH under strict action env + 5c1005c: Automated rollback of commit 536a166. Incompatible changes: - --incompatible_disable_objc_provider_resources no longer has effect. Use of deprecated resource fields on the Objc provider is now disallowed regardless of this flag. - deleted deprecated --experimental-remote-retry* flags, please use --remote_retries instead - flipped --incompatible_list_based_execution_strategy_selection flag to be true by default. See bazelbuild#7480 for details. - Octal integer literals in Starlark are required to start with "Oo". - The "native" module is no longer available in BUILD files, all its members can be accessed directly as global symbols. This can be temporarily reverted by providing --incompatible_disallow_native_in_build_file=false as a flag to Blaze. - The "native" module is no longer available in BUILD files, all its members can be accessed directly as global symbols. This can be temporarily reverted by providing --incompatible_disallow_native_in_build_file=false as a flag to Blaze. - Turn off binary style profile format. - The "native" module is no longer available in BUILD files, all its members can be accessed directly as global symbols. This can be temporarily reverted by providing --incompatible_disallow_native_in_build_f... - cleanup that affects user provided apple frameworks is now enabled by default. See bazelbuild#7944 for more info. - Python rules now determine the Python runtime using toolchains rather than `--python_top` and `--python_path`, which are deprecated. See [bazelbuild#7899](bazelbuild#7899) for information on declaring Python toolchains and migrating your code. As a side-benefit, this addresses [bazelbuild#4815](bazelbuild#4815) (incorrect interpreter version used) on non-Windows platforms. Note however that some builds break due to getting the version they asked for -- consider setting `python_version = "PY2"` on Python 2 targets and `--host_force_python=PY2` if any Python 2 targets are used in the host configuration. You can temporarily opt out of this change with `--incompatible_use_python_toolchains=false`. - Depsets can't be iterated over unless they're converted to lists using the .to_list() method. Use --incompatible_depset_is_not_iterable=false to temporarily restore the previous behaviour. New features: - Bash, runfiles: the copy-pasted init code of the Bash runfiles library is now shorter, see `tools/bash/runfiles/runfiles.bash`. The rlocation() implementation is the same. - Bash, runfiles: the copy-pasted init code of the Bash runfiles library is now shorter, see `tools/bash/runfiles/runfiles.bash`. The rlocation() implementation is the same. - Bash, runfiles: the copy-pasted init code of the Bash runfiles library is now shorter, see `tools/bash/runfiles/runfiles.bash`. To use the new init code, you need Bazel 0.27 or newer. The old (longer) init code still works. Important changes: - The `outputs` parameter of the `rule()` function is deprecated and attached to flag `--incompatible_no_rule_outputs_param`. Migrate rules to use `OutputGroupInfo` or `attr.output` instead. See bazelbuild#7977 for more info. - The --incompatible_disable_objc_library_resources flag is being removed. Please remove it from your configs as it otherwise will fail the build. - Add a generic additional_linker_inputs attribute on cc_binary rules. - Windows, C++ autoconfigure: BAZEL_VC and BAZEL_VS may now have quotes, so if you set these envvars' values in cmd.exe via TAB-completion then you no longer need to remove the surrounding quotes. - pkg_deb has new attributes: `config` and `templates` that can be used for integration with debconf - Allow cc_import() of a DLL with no interface library on Windows, used to document runtime dependencies. - All host-configured Python tools that are built for the wrong Python version will now emit a warning message when they exit with non-zero status. See bazelbuild#7899. - deprecated --remote_local_fallback_strategy. Use `--strategy=remote,local` instead. See bazelbuild#7480. - Introduce --incompatible_disable_native_android_rules flag - The Android desugaring actions now support a persistent worker mode for faster local build performance. Enable it with `--strategy=Desugar=worker`. - --incompatible_static_name_resolution_in_build_files is now enabled by default - --incompatible_disable_deprecated_attr_params is now enabled by default (bazelbuild#5818) - Repository containing autoconfigured C++ toolchain `@local_config_cc` has been split in 2 - see `local_config_cc_toolchains`. - --incompatible_string_join_requires_strings is now enabled by default - Flag --incompatible_new_actions_api is enabled by dewfault (bazelbuild#5825) - New flag `--incompatible_disallow_empty_glob`. See bazelbuild#8195 - --incompatible_no_kwargs_in_build_files is enabled by default - Incompatible flag `--incompatible_require_ctx_in_configure_features` has been flipped. See bazelbuild#7793 for more information. - `BAZEL_USE_XCODE_TOOLCHAIN=1` tells Bazel not to look for Xcode to decide whether to enable toolchains for Apple rules, but to assume Xcode is available. Can be also used when building on Darwin and no C++ or ObjC is being built, so there is no need to detect Xcode. - Android desugaring actions now use persistent workers by default. This has been measured to provide up to 20% reduction in build times. To disable it, use the `--strategy=Desugar=sandboxed` flag. See bazelbuild#8342 and bazelbuild#8427 for more details on local build speed optimization for Android apps. - Fixed an issue with Android builds where `--fat_apk_cpu` doesn't pack all selected shared libraries from `aar_import` targets into the APK. See [bazelbuild#8283](bazelbuild#8283). - Turn on --experimental_starlark_config_transitions by default for starlark transitions (see https://docs.bazel.build/versions/master/skylark/config.html#user- defined-transitions for more info) - Turn on --experimental_build_setting_api by default for starlark build settings (see https://docs.bazel.build/versions/master/skylark/config.html#user- defined-build-settings for more info) - Incompatible flag `--incompatible_dont_enable_host_nonhost_crosstool_features` has been flipped. See bazelbuild#7407 for more information. - Added support for Android NDK 19 and 20. - Flip --incompatible_no_support_tools_in_action_inputs - --remote_executor, --remote_cache or --bes_backend=someurl.com would be treated as grpcs://someurl.com, if the --incompatible_tls_enabled_removed flag enabled. See bazelbuild#8061 for details. - Add new options --cs_fdo_absolute_path= to support the absolute path profile for LLVM's context-sensitive FDO. - When `--incompatible_strict_action_env` is enabled, the default `PATH` now includes `/usr/local/bin`. - Turn on --experimental_build_setting_api by default for starlark build settings (see https://docs.bazel.build/versions/master/skylark/config.html#user- defined-build-settings for more info) This release contains contributions from many people at Google, as well as Alex Thompson, Andy Scott, Benjamin Peterson, David McNett, Drew Gassaway, Ira Shikhman, James deBoer, Jay Vercellone, Jingwen Chen, Josh Rosen, Keith Smiley, Laurent Le Brun, Lee Mracek, Marwan Tammam, Matt Passell, Michael Hackner, Michal Majcherski, Patrick Niklaus, Peter Mounce, Ricky Pai, Steeve Morin, szakmary, Takuto Ikuta, Vladimir Chebotarev, Yen-Chi Chen.
bump This has been open for over three years; the workarounds specify deprecated flags. |
The current docs for the
This leads me to believe that Furthermore, the linked workaround uses deprecated rules and flags ( It also appears according to this update that this bug may currently be fixed for all platforms except Windows. If all of this is correct, some updates that might help are:
|
Summary: This works around bazelbuild/bazel#4815 and also removes our dependcy on the system python which in general is a good thing. GitOrigin-RevId: 6aabd21482e39d0389945b05bdd6d87e3df2da09
(This is a roll-forward of bazelbuild/bazel@bf66dc7.) This flips --incompatible_use_python_toolchains, which deprecates --python_top (and for the most part, --python_path). See #7899 for more on the change and migration procedure. Known downstream breakages are summarized [here](bazelbuild/bazel#7899 (comment)). Fixes #7899, fixes #7375, significant progress on #4815. RELNOTES[INC]: Python rules now determine the Python runtime using toolchains rather than `--python_top` and `--python_path`, which are deprecated. See [#7899](bazelbuild/bazel#7899) for information on declaring Python toolchains and migrating your code. As a side-benefit, this addresses [#4815](bazelbuild/bazel#4815) (incorrect interpreter version used) on non-Windows platforms. Note however that some builds break due to getting the version they asked for -- consider setting `python_version = "PY2"` on Python 2 targets and `--host_force_python=PY2` if any Python 2 targets are used in the host configuration. You can temporarily opt out of this change with `--incompatible_use_python_toolchains=false`. PiperOrigin-RevId: 250918912
Thank you for contributing to the Bazel repository! This issue has been marked as stale since it has not had any activity in the last 1+ years. It will be closed in the next 14 days unless any other activity occurs or one of the following labels is added: "not stale", "awaiting-bazeler". Please reach out to the triage team ( |
This issue has been automatically closed due to inactivity. If you're still interested in pursuing this, please reach out to the triage team ( |
Description of the problem / feature request:
Running
py_test()
andpy_binary()
rules under bazel doesn't selectpython3
when onlysrcs_version="PY3", default_python_version="PY3"
attributes are set on the rules. How do you specify python2/3 builds?Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
I wrote an integration test: emcfarlane@5a6feef
bazel.log
What operating system are you running Bazel on?
Mac
What's the output of
bazel info release
?release 0.10.0-homebrew
What's the output of
git remote get-url origin ; git rev-parse master ; git rev-parse HEAD
?Have you found anything relevant by searching the web?
#3871
#3517
bazelbuild/rules_python#62
The text was updated successfully, but these errors were encountered: