astral-sh / uv

An extremely fast Python package and project manager, written in Rust.
https://docs.astral.sh/uv
Apache License 2.0
21.22k stars 622 forks source link

Markers under universal resolution could have more concise representation #5992

Open notatallshaw opened 1 month ago

notatallshaw commented 1 month ago

uv 0.2.35

Markers are looking much better in general, but here's an example that popped up for me that felt a little too verbose:

$ echo -e "sqlalchemy>=2" | uv pip compile --universal --annotation-style line - 2>/dev/null | grep "greenlet=="
greenlet==3.0.3 ; (python_version < '3.13' and platform_machine == 'AMD64') or (python_version < '3.13' and platform_machine == 'WIN32') or (python_version < '3.13' and platform_machine == 'aarch64') or (python_version < '3.13' and platform_machine == 'amd64') or (python_version < '3.13' and platform_machine == 'ppc64le') or (python_version < '3.13' and platform_machine == 'win32') or (python_version < '3.13' and platform_machine == 'x86_64')  # via sqlalchemy

This could have been more neatly represented as:

greenlet==3.0.3 ; python_version < '3.13'  and (platform_machine == 'AMD64' or platform_machine == 'WIN32' or platform_machine == 'aarch64' or platform_machine == 'amd64' or platform_machine == 'ppc64le' or platform_machine == 'win32' or platform_machine == 'x86_64')  # via sqlalchemy

This is fairly small and not that big of a deal.

ibraheemdev commented 1 month ago

Hmm yeah this is a consequence of us strictly writing in DNF form. Your example does seem like it would be much simpler in CNF.. it's possible that we want more aggressive simplification. However, having a stable representation of markers is also important (see https://github.com/astral-sh/uv/issues/5179), so if we do decide to simplify more we should use an established algorithm instead of continuously adding heuristics (as we were before https://github.com/astral-sh/uv/pull/5898).