fix(py_console_script_binary): only create _script_gen for the exec cfg (#4219)
Without this, `py_console_script_gen` exists for both the target and
exec config which causes issues when cross-compiling.
I use py_console_script_binary for glad2 which I pass as a tool to a
genrule, but starting with rules_python 2.0.0 I get the following error
when e.g. cross-compiling to wasm:
```
DEBUG: /home/runner/.cache/bazel/_bazel_runner/a9f0723b1e9e47cd91eaa9d5188be59d/external/rules_python+/python/private/config_settings.bzl:248:14: The current configuration rules_python config flags is:
@@rules_python+//python/config_settings:pip_whl_osx_version: ""
@@rules_python+//python/config_settings:py_freethreaded: "no"
@@rules_python+//python/config_settings:py_linux_libc: "glibc"
@@rules_python+//python/config_settings:python_version: "3.14"
If the value is missing, then the default value is being used, see documentation:
https://rules-python.readthedocs.io/en/latest/api/rules_python/python/config_settings
ERROR: /home/runner/.cache/bazel/_bazel_runner/a9f0723b1e9e47cd91eaa9d5188be59d/external/rules_python++pip+hastur_pypi/glad2/BUILD.bazel:6:12: configurable attribute "actual" in @@rules_python++pip+hastur_pypi//glad2:_no_matching_repository doesn't match this configuration: No matching wheel for current configuration's Python version and platform.
The current build configuration's Python version doesn't match any of the Python
wheels available for this distribution. This distribution supports the following Python
configuration settings:
//_config:is_cp314_linux_x86_64
As configured by the `pip.parse.target_platforms` attribute. Note that
`requirements_by_platform` only affects the Bazel host platform unless
`target_platforms` is also set.
To determine the current configuration's Python version, run:
`bazel config <config id>` (shown further below)
For the current configuration value see the debug message above that is
printing the current flag values. If you can't see the message, then re-run the
build to make it a failure instead by running the build with:
--@@rules_python+//python/config_settings:current_config=fail
However, the command above will hide the `bazel config <config id>` message.
This instance of @@rules_python++pip+hastur_pypi//glad2:_no_matching_repository has configuration identifier 98696d4. To inspect its configuration, run: bazel config 98696d4.
For more help, see https://bazel.build/docs/configurable-attributes#faq-select-choose-condition.
```
With this change, Bazel seems happy to only run the
`py_console_script_gen` bits for the exec config and my
cross-compilation works again.
---------
Co-authored-by: Ignas Anikevicius <240938+aignas@users.noreply.github.com>
This repository is the home of the core Python rules -- py_library, py_binary, py_test, and related symbols that provide the basis for Python support in Bazel. It also contains package installation rules for integrating with PyPI and other indices.
Documentation for rules_python is at https://rules-python.readthedocs.io and in the Bazel Build Encyclopedia.
Examples live in the examples directory.
The core rules are stable. Their implementation is subject to Bazel's backward compatibility policy. This repository aims to follow semantic versioning.
The Bazel community maintains this repository. Neither Google nor the Bazel team provides support for the code. However, this repository is part of the test suite used to vet new Bazel releases. See How to contribute page for information on our development workflow.
requirements.txt is how users have been defining dependencies for a long time. We support this to support legacy usecases or package managers that we don't support directly. Any additional information that we need will be retrieved from the SimpleAPI during the bzlmod extension evaluation phase. Then it will be written to the MODULE.bazel.lock file for future reuse. We have plans to support uv.lock file directly. uv is recommended for generating a fully locked requirements.txt file and we do provide a rule for it.py_binary, py_test rules should scale to large monorepos and we work hard to minimize the work done during analysis and build phase. What is more, the space requirements for should be minimal, so we strive to use symlinks rather than extracting wheels at build time. This means that for different configurations of the same build, we are not extracting the wheel multiple times thus scaling better over the time. From 2.0 onwards we are creating a virtual env for each target by creating an actual minimal virtual environment using symlinks. We plan on creating the traditional site-packages layout in the future by default.rules_python and this has resulted in a few PEPs supported within pure starlark - PEP440, PEP509.Common misconceptions:
rules_python has to keep backwards compatibility with google3. Whilst this might have been true in the past, rules_python is an open source project and any compatibility needs should come from the community - we have no requirement to keep this compatibility and are allowed to make our decisions. However, we do want to keep backwards compatibility as long as possible to not upset users with never ending migrations.rules_python is not caching pip downloads. With 2.0, we use Bazel's downloader by default and rely on bazel to provide the repository caching mechanisms. This means that for simpler setups this should result in transparent and scalable caching with the most recent bazel versions unless there are issues in the bazel itself.For detailed documentation, see https://rules-python.readthedocs.io
See Bzlmod support for more details.