For more detailed setup instructions, see https://rules-python.readthedocs.io/en/latest/getting-started.html
Using Bzlmod
Add to your MODULE.bazel
file:
bazel_dep(name = "rules_python", version = "1.1.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 = "9c6e26911a79fbf510a8f06d8eedb40f412023cf7fa6d1461def27116bff022c",
strip_prefix = "rules_python-1.1.0",
url = "https://github.com/bazelbuild/rules_python/releases/download/1.1.0/rules_python-1.1.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 = "9c6e26911a79fbf510a8f06d8eedb40f412023cf7fa6d1461def27116bff022c",
strip_prefix = "rules_python-1.1.0/gazelle",
url = "https://github.com/bazelbuild/rules_python/releases/download/1.1.0/rules_python-1.1.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
- tests: skip workspace-specific examples for bazel 9 by @rickeylev in #2471
- chore: ignore examples/pip_repository_annotations bazel-bin symlink by @rickeylev in #2472
- chore: use per-rule loads in pip_compile.bzl by @rickeylev in #2473
- tests: make multi_python_versions pass with Bazel 9 workspace by @rickeylev in #2474
- fix: normalize argv0 so runfiles root can be found on windows with bazel 9 by @rickeylev in #2481
- chore: load specific bzl files instead of generic defs.bzl by @rickeylev in #2483
- feat(pypi): support freethreaded in experimental_index_url by @aignas in #2460
- fix: Make sure wheelmaker uses the default shell env by @shs96c in #2477
- chore: remove find_requirements re-export from bazel_tools by @rickeylev in #2484
- feat(gazelle): Include types/stubs packages by @ewianda in #2425
- build(deps): bump django from 4.2.16 to 4.2.17 in /examples/bzlmod_build_file_generation by @dependabot in #2486
- build(deps): bump rich from 13.9.3 to 13.9.4 in /tools/publish by @dependabot in #2371
- fix: define rules_python_internal earlier so Bazel 9 doesn't try to use PyInfo et al builtins by @rickeylev in #2485
- chore: replace rules_proto with com_google_protobuf by @rickeylev in #2487
- doc: freethreaded support changelog by @aignas in #2497
- ci: fix CI after bazel 8 release by @aignas in #2492
- fix: Strip trailing slash for repo url by @amartani in #2495
- fix(pypi): pass requirements without env markers to the whl_library by @aignas in #2488
- fix: make bazel 9 workspace recognize rules_python as the main module by @rickeylev in #2501
- fix(gazelle): Support parsing files that use Python3.12 PEP 695 (Type Parameter Syntax) by using dougthor42's fork of go-tree-sitter by @dougthor42 in #2496
- fix(pypi): Fix use_hub_alias_dependencies with WORKSPACE by @gholms in #2504
- build(deps): bump astroid from 3.3.5 to 3.3.6 in /docs by @dependabot in #2490
- docs: Fix toolchain implementation file name by @nicholasjng in #2512
- doc: correct toolchain usage in repository_rule context docs by @aignas in #2510
- fix: py_proto_library: external runfiles by @tpudlik in #2516
- refactor(pypi): A better error message when the wheel select hits no_match by @aignas in #2519
- refactor: consolidate py_executable_bazel, common_bazel by @rickeylev in #2523
- feat(toolchain): Add support for Python 3.13.1. by @okin in #2482
- refactor: stop warning if we don't find anything via SimpleAPI by @aignas in #2532
- feat(pypi): only query SimpleAPI for pkgs that have shas by @aignas in #2527
- refactor(pypi): further cleanup of
pip.parse
code by @aignas in #2534 - feat: add pyi attributes/fields, original source fields by @rickeylev in #2538
- fix(gazelle): Don't ignore
setup.py
files when running Gazelle by @dougthor42 in #2536 - fix(pypi): change the parallelisation scheme for querying SimpleAPI by @aignas in #2531
- refactor: fold per-target python version into base rules by @rickeylev in #2541
- fix(whl_library): track sources in whl_library by @aignas in #2526
- Updated pip and packaging versions to work with free-threading packages by @vfdev-5 in #2514
- chore: add check for version_next markers by @rickeylev in #2542
- feat: Add feature to expose whether the native rules are used by @jsharpe in #2549
- chore: update changelog for 1.1.0 by @rickeylev in #2547
- chore: update version strings in docs. by @rickeylev in #2546
- feat: make pypi-generated targets include pyi files by @rickeylev in #2545
- fix: _which_unchecked: don't watch PATH if binary exists. by @Ubehebe in #2552
- chore: update release check to ignore VERSION_NEXT substring in CONTRIBUTING.md by @rickeylev in #2553
- fix(gazelle): Fix the requirements arg to the gazelle python manifest generator. by @sputt in #2533
- docs: note direct_pyi_files/transitive_pyi_files are usually build-time only by @rickeylev in #2555
- refactor(pypi): rename config settings and improve docs by @aignas in #2556
- fix(pypi): include pyi files in data attribute by @rickeylev in #2558
New Contributors
- @okin made their first contribution in #2482
- @Ubehebe made their first contribution in #2552
- @sputt made their first contribution in #2533
Full Changelog: 1.0.0...1.1.0