Description
This issue is to track a starlark implementation for the pypa-spec for requirements line parsing and metadata Requires-Dist parsing.
Right now, we have a partial implementation in pep508_evaluate.bzl.
Some relevant docs:
- https://packaging.python.org/en/latest/specifications/dependency-specifiers
- https://packaging.python.org/en/latest/specifications/version-specifiers
- (historical) https://peps.python.org/pep-0508/
- @groodt mentioned pypa/packaging has a set of tests ; maybe we can consume those somehow
TODO
-
>=, <=, <, >
operators for string comparisons -
===
string operator (I think?) -
~=
string operator (I think?) - data-based version comparison
- Implement pypa normalization rules
-
python_version
- use theX.Y
python version -
python_full_version
- use theX.Y.Z
python version -
os_name
- use a value derived from@platforms//os:<name>
values -
sys_platform
- use a value derived from@platforms//os:<name>
values -
platform_release
- use""
for the value -
platform_system
- use a value derived from@platforms//os:<name>
values -
platform_version
- uses""
for the value, missed the fact that we should default to0
-
platform_machine
- use a value derived from@platforms//cpu:<name>
values -
platform_python_implementation
- UseCPython
constant. -
implementation_name
- Usecpython
constant. - Support
*
in version comparison (see https://peps.python.org/pep-0440/#compatible-release)
Some keys seem tedious to support
platform_release, platform_version
For pip, this is simply the host machine value. For bazel, it would mean whatever the target platform would return. Using the bazel host machine value wouldn't be correct for cross builds, but will probably have to suffice as the first impl and in the short term.
Long term, I think we'll need a --platform_{release,version}
flag (or toolchain?), which points to a target that can provide the appropriate value.
Notable bits from the spec:
Variables whose value cannot be calculated on a given Python implementation should evaluate to 0 for versions, and an empty string for all other variables.