8000 revert(bzlmod)!: allow bzlmod pip.parse to implicitly use default pyt… · matts1/rules_python@0642390 · GitHub 10000
[go: up one dir, main page]

Skip to content

Commit 0642390

Browse files
authored
revert(bzlmod)!: allow bzlmod pip.parse to implicitly use default python version (bazel-contrib#1341)
Reverts bazel-contrib#1303 The main issue is that `pip.parse()` accepts a locked requirements file -- this means the requirements are specific to a particular Python version[1]. Because the default Python version can arbitrarily change, the lock file may not be valid for the Python version that is used at runtime. The net result is a module will use dependencies for e.g. Python 3.8, but will use 3.9 at runtime. Additionally, the dependencies resolved for 3.8 will be created under names such as `@foo_39` (because that's the python_version pip.parse sees), which is just more confusing. BREAKING CHANGE: * pip.parse() must have `python_version` explicitly set. Set it to the Python version used to resolve the requirements file. [1] Lock files aren't necessarily version specific, but we don't currently support the environment markers in lock files to make them cross-python-version compatible.
1 parent 23354a9 commit 0642390

File tree

2 files changed

+3
-10
lines changed

2 files changed

+3
-10
lines changed

examples/bzlmod/MODULE.bazel

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ 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-
1814
# We next initialize the python toolchain using the extension.
1915
# You can set different Python versions in this block.
2016
python = use_extension("@rules_python//python/extensions:python.bzl", "python")
@@ -91,10 +87,9 @@ use_repo(pip, "whl_mods_hub")
9187
# call.
9288
# Alternatively, `python_interpreter_target` can be used to directly specify
9389
# 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.
9690
pip.parse(
9791
hub_name = "pip",
92+
python_version = "3.9",
9893
requirements_lock = "//:requirements_lock_3_9.txt",
9994
requirements_windows = "//:requirements_windows_3_9.txt",
10095
# These modifications were created above and we

python/extensions/pip.bzl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -348,16 +348,14 @@ Targets from different hubs should not be used together.
348348
""",
349349
),
350350
"python_version": attr.string(
351-
default = DEFAULT_PYTHON_VERSION,
351+
mandatory = True,
352352
doc = """
353353
The Python version to use for resolving the pip dependencies. If not specified,
354354
then the default Python version (as set by the root module or rules_python)
355355
will be used.
356356
357357
The version specified here must have a corresponding `python.toolchain()`
358-
configured. This attribute defaults to the version of the toolchain
359-
that is set as the default Python version. Or if only one toolchain
360-
is used, this attribute defaults to that version of Python.
358+
configured.
361359
""",
362360
),
363361
"whl_modifications": attr.label_keyed_string_dict(

0 commit comments

Comments
 (0)
0