Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ gh repo fork bazel-contrib/rules_python --clone --remote
Next, make sure you have a new enough version of Python installed that supports the
various code formatters and other devtools. For a quick start,
[install pyenv](https://github.com/pyenv/pyenv-installer) and
at least Python 3.9.15:
at least Python 3.11.11:

```shell
curl https://pyenv.run | bash
pyenv install 3.9.15
pyenv shell 3.9.15
pyenv install 3.11.11
pyenv shell 3.11.11
```

## Development workflow
Expand Down
1 change: 0 additions & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ dev_pip = use_extension(
uv_lock = "//dev:uv.lock",
)
for python_version in [
"3.9",
"3.10",
"3.11",
"3.12",
Expand Down
1 change: 1 addition & 0 deletions dev/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[project]
name = "rules_python_dev"
version = "0.0.0"
requires-python = ">=3.10"

dependencies = [
# NOTE: This is only used as input to create the resolved requirements.txt
Expand Down
13 changes: 8 additions & 5 deletions docs/_includes/py_console_script_binary.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,15 @@ py_console_script_binary(
:::{rubric} Using a specific Python version
:::

A specific Python version can be forced by passing the desired Python version, e.g. to force Python 3.9:
A specific Python version can be forced by passing the desired Python version,
e.g. to force Python 3.14:
```starlark
load("@rules_python//python/entry_points:py_console_script_binary.bzl", "py_console_script_binary")

py_console_script_binary(
name = "yamllint",
pkg = "@pip//yamllint",
python_version = "3.9",
python_version = "3.14",
)
```

Expand Down Expand Up @@ -75,16 +76,18 @@ Python interpreter is available in the environment.
:::{rubric} Using a specific Python Version directly from a Toolchain
:::
:::{deprecated} 1.1.0
The toolchain-specific `py_binary` and `py_test` symbols are aliases to the regular rules.
For example, `load("@python_versions//3.11:defs.bzl", "py_binary")` and `load("@python_versions//3.11:defs.bzl", "py_test")` are deprecated.
The toolchain-specific `py_binary` and `py_test` symbols are aliases to the
regular rules. For example, `load("@python_versions//3.14:defs.bzl",
"py_binary")` and `load("@python_versions//3.14:defs.bzl", "py_test")` are
deprecated.

You should instead specify the desired Python version with `python_version`; see the example above.
:::
Alternatively, the {obj}`py_console_script_binary.binary_rule` arg can be passed
the version-bound `py_binary` symbol, or any other `py_binary`-compatible rule
of your choosing:
```starlark
load("@python_versions//3.9:defs.bzl", "py_binary")
load("@python_versions//3.14:defs.bzl", "py_binary")
load("@rules_python//python/entry_points:py_console_script_binary.bzl", "py_console_script_binary")

py_console_script_binary(
Expand Down
2 changes: 1 addition & 1 deletion docs/coverage.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ For Bzlmod:

```starlark
python.toolchain(
"@python3_9_toolchains//:all",
"@python3_14_toolchains//:all",
configure_coverage_tool = True,
)
```
Expand Down
2 changes: 1 addition & 1 deletion docs/howto/get-python-version.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ my_rule(
```

When you build this target, it will generate a file named
`show_python_version.txt` containing the Python version (e.g., `3.9`).
`show_python_version.txt` containing the Python version (e.g., `3.14`).

```starlark
bazel build :show_python_version
Expand Down
20 changes: 10 additions & 10 deletions docs/pypi/download.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
# Define concrete hub 'pypi_a'
pip.parse(
hub_name = "pypi_a",
python_version = "3.11",
python_version = "3.14",
requirements_lock = "//:requirements_a.txt",
)

# Define concrete hub 'pypi_b'
pip.parse(
hub_name = "pypi_b",
python_version = "3.11",
python_version = "3.14",
requirements_lock = "//:requirements_b.txt",
)

Expand Down Expand Up @@ -241,9 +241,9 @@ Let's say you have two requirements files:
```
# requirements.linux_x86_64.txt
--platform=manylinux_2_17_x86_64
--python-version=39
--python-version=314
--implementation=cp
--abi=cp39
--abi=cp314

foo==0.0.1 --hash=sha256:deadbeef
bar==0.0.1 --hash=sha256:deadb00f
Expand All @@ -252,9 +252,9 @@ bar==0.0.1 --hash=sha256:deadb00f
```
# requirements.osx_aarch64.txt contents
--platform=macosx_10_9_arm64
--python-version=39
--python-version=314
--implementation=cp
--abi=cp39
--abi=cp314

foo==0.0.3 --hash=sha256:deadbaaf
```
Expand All @@ -263,7 +263,7 @@ With these 2 files your {bzl:obj}`pip.parse` could look like:
```starlark
pip.parse(
hub_name = "pip",
python_version = "3.9",
python_version = "3.14",
# Tell `pip` to ignore sdists
download_only = True,
requirements_by_platform = {
Expand All @@ -274,9 +274,9 @@ pip.parse(
```

With this, `pip.parse` will create a hub repository that is going to
support only two platforms - `cp39_osx_aarch64` and `cp39_linux_x86_64` - and it
will only use `wheels` and ignore any sdists that it may find on the PyPI-
compatible indexes.
support only two platforms - `cp314_osx_aarch64` and
`cp314_linux_x86_64` - and it will only use `wheels` and ignore any sdists
that it may find on the PyPI-compatible indexes.

:::{warning}
Because bazel is not aware what exactly is downloaded, the same wheel may be downloaded
Expand Down
62 changes: 50 additions & 12 deletions examples/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,76 @@ load("@rules_python//python/uv/private:lock.bzl", "lock") # buildifier: disable
licenses(["notice"]) # Apache 2.0

lock(
name = "bzlmod_requirements_3_9",
name = "bzlmod_requirements_3_12",
srcs = ["bzlmod/requirements.in"],
out = "bzlmod/requirements_lock_3_9.txt",
out = "bzlmod/requirements_lock_3_12.txt",
args = [
"--emit-index-url",
"--universal",
"--python-version=3.9",
"--python-version=3.12",
],
python_version = "3.9",
python_version = "3.12",
)

lock(
name = "bzlmod_requirements_3_11",
name = "bzlmod_requirements_3_12_windows",
srcs = ["bzlmod/requirements.in"],
out = "bzlmod/requirements_lock_3_11.txt",
out = "bzlmod/requirements_windows_3_12.txt",
args = [
"--emit-index-url",
"--python-platform",
"windows",
"--python-version=3.12",
],
python_version = "3.12",
)

lock(
name = "bzlmod_requirements_3_13",
srcs = ["bzlmod/requirements.in"],
out = "bzlmod/requirements_lock_3_13.txt",
args = [
"--emit-index-url",
"--universal",
"--python-version=3.13",
],
python_version = "3.13",
)

lock(
name = "bzlmod_requirements_3_13_windows",
srcs = ["bzlmod/requirements.in"],
out = "bzlmod/requirements_windows_3_13.txt",
args = [
"--emit-index-url",
"--python-platform",
"windows",
"--python-version=3.13",
],
python_version = "3.13",
)

lock(
name = "bzlmod_requirements_3_14",
srcs = ["bzlmod/requirements.in"],
out = "bzlmod/requirements_lock_3_14.txt",
args = [
"--emit-index-url",
"--universal",
"--python-version=3.11",
"--python-version=3.14",
],
python_version = "3.11",
python_version = "3.14",
)

lock(
name = "bzlmod_requirements_3_11_windows",
name = "bzlmod_requirements_3_14_windows",
srcs = ["bzlmod/requirements.in"],
out = "bzlmod/requirements_windows_3_11.txt",
out = "bzlmod/requirements_windows_3_14.txt",
args = [
"--emit-index-url",
"--python-platform",
"windows",
"--python-version=3.11",
"--python-version=3.14",
],
python_version = "3.11",
python_version = "3.14",
)
1 change: 1 addition & 0 deletions examples/build_file_generation/.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ build --enable_runfiles
common --noenable_bzlmod
common --enable_workspace
common --incompatible_python_disallow_native_rules
common --incompatible_default_to_explicit_init_py
6 changes: 3 additions & 3 deletions examples/build_file_generation/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ py_repositories()
# This toolchain will allow bazel to download a specific python version, and use that version
# for compilation.
python_register_toolchains(
name = "python39",
python_version = "3.9",
name = "python3_14",
python_version = "3.14",
)

load("@rules_python//python:pip.bzl", "pip_parse")
Expand Down Expand Up @@ -65,7 +65,7 @@ pip_parse(
# 3. Wrapper script, like in the autodetecting python toolchain.
#
# Here, we use the interpreter constant that resolves to the host interpreter from the default Python toolchain.
python_interpreter_target = "@python39_host//:python",
python_interpreter_target = "@python3_14_host//:python",
# Set the location of the lock file.
requirements_lock = "//:requirements_lock.txt",
requirements_windows = "//:requirements_windows.txt",
Expand Down
18 changes: 9 additions & 9 deletions examples/build_file_generation/gazelle_python.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,22 @@
manifest:
modules_mapping:
alabaster: alabaster
babel: Babel
babel: babel
blinker: blinker
certifi: certifi
charset_normalizer: charset_normalizer
click: click
docutils: docutils
flask: Flask
flask: flask
idna: idna
imagesize: imagesize
importlib_metadata: importlib_metadata
itsdangerous: itsdangerous
jinja2: Jinja2
markupsafe: MarkupSafe
jinja2: jinja2
markupsafe: markupsafe
packaging: packaging
pygments: Pygments
pygments: pygments
requests: requests
roman_numerals: roman_numerals
snowballstemmer: snowballstemmer
sphinx: sphinx
sphinxcontrib.applehelp: sphinxcontrib_applehelp
Expand All @@ -31,8 +32,7 @@ manifest:
sphinxcontrib.qthelp: sphinxcontrib_qthelp
sphinxcontrib.serializinghtml: sphinxcontrib_serializinghtml
urllib3: urllib3
werkzeug: Werkzeug
zipp: zipp
werkzeug: werkzeug
pip_repository:
name: pip
integrity: 19c0e03a9cf1d6bbb2dfe301325fefc59a30c3f967f84c2f1baaf915c2805da7
integrity: d775f39a5dd4a17ddda29d6f216e29a14fbfdfaa3ec1d7a213fda9e4bcafb350
Loading