For more detailed setup instructions, see https://rules-python.readthedocs.io/en/latest/getting-started.html
For the user-facing changelog see here
Using Bzlmod
Add to your MODULE.bazel
file:
bazel_dep(name = "rules_python", version = "1.3.0")
python = use_extension("@rules_python//python/extensions:python.bzl", "python")
python.toolchain(
python_version = "3.13",
)
pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
pip.parse(
hub_name = "pypi",
python_version = "3.13",
requirements_lock = "//:requirements_lock.txt",
)
use_repo(pip, "pypi")
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 = "2cc26bbd53854ceb76dd42a834b1002cd4ba7f8df35440cf03482e045affc244",
strip_prefix = "rules_python-1.3.0",
url = "https://github.com/bazel-contrib/rules_python/releases/download/1.3.0/rules_python-1.3.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 = "2cc26bbd53854ceb76dd42a834b1002cd4ba7f8df35440cf03482e045affc244",
strip_prefix = "rules_python-1.3.0/gazelle",
url = "https://github.com/bazel-contrib/rules_python/releases/download/1.3.0/rules_python-1.3.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
- docs: Add horizontal spacers around filenames in custom toolchain guide by @nicholasjng in #2563
- fix: Avoid creating URLs with empty path segments from index URLs in environment variables by @WillMorrison in #2557
- docs: update gazelle README.md by @alexeagle in #2567
- fix: Don't fail in override from a non-root module by @mailto-jonas in #2566
- chore: remove internal usage of deprecated py_binary ad py_test by @aignas in #2569
- fix: Fix encoding of runfiles manifest and repository mapping files. by @phst in #2568
- fix: make coverage work with bootstrap=script by @rickeylev in #2574
- doc: point users to our CHANGELOG at the top of the release note by @aignas in #2582
- fix: Enable location expansion for
sh_py_run_test
by @philsc in #2583 - fix(sphinxdocs): do not crash when tag_class does not have doc by @aignas in #2585
- refactor(uv): move around uv implementation files by @aignas in #2580
- revert: Updated pip and packaging versions to work with free-threading packages (#2514) by @aignas in #2584
- docs: using python_version attribute for specifying python version by @JeroenSchmidt in #2589
- fix: make plain zipapp work with bootstrap=script by @rickeylev in #2598
- fix: add flag to use runtime venv creation when using bootstrap=script by @rickeylev in #2590
- docs: Update URL in gazelle example by @hofbi in #2602
- refactor: expose base rule construction via builders to allow customization for testing by @rickeylev in #2600
- feat: Remove and redirect py_proto_library to protobuf by @comius in #2604
- chore: updates for 1.2.0 release by @rickeylev in #2611
- docs: update dev docs on how to pick next version by @rickeylev in #2612
- docs: tell how to create branches for releases by @rickeylev in #2613
- docs: split out release steps into separate doc by @rickeylev in #2615
- feat: provide access to arbitrary interpreters by @philsc in #2507
- docs: add changelog update for //python/bin by @rickeylev in #2616
- refactor: cleanup now-unreferenced proto toolchain type by @alexeagle in #2620
- docs: add some docs to help contributors get started by @rickeylev in #2623
- ci: use Python 3.9 for mypy workflow to fix ci by @rickeylev in #2625
- fix(pypi): correctly translate ppc64le to bazel platforms by @aignas in #2577
- fix: Gazelle bug with merging py_binary targets in per-file mode and partial update by @jimmyt857 in #2619
- refactor: stop using some deprecated Starlark APIs by @EdSchouten in #2626
- docs: fix changelog header for 1.2.0 entry by @rickeylev in #2635
- fix: Downgrade "running as root" error to a warning by default by @Wyverald in #2636
- fix: spill module mapping args to a file by @mattem in #2644
- Add error for pip.parse attrs that require other attrs by @keith in #2646
- feat: Package pyi files in wheel by @Synss in #2609
- chore: Remove *_build_test targets from sphinx_docs (#2645) by @255 in #2650
- fix(pypi): use python -B for repo-phase invocations by @aignas in #2641
- build: Update doublestar to a version that works with the latest Gazelle by @shs96c in #2480
- fix: Add libdir to library search path by @shs96c in #2476
- fix(gazelle): Include YAML 'docstart' in gazelle manifest file by @dougthor42 in #2656
- feat(uv): parse the dist-manifest.json to not hardcode sha256 in rules_python by @aignas in #2578
- fix(coverage): missing files in the coverage report if they have no tests by @BurnzZ in #2607
- feat(pypi): support direct urls for wheels in bazel downloader by @chrisirhc in #2655
- refactor: API for deriving customized versions of the base rules by @rickeylev in #2610
- fix(gazelle): Explicitly call sys.exit in the modules_mapping generator by @samschlegel in #2662
- feat(rules): allow deriving custom rules from core rules by @rickeylev in #2666
- feat(binary/test): add interpreter_args attribute by @rickeylev in #2669
- feat: env-var for additional interpreter args in bootstrap stage 1 by @andponlin-canva in #2654
- Update source repo in BCR metadata.json by @meteorcloudy in #2672
- build(deps): bump jinja2 from 3.1.4 to 3.1.6 in /examples/bzlmod by @dependabot in #2651
- chore(docs): fix forward-ref to 1.0 by @alexeagle in #2673
- chore: account for new GH org of standalone interpreter by @alexeagle in #2676
- feat(rules): add main_module attribute to run a module name (python -m) by @rickeylev in #2671
- fix: expose public attrb/ruleb bzl targets by @aignas in #2682
- chore: update changelog and version markers for 1.3 release by @rickeylev in #2683
- chore: ignore releasing.md for version string check by @rickeylev in #2684
- chore: replace bazelbuild with bazel-contrib by @rickeylev in #2688
- chore: update bcr metadata files to specify bazel-contrib by @rickeylev in #2686
New Contributors
- @mailto-jonas made their first contribution in #2566
- @JeroenSchmidt made their first contribution in #2589
- @hofbi made their first contribution in #2602
- @jimmyt857 made their first contribution in #2619
- @EdSchouten made their first contribution in #2626
- @Synss made their first contribution in #2609
- @255 made their first contribution in #2650
- @BurnzZ made their first contribution in #2607
- @samschlegel made their first contribution in #2662
- @andponlin-canva made their first contribution in #2654
Full Changelog: 1.1.0...1.3.0