uv icon indicating copy to clipboard operation
uv copied to clipboard

feat: add linehaul info to uv-client

Open samypr100 opened this issue 1 year ago • 0 comments

Summary

Closes #1958

This adds linehaul metadata to uv's user-agent when pep508 markers are provided to the RegistryClientBuilder. Thanks to #2381, we were able to leverage most information from markers and avoid inconsistency.

Linehaul is meant to be accompanying metadata pip sends in it's user agent when talking to registries. You can see this output by running something like python -c 'from pip._internal.network.session import user_agent; print(user_agent())'.

Below are some examples from PIP:

  • Linux GHA: pip/24.0 {"ci":true,"cpu":"x86_64","distro":{"id":"jammy","libc":{"lib":"glibc","version":"2.35"},"name":"Ubuntu","version":"22.04"},"implementation":{"name":"CPython","version":"3.12.2"},"installer":{"name":"pip","version":"24.0"},"openssl_version":"OpenSSL 3.0.2 15 Mar 2022","python":"3.12.2","rustc_version":"1.76.0","system":{"name":"Linux","release":"6.5.0-1016-azure"}}
  • Windows GHA: pip/24.0 {"ci":true,"cpu":"AMD64","implementation":{"name":"CPython","version":"3.12.2"},"installer":{"name":"pip","version":"24.0"},"openssl_version":"OpenSSL 3.0.13 30 Jan 2024","python":"3.12.2","rustc_version":"1.76.0","system":{"name":"Windows","release":"2022Server"}}
  • OSX GHA: pip/24.0 {"ci":true,"cpu":"arm64","distro":{"name":"macOS","version":"14.2.1"},"implementation":{"name":"CPython","version":"3.12.2"},"installer":{"name":"pip","version":"24.0"},"openssl_version":"OpenSSL 3.0.13 30 Jan 2024","python":"3.12.2","rustc_version":"1.76.0","system":{"name":"Darwin","release":"23.2.0"}}

In PyPI, this metadata processed by https://github.com/pypi/linehaul-cloud-function

Here's how our results look like (sorry for the keys not having the same order):

  • Linux GHA: uv/0.1.21 {"installer":{"name":"uv","version":"0.1.21"},"python":"3.12.2","implementation":{"name":"CPython","version":"3.12.2"},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","libc":null},"system":{"name":"Linux","release":"6.5.0-1016-azure"},"cpu":"x86_64","openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
  • Windows GHA: uv/0.1.21 {"installer":{"name":"uv","version":"0.1.21"},"python":"3.12.2","implementation":{"name":"CPython","version":"3.12.2"},"distro":null,"system":{"name":"Windows","release":"2022Server"},"cpu":"AMD64","openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
  • OSX GHA: uv/0.1.21 {"installer":{"name":"uv","version":"0.1.21"},"python":"3.12.2","implementation":{"name":"CPython","version":"3.12.2"},"distro":{"name":"macOS","version":"14.2.1","id":null,"libc":null},"system":{"name":"Darwin","release":"23.2.0"},"cpu":"arm64","openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Distro information (such as the one pip uses from pip._vendor import distro to retrieve instead of platform module) was not retrievable from markers. Instead, the linux release codename/name/version uses sys-info crate, adding about 50us of extra overhead, and the osx version re-used the mac_version implementation from #2381 which adds about 20us of overhead on osx. I tried to use other crates to avoid re-implementing mac_version but most of them didn't yield satisfactory performance (40ms-60ms~) or had the wrong values needed (e.g. darwin version vs osx version).

I also didn't add libc retrieval or rustc retrieval as those seem to add substantial overhead due to querying ldd or rustc. PyPy version detection was also not added to avoid adding extra overhead to support PyPy for linehaul. All other behavior was kept 1-1 to match what pip's linehaul implementation does (as of 24.0). This also aligns with what was discussed in #1958.

Test Plan

Added new integration test to uv-client.

samypr100 avatar Mar 17 '24 03:03 samypr100