Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e5d9f10

Browse filesBrowse files
authored
feat(bzlmod): Allow bzlmod pip.parse to reference the default python toolchain and interpreter (bazel-contrib#1303)
This commit defaults `the pip.parse` `python_version` attribute to the default version of Python, as configured by the `python.toolchain` extension. This allows a user to use the Python version set by rules_python or the root module. Also, this makes setting the attribute optional (as it has a default) and we automatically select the interpreter. Closes bazel-contrib#1267
1 parent 523b9de commit e5d9f10
Copy full SHA for e5d9f10

File tree

2 files changed

+10
-3
lines changed
Filter options

2 files changed

+10
-3
lines changed

‎examples/bzlmod/MODULE.bazel

Copy file name to clipboardExpand all lines: examples/bzlmod/MODULE.bazel
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ local_path_override(
1111
path = "../..",
1212
)
1313

14+
# Setting python.toolchain is optional as rules_python
15+
# sets a toolchain for you, using the latest supported version
16+
# of Python. We do recomend that you set a version here.
17+
1418
# We next initialize the python toolchain using the extension.
1519
# You can set different Python versions in this block.
1620
python = use_extension("@rules_python//python/extensions:python.bzl", "python")
@@ -87,9 +91,10 @@ use_repo(pip, "whl_mods_hub")
8791
# call.
8892
# Alternatively, `python_interpreter_target` can be used to directly specify
8993
# the Python interpreter to run to resolve dependencies.
94+
# Because we do not have a python_version defined here
95+
# pip.parse uses the python toolchain that is set as default.
9096
pip.parse(
9197
hub_name = "pip",
92-
python_version = "3.9",
9398
requirements_lock = "//:requirements_lock_3_9.txt",
9499
requirements_windows = "//:requirements_windows_3_9.txt",
95100
# These modifications were created above and we

‎python/extensions/pip.bzl

Copy file name to clipboardExpand all lines: python/extensions/pip.bzl
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,14 +347,16 @@ Targets from different hubs should not be used together.
347347
""",
348348
),
349349
"python_version": attr.string(
350-
mandatory = True,
350+
default = DEFAULT_PYTHON_VERSION,
351351
doc = """
352352
The Python version to use for resolving the pip dependencies. If not specified,
353353
then the default Python version (as set by the root module or rules_python)
354354
will be used.
355355
356356
The version specified here must have a corresponding `python.toolchain()`
357-
configured.
357+
configured. This attribute defaults to the version of the toolchain
358+
that is set as the default Python version. Or if only one toolchain
359+
is used, this attribute defaults to that version of Python.
358360
""",
359361
),
360362
"whl_modifications": attr.label_keyed_string_dict(

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.