-
-
Notifications
You must be signed in to change notification settings - Fork 617
Description
🐞 bug report
Affected Rule
The issue is caused by the rule: pip_parse
(all versions)
Is this a regression?
It appears to be. Previously, rules_python did evaluate platform markers see nikhaldi@323e84e
In 0.16, python/pip_install/extract_wheels/parse_requirements_to_bzl.py
will gladly parse a requirements file which uses markers, but does nothing with them. Nor does the new Starlark parser introduced in ba69aec.
It appears this functionality was simply never implemented in the new parser, and was deleted in 37e7e68 when the legacy pip_import
implementation was removed.
Description
rules_python
makes no attempt to evaluate requirement marker expressions, which leads to false build failures due to attempting to install packages marked as not viable because pip wheel
succeeds with a no-op and an error message when presented with a requirement which will be ignored due to markers.
🔬 Minimal Reproduction
When handed a requirements.txt
file which uses platform markers to select a different version of an artifact depending on markers everything appears okay. Consider
matplotlib==3.4.3 ; sys_platform != "darwin" or platform_machine != "arm64"
matplotlib==3.4.3.post1+abnormal ; sys_platform == "darwin" and platform_machine == "arm64"
The correct behavior for this requirements file should be to choose between these two versions. Note that the boolean selector condition is disjoint. However the actual behavior is to unconditionally attempt to install the first requirement clause listed in the file. This breaks both bazel fetch //...
and any rules referencing the requirement("matplotlib")
.
The behavior should be to evaluate all the marker expressions and select matching versions/args.
It may be valid for no versions of a package to be selected. Consider tensorflow-macos==2.7.0 ; sys_platform == "darwin"
. Arguably this should be achieved with platform-specific lockfiles and requirements_darwin
, but it shouldn't be an error.
If multiple requirements are selected, that should likely be an error.
🔥 Exception or Error
ERROR: $REPO/BUILD:1:11: $TARGET depends on @pypi_py38_darwin_arm64_matplotlib//:pkg in repository @pypi_py38_darwin_arm64_matplotlib which failed to fetch. no such package '@pypi_py38_darwin_arm64_matplotlib//': whl_library pypi_py38_darwin_arm64_matplotlib failed:
Ignoring matplotlib: markers 'sys_platform != "darwin" or platform_machine != "arm64"' don't match your environment
(Traceback (most recent call last):
File "/Users/arrdem/.pyenv/versions/3.8.16/lib/python3.8/runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/Users/arrdem/.pyenv/versions/3.8.16/lib/python3.8/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/private/var/tmp/_bazel_arrdem/64fd9f51655edad1a031ed416b537465/external/rules_python/python/pip_install/extract_wheels/extract_single_wheel.py", line 105, in <module>
main()
File "/private/var/tmp/_bazel_arrdem/64fd9f51655edad1a031ed416b537465/external/rules_python/python/pip_install/extract_wheels/extract_single_wheel.py", line 92, in main
whl = next(iter(glob.glob("*.whl")))
StopIteration
)