Skip to content

0.33.0

Compare
Choose a tag to compare
@github-actions github-actions released this 12 Jun 01:41
· 166 commits to main since this release
2a19374

Using Bzlmod with Bazel 6

NOTE: bzlmod support is still beta. APIs subject to change.

Add to your MODULE.bazel file:

bazel_dep(name = "rules_python", version = "0.33.0")

pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")

pip.parse(
    hub_name = "pip",
    python_version = "3.11",
    requirements_lock = "//:requirements_lock.txt",
)

use_repo(pip, "pip")

Using WORKSPACE

Paste this snippet into your WORKSPACE file:

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
    name = "rules_python",
    sha256 = "dc6e2756130fafb90273587003659cadd1a2dfef3f6464c227794cdc01ebf70e",
    strip_prefix = "rules_python-0.33.0",
    url = "https://github.com/bazelbuild/rules_python/releases/download/0.33.0/rules_python-0.33.0.tar.gz",
)

load("@rules_python//python:repositories.bzl", "py_repositories")

py_repositories()

Gazelle plugin

Paste this snippet into your WORKSPACE file:

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
    name = "rules_python_gazelle_plugin",
    sha256 = "dc6e2756130fafb90273587003659cadd1a2dfef3f6464c227794cdc01ebf70e",
    strip_prefix = "rules_python-0.33.0/gazelle",
    url = "https://github.com/bazelbuild/rules_python/releases/download/0.33.0/rules_python-0.33.0.tar.gz",
)

# To compile the rules_python gazelle extension from source,
# we must fetch some third-party go dependencies that it uses.

load("@rules_python_gazelle_plugin//:deps.bzl", _py_gazelle_deps = "gazelle_deps")

_py_gazelle_deps()

What's Changed

🎉 0.33.0 of rules_python and the gazelle plugin has just been tagged, notable changes/fixes/additions:

  • gazelle plugin is now using tree-sitter instead of Python to parse python files, which makes it 3 times faster on larger monorepos and it does not require a python interpreter anymore. There is a known issue of the plugin being tricky to cross-compile, so please leave comments there if you are seeing issues.
  • The dependence on the system having a Python interpreter can now be avoided if using a hermetic toolchain. This can be enabled with bootstrap_impl config setting.
  • The MODULE.bazel.lock file is now the same irrespective of the host platform that rules_python is being used on. This required to remove host-platform specific references in @pythons_hub//:interpreters.bzl, so if you want to use a host python in a repository rule context, use @python_{version}_host//:python.
  • The python files can now be compiled to .pyc during the bazel build phase, enable this with @rules_python//python/config_settings:precompile=enabled config setting, more info in the docs.
  • whl_filegroup can now be used to extract files from a whl target. This is useful in cases where one wants to use e.g. numpy headers or similar. The benefit of this is that users don’t need to modify the pip.parse whl distributions and can have better performance (no need to refetch the pip packages when the desired file list changes) and ergonomics through build-time rules.
  • experimental_index_url flag in pip.parse now enables using the whl filenames to derive the target platform config settings, so you can finally get the right wheel for the right target platform. It is best to use this feature together with requirements_by_platform (also added in 0.33.0) to specify requirements files per (os, arch) explicitly. We now also do not ignore yanked packages which mirrors the behaviour of uv more closely. The users have a few config settings that they can use to change the behaviour (preference of universal2 wheels on osx, preference of musllinux and the libc version on linux, disabling sdist). The config settings are documented here.

See the full changelog here.

PRs:

  • fix(gazelle): delete invalid py_library and use correct NonEmptyAttrs for py_* by @hunshcn in #1887
  • fix(gazelle): generate empty py_library only when need by @hunshcn in #1905
  • refactor: Mark internal and python extension as reproducible by @fmeum in #1892
  • feat: compile source files at build time by @rickeylev in #1902
  • docs: doc that precompiling is disabled by default by @rickeylev in #1908
  • fix(whl_library): fix the dependency generation for multi-python depenency closures by @aignas in #1875
  • fix: gazelle failing on Windows with "panic: runtime error: invalid memory address or nil pointer dereference" by @bartoszpop in #1872
  • feat(pip): support specifying requirements per (os, arch) by @aignas in #1885
  • feat(toolchains): Add riscv64 linux platform to available toolchain platforms by @JeffreyALaw in #1907
  • fix: remove bzlmod pip.parse() annotations attribute by @jbedard in #1808
  • feat(gazelle): pure golang helper by @hunshcn in #1895
  • doc: fix doc typo in py_wheel.bzl by @tnielens in #1899
  • feat: add whl_filegroup by @lalten in #1904
  • chore(precompiling): use PyCompile as mnemonic to match Google mnemonic by @rickeylev in #1911
  • docs: implement Starlark domain plugin for Sphinx by @rickeylev in #1909
  • docs: generate Starlark domain markup instead of regular markdown by @rickeylev in #1919
  • docs: rename sphinx plugin to sphinx_bzl by @rickeylev in #1922
  • docs: document the current_py_cc_headers and libraries targets by @rickeylev in #1927
  • build(deps): Update the pip_install dependencies by @JulesDT in #1914
  • doc: fix toolchains.md mistake by @xinnjie in #1928
  • refactor/fix: store dists in parse_requirements output by @aignas in #1917
  • fix: don't require system Python to perform bootstrapping by @rickeylev in #1929
  • feat(gazelle): Support "$python_root$" placeholder in the "gazelle:python_visibility" directive by @dougthor42 in #1936
  • feat: Upgrade to protobuf 27.0 and remove py_proto_library by @comius in #1933
  • fix(pip.parse): make the pip extension reproducible if PyPI is not called by @aignas in #1937
  • feat(bzlmod): support cross-platform whl setups within the main hub repo by @aignas in #1837
  • doc(pip_parse_vendored): fix the example by @aignas in #1942
  • fix: make the pythons_hub platform independent by @aignas in #1946
  • revert: upgrade to protobuf 27.0 and remove py_proto_library (#1933) by @aignas in #1948
  • chore: refer to rules_python toolchain type target instead of bazel_tools by @rickeylev in #1949
  • chore: changelog changes for release 0.33.0 by @aignas in #1950

New Contributors

Full Changelog: 0.32.2...0.33.0