1:::{default-domain} bzl 2::: 3 4# rules_python Changelog 5 6This is a human-friendly changelog in a keepachangelog.com style format. 7Because this changelog is for end-user consumption of meaningful changes,only 8a summary of a release's changes is described. This means every commit is not 9necessarily mentioned, and internal refactors or code cleanups are omitted 10unless they're particularly notable. 11 12A brief description of the categories of changes: 13 14* `Changed`: Some behavior changed. If the change is expected to break a 15 public API or supported behavior, it will be marked as **BREAKING**. Note that 16 beta APIs will not have breaking API changes called out. 17* `Fixed`: A bug, or otherwise incorrect behavior, was fixed. 18* `Added`: A new feature, API, or behavior was added in a backwards compatible 19 manner. 20* Particular sub-systems are identified using parentheses, e.g. `(bzlmod)` or 21 `(docs)`. 22 23## Unreleased 24 25[x.x.x]: https://github.com/bazelbuild/rules_python/releases/tag/x.x.x 26 27### Changed 28* Nothing yet 29 30### Fixed 31* Nothing yet 32 33### Added 34* Nothing yet 35 36### Removed 37* Nothing yet 38 39## [0.36.0] - 2024-09-24 40 41[0.36.0]: https://github.com/bazelbuild/rules_python/releases/tag/0.36.0 42 43### Changed 44* (gazelle): Update error messages when unable to resolve a dependency to be more human-friendly. 45* (flags) The {obj}`--python_version` flag now also returns 46 {obj}`config_common.FeatureFlagInfo`. 47* (toolchain): The toolchain patches now expose the `patch_strip` attribute 48 that one should use when patching toolchains. Please set it if you are 49 patching python interpreter. In the next release the default will be set to 50 `0` which better reflects the defaults used in public `bazel` APIs. 51* (toolchains) When {obj}`py_runtime.interpreter_version_info` isn't specified, 52 the {obj}`--python_version` flag will determine the value. This allows 53 specifying the build-time Python version for the 54 {obj}`runtime_env_toolchains`. 55* (toolchains) {obj}`py_cc_toolchain.libs` and {obj}`PyCcToolchainInfo.libs` is 56 optional. This is to support situations where only the Python headers are 57 available. 58* (bazel) Minimum bazel 7 version that we test against has been bumped to `7.1`. 59 60### Fixed 61* (whl_library): Remove `--no-index` and add `--no-build-isolation` to the 62 `pip install` command when installing a wheel from a local file, which happens 63 when `experimental_index_url` flag is used. 64* (bzlmod) get the path to the host python interpreter in a way that results in 65 platform non-dependent hashes in the lock file when the requirement markers need 66 to be evaluated. 67* (bzlmod) correctly watch sources used for evaluating requirement markers for 68 any changes so that the repository rule or module extensions can be 69 re-evaluated when the said files change. 70* (gazelle): Fix incorrect use of `t.Fatal`/`t.Fatalf` in tests. 71* (toolchain) Omit third-party python packages from coverage reports from 72 stage2 bootstrap template. 73* (bzlmod) Properly handle relative path URLs in parse_simpleapi_html.bzl 74* (gazelle) Correctly resolve deps that have top-level module overlap with a gazelle_python.yaml dep module 75* (rules) Make `RUNFILES_MANIFEST_FILE`-based invocations work when used with 76 {obj}`--bootstrap_impl=script`. This fixes invocations using non-sandboxed 77 test execution with `--enable_runfiles=false --build_runfile_manifests=true`. 78 ([#2186](https://github.com/bazelbuild/rules_python/issues/2186)). 79* (py_wheel) Fix incorrectly generated `Required-Dist` when specifying requirements with markers 80 in extra_requires in py_wheel rule. 81* (rules) Prevent pytest from trying run the generated stage2 82 bootstrap .py file when using {obj}`--bootstrap_impl=script` 83* (toolchain) The {bzl:obj}`gen_python_config_settings` has been fixed to include 84 the flag_values from the platform definitions. 85 86 87### Added 88* (bzlmod): Toolchain overrides can now be done using the new 89 {bzl:obj}`python.override`, {bzl:obj}`python.single_version_override` and 90 {bzl:obj}`python.single_version_platform_override` tag classes. 91 See [#2081](https://github.com/bazelbuild/rules_python/issues/2081). 92* (rules) Executables provide {obj}`PyExecutableInfo`, which contains 93 executable-specific information useful for packaging an executable or 94 or deriving a new one from the original. 95* (py_wheel) Removed use of bash to avoid failures on Windows machines which do not 96 have it installed. 97* (docs) Automatically generated documentation for {bzl:obj}`python_register_toolchains` 98 and related symbols. 99* (toolchains) Added {attr}`python_repository.patch_strip` attribute for 100 allowing values that are other than `1`, which has been hard-coded up until 101 now. If you are relying on the undocumented `patches` support in 102 `TOOL_VERSIONS` for registering patched toolchains please consider setting 103 the `patch_strip` explicitly to `1` if you depend on this value - in the 104 future the value may change to default to `0`. 105* (toolchains) Added `//python:none`, a special target for use with 106 {obj}`py_exec_tools_toolchain.exec_interpreter` to treat the value as `None`. 107 108### Removed 109* (toolchains): Removed accidentally exposed `http_archive` symbol from 110 `python/repositories.bzl`. 111* (toolchains): An internal _is_python_config_setting_ macro has been removed. 112 113## [0.35.0] - 2024-08-15 114 115[0.35.0]: https://github.com/bazelbuild/rules_python/releases/tag/0.35.0 116 117### Changed 118* (whl_library) A better log message when the wheel is built from an sdist or 119 when the wheel is downloaded using `download_only` feature to aid debugging. 120* (gazelle): Simplify and make gazelle_python.yaml have only top level package name. 121 It would work well in cases to reduce merge conflicts. 122* (toolchains): Change some old toochain versions to use [20240726] release to 123 include dependency updates `3.8.19`, `3.9.19`, `3.10.14`, `3.11.9` 124* (toolchains): Bump default toolchain versions to: 125 * `3.12 -> 3.12.4` 126* (rules) `PYTHONSAFEPATH` is inherited from the calling environment to allow 127 disabling it (Requires {obj}`--bootstrap_impl=script`) 128 ([#2060](https://github.com/bazelbuild/rules_python/issues/2060)). 129 130### Fixed 131* (rules) `compile_pip_requirements` now sets the `USERPROFILE` env variable on 132 Windows to work around an issue where `setuptools` fails to locate the user's 133 home directory. 134* (rules) correctly handle absolute URLs in parse_simpleapi_html.bzl. 135* (rules) Fixes build targets linking against `@rules_python//python/cc:current_py_cc_libs` 136 in host platform builds on macOS, by editing the `LC_ID_DYLIB` field of the hermetic interpreter's 137 `libpython3.x.dylib` using `install_name_tool`, setting it to its absolute path under Bazel's 138 execroot. 139* (rules) Signals are properly received when using {obj}`--bootstrap_impl=script` 140 (for non-zip builds). 141 ([#2043](https://github.com/bazelbuild/rules_python/issues/2043)) 142* (rules) Fixes Python builds when the `--build_python_zip` is set to `false` on 143 Windows. See [#1840](https://github.com/bazelbuild/rules_python/issues/1840). 144* (rules) Fixes Mac + `--build_python_zip` + {obj}`--bootstrap_impl=script` 145 ([#2030](https://github.com/bazelbuild/rules_python/issues/2030)). 146* (rules) User dependencies come before runtime site-packages when using 147 {obj}`--bootstrap_impl=script`. 148 ([#2064](https://github.com/bazelbuild/rules_python/issues/2064)). 149* (rules) Version-aware rules now return both `@_builtins` and `@rules_python` 150 providers instead of only one. 151 ([#2114](https://github.com/bazelbuild/rules_python/issues/2114)). 152* (pip) Fixed pypi parse_simpleapi_html function for feeds with package metadata 153 containing ">" sign 154* (toolchains) Added missing executable permission to 155 `//python/runtime_env_toolchains` interpreter script so that it is runnable. 156 ([#2085](https://github.com/bazelbuild/rules_python/issues/2085)). 157* (pip) Correctly use the `sdist` downloaded by the bazel downloader when using 158 `experimental_index_url` feature. Fixes 159 [#2091](https://github.com/bazelbuild/rules_python/issues/2090). 160* (gazelle) Make `gazelle_python_manifest.update` manual to avoid unnecessary 161 network behavior. 162* (bzlmod): The conflicting toolchains during `python` extension will no longer 163 cause warnings by default. In order to see the warnings for diagnostic purposes 164 set the env var `RULES_PYTHON_REPO_DEBUG_VERBOSITY` to one of `INFO`, `DEBUG` or `TRACE`. 165 Fixes [#1818](https://github.com/bazelbuild/rules_python/issues/1818). 166* (runfiles) Make runfiles lookups work for the situation of Bazel 7, 167 Python 3.9 (or earlier, where safepath isn't present), and the Rlocation call 168 in the same directory as the main file. 169 Fixes [#1631](https://github.com/bazelbuild/rules_python/issues/1631). 170 171### Added 172* (rules) `compile_pip_requirements` supports multiple requirements input files as `srcs`. 173* (rules) `PYTHONSAFEPATH` is inherited from the calling environment to allow 174 disabling it (Requires {obj}`--bootstrap_impl=script`) 175 ([#2060](https://github.com/bazelbuild/rules_python/issues/2060)). 176* (gazelle) Added `python_generation_mode_per_package_require_test_entry_point` 177 in order to better accommodate users who use a custom macro, 178 [`pytest-bazel`][pytest_bazel], [rules_python_pytest] or `rules_py` 179 [py_test_main] in order to integrate with `pytest`. Currently the default 180 flag value is set to `true` for backwards compatible behaviour, but in the 181 future the flag will be flipped be `false` by default. 182* (toolchains) New Python versions available: `3.12.4` using the [20240726] release. 183* (pypi) Support env markers in requirements files. Note, that this means that 184 if your requirements files contain env markers, the Python interpreter will 185 need to be run during bzlmod phase to evaluate them. This may incur 186 downloading an interpreter (for hermetic-based builds) or cause non-hermetic 187 behavior (if using a system Python). 188 189[rules_python_pytest]: https://github.com/caseyduquettesc/rules_python_pytest 190[py_test_main]: https://docs.aspect.build/rulesets/aspect_rules_py/docs/rules/#py_pytest_main 191[pytest_bazel]: https://pypi.org/project/pytest-bazel 192[20240726]: https://github.com/indygreg/python-build-standalone/releases/tag/20240726 193 194## [0.34.0] - 2024-07-04 195 196[0.34.0]: https://github.com/bazelbuild/rules_python/releases/tag/0.34.0 197 198### Changed 199* `protobuf`/`com_google_protobuf` dependency bumped to `v24.4` 200* (bzlmod): optimize the creation of config settings used in pip to 201 reduce the total number of targets in the hub repo. 202* (toolchains) The exec tools toolchain now finds its interpreter by reusing 203 the regular interpreter toolchain. This avoids having to duplicate specifying 204 where the runtime for the exec tools toolchain is. 205* (toolchains) ({obj}`//python:autodetecting_toolchain`) is deprecated. It is 206 replaced by {obj}`//python/runtime_env_toolchains:all`. The old target will be 207 removed in a future release. 208 209### Fixed 210* (bzlmod): When using `experimental_index_url` the `all_requirements`, 211 `all_whl_requirements` and `all_data_requirements` will now only include 212 common packages that are available on all target platforms. This is to ensure 213 that packages that are only present for some platforms are pulled only via 214 the `deps` of the materialized `py_library`. If you would like to include 215 platform specific packages, using a `select` statement with references to the 216 specific package will still work (e.g. 217 ``` 218 my_attr = all_requirements + select( 219 { 220 "@platforms//os:linux": ["@pypi//foo_available_only_on_linux"], 221 "//conditions:default": [], 222 } 223 ) 224 ``` 225* (bzlmod): Targets in `all_requirements` now use the same form as targets returned by the `requirement` macro. 226* (rules) Auto exec groups are enabled. This allows actions run by the rules, 227 such as precompiling, to pick an execution platform separately from what 228 other toolchains support. 229* (providers) {obj}`PyRuntimeInfo` doesn't require passing the 230 `interpreter_version_info` arg. 231* (bzlmod) Correctly pass `isolated`, `quiet` and `timeout` values to `whl_library` 232 and drop the defaults from the lock file. 233* (whl_library) Correctly handle arch-specific dependencies when we encounter a 234 platform specific wheel and use `experimental_target_platforms`. 235 Fixes [#1996](https://github.com/bazelbuild/rules_python/issues/1996). 236* (rules) The first element of the default outputs is now the executable again. 237* (pip) Fixed crash when pypi packages lacked a sha (e.g. yanked packages) 238 239### Added 240* (toolchains) {obj}`//python/runtime_env_toolchains:all`, which is a drop-in 241 replacement for the "autodetecting" toolchain. 242* (gazelle) Added new `python_label_convention` and `python_label_normalization` directives. These directive 243 allows altering default Gazelle label format to third-party dependencies useful for re-using Gazelle plugin 244 with other rules, including `rules_pycross`. See [#1939](https://github.com/bazelbuild/rules_python/issues/1939). 245 246### Removed 247* (pip): Removes the `entrypoint` macro that was replaced by `py_console_script_binary` in 0.26.0. 248 249## [0.33.2] - 2024-06-13 250 251[0.33.2]: https://github.com/bazelbuild/rules_python/releases/tag/0.33.2 252 253### Fixed 254* (toolchains) The {obj}`exec_tools_toolchain_type` is disabled by default. 255 To enable it, set {obj}`--//python/config_settings:exec_tools_toolchain=enabled`. 256 This toolchain must be enabled for precompilation to work. This toolchain will 257 be enabled by default in a future release. 258 Fixes [#1967](https://github.com/bazelbuild/rules_python/issues/1967). 259 260## [0.33.1] - 2024-06-13 261 262[0.33.1]: https://github.com/bazelbuild/rules_python/releases/tag/0.33.1 263 264### Fixed 265* (py_binary) Fix building of zip file when using `--build_python_zip` 266 argument. Fixes [#1954](https://github.com/bazelbuild/rules_python/issues/1954). 267 268## [0.33.0] - 2024-06-12 269 270[0.33.0]: https://github.com/bazelbuild/rules_python/releases/tag/0.33.0 271 272### Changed 273* (deps) Upgrade the `pip_install` dependencies to pick up a new version of pip. 274* (toolchains) Optional toolchain dependency: `py_binary`, `py_test`, and 275 `py_library` now depend on the `//python:exec_tools_toolchain_type` for build 276 tools. 277* (deps): Bumped `bazel_skylib` to 1.6.1. 278* (bzlmod): The `python` and internal `rules_python` extensions have been 279 marked as `reproducible` and will not include any lock file entries from now 280 on. 281* (gazelle): Remove gazelle plugin's python deps and make it hermetic. 282 Introduced a new Go-based helper leveraging tree-sitter for syntax analysis. 283 Implemented the use of `pypi/stdlib-list` for standard library module verification. 284* (pip.parse): Do not ignore yanked packages when using `experimental_index_url`. 285 This is to mimic what `uv` is doing. We will print a warning instead. 286* (pip.parse): Add references to all supported wheels when using `experimental_index_url` 287 to allowing to correctly fetch the wheels for the right platform. See the 288 updated docs on how to use the feature. This is work towards addressing 289 [#735](https://github.com/bazelbuild/rules_python/issues/735) and 290 [#260](https://github.com/bazelbuild/rules_python/issues/260). The spoke 291 repository names when using this flag will have a structure of 292 `{pip_hub_prefix}_{wheel_name}_{py_tag}_{abi_tag}_{platform_tag}_{sha256}`, 293 which is an implementation detail which should not be relied on and is there 294 purely for better debugging experience. 295* (bzlmod) The `pythons_hub//:interpreters.bzl` no longer has platform-specific 296 labels which where left there for compatibility reasons. Move to 297 `python_{version}_host` keys if you would like to have access to a Python 298 interpreter that can be used in a repository rule context. 299 300### Fixed 301* (gazelle) Remove `visibility` from `NonEmptyAttr`. 302 Now empty(have no `deps/main/srcs/imports` attr) `py_library/test/binary` rules will 303 be automatically deleted correctly. For example, if `python_generation_mode` 304 is set to package, when `__init__.py` is deleted, the `py_library` generated 305 for this package before will be deleted automatically. 306* (whl_library): Use _is_python_config_setting_ to correctly handle multi-python 307 version dependency select statements when the `experimental_target_platforms` 308 includes the Python ABI. The default python version case within the select is 309 also now handled correctly, stabilizing the implementation. 310* (gazelle) Fix Gazelle failing on Windows with 311 "panic: runtime error: invalid memory address or nil pointer dereference" 312* (bzlmod) remove `pip.parse(annotations)` attribute as it is unused and has been 313 replaced by whl_modifications. 314* (pip) Correctly select wheels when the python tag includes minor versions. 315 See ([#1930](https://github.com/bazelbuild/rules_python/issues/1930)) 316* (pip.parse): The lock file is now reproducible on any host platform if the 317 `experimental_index_url` is not used by any of the modules in the dependency 318 chain. To make the lock file identical on each `os` and `arch`, please use 319 the `experimental_index_url` feature which will fetch metadata from PyPI or a 320 different private index and write the contents to the lock file. Fixes 321 [#1643](https://github.com/bazelbuild/rules_python/issues/1643). 322* (pip.parse): Install `yanked` packages and print a warning instead of 323 ignoring them. This better matches the behaviour of `uv pip install`. 324* (toolchains): Now matching of the default hermetic toolchain is more robust 325 and explicit and should fix rare edge-cases where the host toolchain 326 autodetection would match a different toolchain than expected. This may yield 327 to toolchain selection failures when the python toolchain is not registered, 328 but is requested via `//python/config_settings:python_version` flag setting. 329* (doc) Fix the `WORKSPACE` requirement vendoring example. Fixes 330 [#1918](https://github.com/bazelbuild/rules_python/issues/1918). 331 332### Added 333* (rules) Precompiling Python source at build time is available. but is 334 disabled by default, for now. Set 335 `@rules_python//python/config_settings:precompile=enabled` to enable it 336 by default. A subsequent release will enable it by default. See the 337 [Precompiling docs][precompile-docs] and API reference docs for more 338 information on precompiling. Note this requires Bazel 7+ and the Pystar rule 339 implementation enabled. 340 ([#1761](https://github.com/bazelbuild/rules_python/issues/1761)) 341* (rules) Attributes and flags to control precompile behavior: `precompile`, 342 `precompile_optimize_level`, `precompile_source_retention`, 343 `precompile_invalidation_mode`, and `pyc_collection` 344* (toolchains) The target runtime toolchain (`//python:toolchain_type`) has 345 two new optional attributes: `pyc_tag` (tells the pyc filename infix to use) and 346 `implementation_name` (tells the Python implementation name). 347* (toolchains) A toolchain type for build tools has been added: 348 `//python:exec_tools_toolchain_type`. 349* (providers) `PyInfo` has two new attributes: `direct_pyc_files` and 350 `transitive_pyc_files`, which tell the pyc files a target makes available 351 directly and transitively, respectively. 352* `//python:features.bzl` added to allow easy feature-detection in the future. 353* (pip) Allow specifying the requirements by (os, arch) and add extra 354 validations when parsing the inputs. This is a non-breaking change for most 355 users unless they have been passing multiple `requirements_*` files together 356 with `extra_pip_args = ["--platform=manylinux_2_4_x86_64"]`, that was an 357 invalid usage previously but we were not failing the build. From now on this 358 is explicitly disallowed. 359* (toolchains) Added riscv64 platform definition for python toolchains. 360* (gazelle) The `python_visibility` directive now supports the `$python_root$` 361 placeholder, just like the `python_default_visibility` directive does. 362* (rules) A new bootstrap implementation that doesn't require a system Python 363 is available. It can be enabled by setting 364 {obj}`--@rules_python//python/config_settings:bootstrap_impl=script`. It 365 will become the default in a subsequent release. 366 ([#691](https://github.com/bazelbuild/rules_python/issues/691)) 367* (providers) `PyRuntimeInfo` has two new attributes: 368 {obj}`PyRuntimeInfo.stage2_bootstrap_template` and 369 {obj}`PyRuntimeInfo.zip_main_template`. 370* (toolchains) A replacement for the Bazel-builtn autodetecting toolchain is 371 available. The `//python:autodetecting_toolchain` alias now uses it. 372* (pip): Support fetching and using the wheels for other platforms. This 373 supports customizing whether the linux wheels are pulled for `musl` or 374 `glibc`, whether `universal2` or arch-specific MacOS wheels are preferred and 375 it also allows to select a particular `libc` version. All of this is done via 376 the `string_flags` in `@rules_python//python/config_settings`. If there are 377 no wheels that are supported for the target platform, `rules_python` will 378 fallback onto building the `sdist` from source. This behaviour can be 379 disabled if desired using one of the available string flags as well. 380* (whl_filegroup) Added a new `whl_filegroup` rule to extract files from a wheel file. 381 This is useful to extract headers for use in a `cc_library`. 382 383[precompile-docs]: /precompiling 384 385## [0.32.2] - 2024-05-14 386 387[0.32.2]: https://github.com/bazelbuild/rules_python/releases/tag/0.32.2 388 389### Fixed 390 391* Workaround existence of infinite symlink loops on case insensitive filesystems when targeting linux platforms with recent Python toolchains. Works around an upstream [issue][indygreg-231]. Fixes [#1800][rules_python_1800]. 392 393[indygreg-231]: https://github.com/indygreg/python-build-standalone/issues/231 394[rules_python_1800]: https://github.com/bazelbuild/rules_python/issues/1800 395 396## [0.32.0] - 2024-05-12 397 398[0.32.0]: https://github.com/bazelbuild/rules_python/releases/tag/0.32.0 399 400### Changed 401 402* (bzlmod): The `MODULE.bazel.lock` `whl_library` rule attributes are now 403 sorted in the attributes section. We are also removing values that are not 404 default in order to reduce the size of the lock file. 405* (coverage) Bump `coverage.py` to [7.4.3](https://github.com/nedbat/coveragepy/blob/master/CHANGES.rst#version-743--2024-02-23). 406* (deps): Bumped `bazel_features` to 1.9.1 to detect optional support 407 non-blocking downloads. 408* (deps): Updated `pip_tools` to >= 7.4.0 409* (toolchains): Change some old toolchain versions to use [20240224] release to 410 include security fixes `3.8.18`, `3.9.18` and `3.10.13` 411* (toolchains): Bump default toolchain versions to: 412 * `3.8 -> 3.8.19` 413 * `3.9 -> 3.9.19` 414 * `3.10 -> 3.10.14` 415 * `3.11 -> 3.11.9` 416 * `3.12 -> 3.12.3` 417 418### Fixed 419 420* (whl_library): Fix the experimental_target_platforms overriding for platform 421 specific wheels when the wheels are for any python interpreter version. Fixes 422 [#1810](https://github.com/bazelbuild/rules_python/issues/1810). 423* (whl_library): Stop generating duplicate dependencies when encountering 424 duplicates in the METADATA. Fixes 425 [#1873](https://github.com/bazelbuild/rules_python/issues/1873). 426* (gazelle) In `project` or `package` generation modes, do not generate `py_test` 427 rules when there are no test files and do not set `main = "__test__.py"` when 428 that file doesn't exist. 429* (whl_library) The group redirection is only added when the package is part of 430 the group potentially fixing aspects that want to traverse a `py_library` graph. 431 Fixes [#1760](https://github.com/bazelbuild/rules_python/issues/1760). 432* (bzlmod) Setting a particular micro version for the interpreter and the 433 `pip.parse` extension is now possible, see the 434 `examples/pip_parse/MODULE.bazel` for how to do it. 435 See [#1371](https://github.com/bazelbuild/rules_python/issues/1371). 436* (refactor) The pre-commit developer workflow should now pass `isort` and `black` 437 checks (see [#1674](https://github.com/bazelbuild/rules_python/issues/1674)). 438 439### Added 440 441* (toolchains) Added armv7 platform definition for python toolchains. 442* (toolchains) New Python versions available: `3.11.8`, `3.12.2` using the [20240224] release. 443* (toolchains) New Python versions available: `3.8.19`, `3.9.19`, `3.10.14`, `3.11.9`, `3.12.3` using 444 the [20240415] release. 445* (gazelle) Added a new `python_visibility` directive to control visibility 446 of generated targets by appending additional visibility labels. 447* (gazelle) Added a new `python_default_visibility` directive to control the 448 _default_ visibility of generated targets. See the [docs][python_default_visibility] 449 for details. 450* (gazelle) Added a new `python_test_file_pattern` directive. This directive tells 451 gazelle which python files should be mapped to the `py_test` rule. See the 452 [original issue][test_file_pattern_issue] and the [docs][test_file_pattern_docs] 453 for details. 454* (wheel) Add support for `data_files` attributes in py_wheel rule 455 ([#1777](https://github.com/bazelbuild/rules_python/issues/1777)) 456* (py_wheel) `bzlmod` installations now provide a `twine` setup for the default 457 Python toolchain in `rules_python` for version 3.11. 458* (bzlmod) New `experimental_index_url`, `experimental_extra_index_urls` and 459 `experimental_index_url_overrides` to `pip.parse` for using the bazel 460 downloader. If you see any issues, report in 461 [#1357](https://github.com/bazelbuild/rules_python/issues/1357). The URLs for 462 the whl and sdist files will be written to the lock file. Controlling whether 463 the downloading of metadata is done in parallel can be done using 464 `parallel_download` attribute. 465* (gazelle) Add a new annotation `include_dep`. Also add documentation for 466 annotations to `gazelle/README.md`. 467* (deps): `rules_python` depends now on `rules_cc` 0.0.9 468* (pip_parse): A new flag `use_hub_alias_dependencies` has been added that is going 469 to become default in the next release. This makes use of `dep_template` flag 470 in the `whl_library` rule. This also affects the 471 `experimental_requirement_cycles` feature where the dependencies that are in 472 a group would be only accessible via the hub repo aliases. If you still 473 depend on legacy labels instead of the hub repo aliases and you use the 474 `experimental_requirement_cycles`, now is a good time to migrate. 475 476[python_default_visibility]: gazelle/README.md#directive-python_default_visibility 477[test_file_pattern_issue]: https://github.com/bazelbuild/rules_python/issues/1816 478[test_file_pattern_docs]: gazelle/README.md#directive-python_test_file_pattern 479[20240224]: https://github.com/indygreg/python-build-standalone/releases/tag/20240224. 480[20240415]: https://github.com/indygreg/python-build-standalone/releases/tag/20240415. 481 482 483## [0.31.0] - 2024-02-12 484 485[0.31.0]: https://github.com/bazelbuild/rules_python/releases/tag/0.31.0 486 487### Changed 488 489* For Bazel 7, the core rules and providers are now implemented in rules_python 490 directly and the rules bundled with Bazel are not used. Bazel 6 and earlier 491 continue to use the Bazel builtin symbols. Of particular note, this means, 492 under Bazel 7, the builtin global symbol `PyInfo` is **not** the same as what 493 is loaded from rules_python. The same is true of `PyRuntimeInfo`. 494 495## [0.30.0] - 2024-02-12 496 497[0.30.0]: https://github.com/bazelbuild/rules_python/releases/tag/0.30.0 498 499### Changed 500 501* (toolchains) Windows hosts always ignore pyc files in the downloaded runtimes. 502 This fixes issues due to pyc files being created at runtime and affecting the 503 definition of what files were considered part of the runtime. 504 505* (pip_parse) Added the `envsubst` parameter, which enables environment variable 506 substitutions in the `extra_pip_args` attribute. 507 508* (pip_repository) Added the `envsubst` parameter, which enables environment 509 variable substitutions in the `extra_pip_args` attribute. 510 511### Fixed 512 513* (bzlmod) pip.parse now does not fail with an empty `requirements.txt`. 514 515* (py_wheel) Wheels generated by `py_wheel` now preserve executable bits when 516 being extracted by `installer` and/or `pip`. 517 518* (coverage) During the running of lcov, the stdout/stderr was causing test 519 failures. By default, suppress output when generating lcov. This can be 520 overridden by setting 'VERBOSE_COVERAGE'. This change only affect bazel 521 7.x.x and above. 522 523* (toolchain) Changed the `host_toolchain` to symlink all files to support 524 Windows host environments without symlink support. 525 526* (PyRuntimeInfo) Switch back to builtin PyRuntimeInfo for Bazel 6.4 and when 527 pystar is disabled. This fixes an error about `target ... does not have ... 528 PyRuntimeInfo`. 529 ([#1732](https://github.com/bazelbuild/rules_python/issues/1732)) 530 531### Added 532 533* (py_wheel) Added `requires_file` and `extra_requires_files` attributes. 534 535* (whl_library) *experimental_target_platforms* now supports specifying the 536 Python version explicitly and the output `BUILD.bazel` file will be correct 537 irrespective of the python interpreter that is generating the file and 538 extracting the `whl` distribution. Multiple python target version can be 539 specified and the code generation will generate version specific dependency 540 closures but that is not yet ready to be used and may break the build if 541 the default python version is not selected using 542 `common --@rules_python//python/config_settings:python_version=X.Y.Z`. 543 544* New Python versions available: `3.11.7`, `3.12.1` using 545 https://github.com/indygreg/python-build-standalone/releases/tag/20240107. 546 547* (toolchain) Allow setting `x.y` as the `python_version` parameter in 548 the version-aware `py_binary` and `py_test` rules. This allows users to 549 use the same rule import for testing with specific Python versions and 550 rely on toolchain configuration and how the latest version takes precedence 551 if e.g. `3.8` is selected. That also simplifies `.bazelrc` for any users 552 that set the default `python_version` string flag in that way. 553 554* (toolchain) The runtime's shared libraries (libpython.so et al) can be 555 accessed using `@rules_python//python/cc:current_py_cc_libs`. This uses 556 toolchain resolution, so the files are from the same runtime used to run a 557 target. If you were previously using e.g. `@python_3_11//:libpython`, then 558 switch to `:current_py_cc_libs` for looser coupling to the underlying runtime 559 repo implementation. 560 561* (repo rules) The environment variable `RULES_PYTHON_REPO_DEBUG=1` can be 562 set to make repository rules log detailed information about what they're 563 up to. 564 565* (coverage) Add support for python 3.12 and bump `coverage.py` to 566 7.4.1. 567 568 569## [0.29.0] - 2024-01-22 570 571[0.29.0]: https://github.com/bazelbuild/rules_python/releases/tag/0.29.0 572 573### Changed 574 575* **BREAKING** The deprecated `incompatible_generate_aliases` feature flags 576 from `pip_parse` and `gazelle` got removed. They had been flipped to `True` 577 in 0.27.0 release. 578* **BREAKING** (wheel) The `incompatible_normalize_name` and 579 `incompatible_normalize_version` flags have been removed. They had been 580 flipped to `True` in 0.27.0 release. 581* (bzlmod) The pip hub repository now uses the newly introduced config settings 582 using the `X.Y` python version notation. This improves cross module 583 interoperability and allows to share wheels built by interpreters using 584 different patch versions. 585 586### Fixed 587 588* (bzlmod pip.parse) Use a platform-independent reference to the interpreter 589 pip uses. This reduces (but doesn't eliminate) the amount of 590 platform-specific content in `MODULE.bazel.lock` files; Follow 591 [#1643](https://github.com/bazelbuild/rules_python/issues/1643) for removing 592 platform-specific content in `MODULE.bazel.lock` files. 593 594* (wheel) The stamp variables inside the distribution name are no longer 595 lower-cased when normalizing under PEP440 conventions. 596 597### Added 598 599* (toolchains) `python_register_toolchains` now also generates a repository 600 that is suffixed with `_host`, that has a single label `:python` that is a 601 symlink to the python interpreter for the host platform. The intended use is 602 mainly in `repository_rule`, which are always run using `host` platform 603 Python. This means that `WORKSPACE` users can now copy the `requirements.bzl` 604 file for vendoring as seen in the updated `pip_parse_vendored` example. 605 606* (runfiles) `rules_python.python.runfiles.Runfiles` now has a static `Create` 607 method to make imports more ergonomic. Users should only need to import the 608 `Runfiles` object to locate runfiles. 609 610* (toolchains) `PyRuntimeInfo` now includes a `interpreter_version_info` field 611 that contains the static version information for the given interpreter. 612 This can be set via `py_runtime` when registering an interpreter toolchain, 613 and will done automatically for the builtin interpreter versions registered via 614 `python_register_toolchains`. 615 Note that this only available on the Starlark implementation of the provider. 616 617* (config_settings) Added `//python/config_settings:is_python_X.Y` config 618 settings to match on minor Python version. These settings match any `X.Y` 619 version instead of just an exact `X.Y.Z` version. 620 621## [0.28.0] - 2024-01-07 622 623[0.28.0]: https://github.com/bazelbuild/rules_python/releases/tag/0.28.0 624 625### Changed 626 627* **BREAKING** (pip_install) the deprecated `pip_install` macro and related 628 items have been removed. 629 630* **BREAKING** Support for Bazel 5 has been officially dropped. This release 631 was only partially tested with Bazel 5 and may or may not work with Bazel 5. 632 Subequent versions will no longer be tested under Bazel 5. 633 634* (runfiles) `rules_python.python.runfiles` now directly implements type hints 635 and drops support for python2 as a result. 636 637* (toolchains) `py_runtime`, `py_runtime_pair`, and `PyRuntimeInfo` now use the 638 rules_python Starlark implementation, not the one built into Bazel. NOTE: This 639 only applies to Bazel 6+; Bazel 5 still uses the builtin implementation. 640 641* (pip_parse) The parameter `experimental_requirement_cycles` may be provided a 642 map of names to lists of requirements which form a dependency 643 cycle. `pip_parse` will break the cycle for you transparently. This behavior 644 is also available under bzlmod as 645 `pip.parse(experimental_requirement_cycles={})`. 646 647* (toolchains) `py_runtime` can now take an executable target. Note: runfiles 648 from the target are not supported yet. 649 ([#1612](https://github.com/bazelbuild/rules_python/issues/1612)) 650 651* (gazelle) When `python_generation_mode` is set to `file`, create one `py_binary` 652 target for each file with `if __name__ == "__main__"` instead of just one 653 `py_binary` for the whole module. 654 655* (gazelle) the Gazelle manifest integrity field is now optional. If the 656 `requirements` argument to `gazelle_python_manifest` is unset, no integrity 657 field will be generated. 658 659### Fixed 660 661* (gazelle) The gazelle plugin helper was not working with Python toolchains 3.11 662 and above due to a bug in the helper components not being on PYTHONPATH. 663 664* (pip_parse) The repositories created by `whl_library` can now parse the `whl` 665 METADATA and generate dependency closures irrespective of the host platform 666 the generation is executed on. This can be turned on by supplying 667 `experimental_target_platforms = ["all"]` to the `pip_parse` or the `bzlmod` 668 equivalent. This may help in cases where fetching wheels for a different 669 platform using `download_only = True` feature. 670* (bzlmod pip.parse) The `pip.parse(python_interpreter)` arg now works for 671 specifying a local system interpreter. 672* (bzlmod pip.parse) Requirements files with duplicate entries for the same 673 package (e.g. one for the package, one for an extra) now work. 674* (bzlmod python.toolchain) Submodules can now (re)register the Python version 675 that rules_python has set as the default. 676 ([#1638](https://github.com/bazelbuild/rules_python/issues/1638)) 677* (whl_library) Actually use the provided patches to patch the whl_library. 678 On Windows the patching may result in files with CRLF line endings, as a result 679 the RECORD file consistency requirement is lifted and now a warning is emitted 680 instead with a location to the patch that could be used to silence the warning. 681 Copy the patch to your workspace and add it to the list if patches for the wheel 682 file if you decide to do so. 683* (coverage): coverage reports are now created when the version-aware 684 rules are used. 685 ([#1600](https://github.com/bazelbuild/rules_python/issues/1600)) 686* (toolchains) Workspace builds register the py cc toolchain (bzlmod already 687 was). This makes e.g. `//python/cc:current_py_cc_headers` Just Work. 688 ([#1669](https://github.com/bazelbuild/rules_python/issues/1669)) 689* (bzlmod python.toolchain) The value of `ignore_root_user_error` is now decided 690 by the root module only. 691 ([#1658](https://github.com/bazelbuild/rules_python/issues/1658)) 692 693### Added 694 695* (docs) bzlmod extensions are now documented on rules-python.readthedocs.io 696* (docs) Support and backwards compatibility policies have been documented. 697 See https://rules-python.readthedocs.io/en/latest/support.html 698* (gazelle) `file` generation mode can now also add `__init__.py` to the srcs 699 attribute for every target in the package. This is enabled through a separate 700 directive `python_generation_mode_per_file_include_init`. 701 702## [0.27.0] - 2023-11-16 703 704[0.27.0]: https://github.com/bazelbuild/rules_python/releases/tag/0.27.0 705 706### Changed 707 708* Make `//python/pip_install:pip_repository_bzl` `bzl_library` target internal 709 as all of the publicly available symbols (etc. `package_annotation`) are 710 re-exported via `//python:pip_bzl` `bzl_library`. 711 712* (gazelle) Gazelle Python extension no longer has runtime dependencies. Using 713 `GAZELLE_PYTHON_RUNTIME_DEPS` from `@rules_python_gazelle_plugin//:def.bzl` is 714 no longer necessary. 715 716* (pip_parse) The installation of `pip_parse` repository rule toolchain 717 dependencies is now done as part of `py_repositories` call. 718 719* (pip_parse) The generated `requirements.bzl` file now has an additional symbol 720 `all_whl_requirements_by_package` which provides a map from the normalized 721 PyPI package name to the target that provides the built wheel file. Use 722 `pip_utils.normalize_name` function from `@rules_python//python:pip.bzl` to 723 convert a PyPI package name to a key in the `all_whl_requirements_by_package` 724 map. 725 726* (pip_parse) The flag `incompatible_generate_aliases` has been flipped to 727 `True` by default on `non-bzlmod` setups allowing users to use the same label 728 strings during the transition period. For example, instead of 729 `@pypi_foo//:pkg`, you can now use `@pypi//foo` or `@pypi//foo:pkg`. Other 730 labels that are present in the `foo` package are `dist_info`, `whl` and 731 `data`. Note, that the `@pypi_foo//:pkg` labels are still present for 732 backwards compatibility. 733 734* (gazelle) The flag `use_pip_repository_aliases` is now set to `True` by 735 default, which will cause `gazelle` to change third-party dependency labels 736 from `@pip_foo//:pkg` to `@pip//foo` by default. 737 738* The `compile_pip_requirements` now defaults to `pyproject.toml` if the `src` 739 or `requirements_in` attributes are unspecified, matching the upstream 740 `pip-compile` behaviour more closely. 741 742* (gazelle) Use relative paths if possible for dependencies added through 743 the use of the `resolve` directive. 744 745* (gazelle) When using `python_generation_mode file`, one `py_test` target is 746 made per test file even if a target named `__test__` or a file named 747 `__test__.py` exists in the same package. Previously in these cases there 748 would only be one test target made. 749 750Breaking changes: 751 752* (pip) `pip_install` repository rule in this release has been disabled and 753 will fail by default. The API symbol is going to be removed in the next 754 version, please migrate to `pip_parse` as a replacement. The `pip_parse` 755 rule no longer supports `requirements` attribute, please use 756 `requirements_lock` instead. 757 758* (py_wheel) switch `incompatible_normalize_name` and 759 `incompatible_normalize_version` to `True` by default to enforce `PEP440` 760 for wheel names built by `rules_python`. 761 762* (tools/wheelmaker.py) drop support for Python 2 as only Python 3 is tested. 763 764### Fixed 765 766* Skip aliases for unloaded toolchains. Some Python versions that don't have full 767 platform support, and referencing their undefined repositories can break operations 768 like `bazel query rdeps(...)`. 769 770* Python code generated from `proto_library` with `strip_import_prefix` can be imported now. 771 772* (py_wheel) Produce deterministic wheel files and make `RECORD` file entries 773 follow the order of files written to the `.whl` archive. 774 775* (gazelle) Generate a single `py_test` target when `gazelle:python_generation_mode project` 776 is used. 777 778* (gazelle) Move waiting for the Python interpreter process to exit to the shutdown hook 779 to make the usage of the `exec.Command` more idiomatic. 780 781* (toolchains) Keep tcl subdirectory in Windows build of hermetic interpreter. 782 783* (bzlmod) sub-modules now don't have the `//conditions:default` clause in the 784 hub repos created by `pip.parse`. This should fix confusing error messages 785 in case there is a misconfiguration of toolchains or a bug in `rules_python`. 786 787### Added 788 789* (bzlmod) Added `.whl` patching support via `patches` and `patch_strip` 790 arguments to the new `pip.override` tag class. 791 792* (pip) Support for using [PEP621](https://peps.python.org/pep-0621/) compliant 793 `pyproject.toml` for creating a resolved `requirements.txt` file. 794 795* (utils) Added a `pip_utils` struct with a `normalize_name` function to allow users 796 to find out how `rules_python` would normalize a PyPI distribution name. 797 798## [0.26.0] - 2023-10-06 799 800### Changed 801 802* Python version patch level bumps: 803 * 3.8.15 -> 3.8.18 804 * 3.9.17 -> 3.9.18 805 * 3.10.12 -> 3.10.13 806 * 3.11.4 -> 3.11.6 807 808* (deps) Upgrade rules_go 0.39.1 -> 0.41.0; this is so gazelle integration works with upcoming Bazel versions 809 810* (multi-version) The `distribs` attribute is no longer propagated. This 811 attribute has been long deprecated by Bazel and shouldn't be used. 812 813* Calling `//python:repositories.bzl#py_repositories()` is required. It has 814 always been documented as necessary, but it was possible to omit it in certain 815 cases. An error about `@rules_python_internal` means the `py_repositories()` 816 call is missing in `WORKSPACE`. 817 818* (bzlmod) The `pip.parse` extension will generate os/arch specific lock 819 file entries on `bazel>=6.4`. 820 821 822### Added 823 824* (bzlmod, entry_point) Added {obj}`py_console_script_binary`, which 825 allows adding custom dependencies to a package's entry points and customizing 826 the `py_binary` rule used to build it. 827 828* New Python versions available: `3.8.17`, `3.11.5` using 829 https://github.com/indygreg/python-build-standalone/releases/tag/20230826. 830 831* (gazelle) New `# gazelle:python_generation_mode file` directive to support 832 generating one `py_library` per file. 833 834* (python_repository) Support `netrc` and `auth_patterns` attributes to enable 835 authentication against private HTTP hosts serving Python toolchain binaries. 836 837* `//python:packaging_bzl` added, a `bzl_library` for the Starlark 838 files `//python:packaging.bzl` requires. 839* (py_wheel) Added the `incompatible_normalize_name` feature flag to 840 normalize the package distribution name according to latest Python 841 packaging standards. Defaults to `False` for the time being. 842* (py_wheel) Added the `incompatible_normalize_version` feature flag 843 to normalize the package version according to PEP440 standard. This 844 also adds support for local version specifiers (versions with a `+` 845 in them), in accordance with PEP440. Defaults to `False` for the 846 time being. 847 848* New Python versions available: `3.8.18`, `3.9.18`, `3.10.13`, `3.11.6`, `3.12.0` using 849 https://github.com/indygreg/python-build-standalone/releases/tag/20231002. 850 `3.12.0` support is considered beta and may have issues. 851 852### Removed 853 854* (bzlmod) The `entry_point` macro is no longer supported and has been removed 855 in favour of the `py_console_script_binary` macro for `bzlmod` users. 856 857* (bzlmod) The `pip.parse` no longer generates `{hub_name}_{py_version}` hub repos 858 as the `entry_point` macro has been superseded by `py_console_script_binary`. 859 860* (bzlmod) The `pip.parse` no longer generates `{hub_name}_{distribution}` hub repos. 861 862### Fixed 863 864* (whl_library) No longer restarts repository rule when fetching external 865 dependencies improving initial build times involving external dependency 866 fetching. 867 868* (gazelle) Improve runfiles lookup hermeticity. 869 870[0.26.0]: https://github.com/bazelbuild/rules_python/releases/tag/0.26.0 871 872## [0.25.0] - 2023-08-22 873 874### Changed 875 876* Python version patch level bumps: 877 * 3.9.16 -> 3.9.17 878 * 3.10.9 -> 3.10.12 879 * 3.11.1 -> 3.11.4 880* (bzlmod) `pip.parse` can no longer automatically use the default 881 Python version; this was an unreliable and unsafe behavior. The 882 `python_version` arg must always be explicitly specified. 883 884### Fixed 885 886* (docs) Update docs to use correct bzlmod APIs and clarify how and when to use 887 various APIs. 888* (multi-version) The `main` arg is now correctly computed and usually optional. 889* (bzlmod) `pip.parse` no longer requires a call for whatever the configured 890 default Python version is. 891 892### Added 893 894* Created a changelog. 895* (gazelle) Stop generating unnecessary imports. 896* (toolchains) s390x supported for Python 3.9.17, 3.10.12, and 3.11.4. 897 898[0.25.0]: https://github.com/bazelbuild/rules_python/releases/tag/0.25.0 899 900## [0.24.0] - 2023-07-11 901 902### Changed 903 904* **BREAKING** (gazelle) Gazelle 0.30.0 or higher is required 905* (bzlmod) `@python_aliases` renamed to `@python_versions 906* (bzlmod) `pip.parse` arg `name` renamed to `hub_name` 907* (bzlmod) `pip.parse` arg `incompatible_generate_aliases` removed and always 908 true. 909 910### Fixed 911 912* (bzlmod) Fixing Windows Python Interpreter symlink issues 913* (py_wheel) Allow twine tags and args 914* (toolchain, bzlmod) Restrict coverage tool visibility under bzlmod 915* (pip) Ignore temporary pyc.NNN files in wheels 916* (pip) Add format() calls to glob_exclude templates 917* plugin_output in py_proto_library rule 918 919### Added 920 921* Using Gazelle's lifecycle manager to manage external processes 922* (bzlmod) `pip.parse` can be called multiple times with different Python 923 versions 924* (bzlmod) Allow bzlmod `pip.parse` to reference the default python toolchain and interpreter 925* (bzlmod) Implementing wheel annotations via `whl_mods` 926* (gazelle) support multiple requirements files in manifest generation 927* (py_wheel) Support for specifying `Description-Content-Type` and `Summary` in METADATA 928* (py_wheel) Support for specifying `Project-URL` 929* (compile_pip_requirements) Added `generate_hashes` arg (default True) to 930 control generating hashes 931* (pip) Create all_data_requirements alias 932* Expose Python C headers through the toolchain. 933 934[0.24.0]: https://github.com/bazelbuild/rules_python/releases/tag/0.24.0 935