uv icon indicating copy to clipboard operation
uv copied to clipboard

bug: uv pip compile does not respect `python-downloads` and `python-preference`

Open maartenbreddels opened this issue 4 months ago • 0 comments

Reproducing the issue

I have my system python version 3.9.16 (on osx)

$ which python
/Users/maartenbreddels/miniconda3/envs/dev/bin/python
$ python --version
Python 3.9.16

uv is up to date (0.4.20).

I have the following uv.toml

environments = [
    "platform_system == 'Emscripten'"
]

python-downloads = "auto"
python-preference = "only-managed"

My current requirement file is:

https://py.cafe/gh/artifact/holoviz/panel/2021154790/panel-1.5.2-py3-none-any.whl

(PS: this url will fetch/extract a wheel on the fly from an upload artifact, i have excluded that endpoint being an issue by manually downloading the wheel from https://github.com/holoviz/panel/actions/runs/11204446095 an replacing the url with a local filename - i.e. /Users/maartenbreddels/Downloads/pip/panel-1.5.2-py3-none-any.whl in my case)

Running uv gives:

$ UV_PYTHON_PREFERENCE=only-managed UV_PYTHON_DOWNLOADS=auto uv pip compile requirements.txt --python-version 3.12.1 --universal
warning: The requested Python version 3.12.1 is not available; 3.9.16 will be used to build dependencies instead.
  × No solution found when resolving dependencies:
  ╰─▶ Because the current Python version (3.9.16) does not satisfy Python>=3.10 and panel==1.5.2 depends on Python>=3.10, we can conclude that
      panel==1.5.2 cannot be used.
      And because only panel==1.5.2 is available and you require panel, we can conclude that your requirements are unsatisfiable.

(Note that I also set UV_PYTHON_PREFERENCE=only-managed UV_PYTHON_DOWNLOADS=auto just to be sure uv catches this setting, it shouldn't be needed).

What I expect

I expect uv pip compile to

  1. NOT use the system Python (3.9.16)
  2. Install and use a 3.12.1 Python version

Current workaround

First install the correct python version manually using `uv python install'

$ uv python install 3.12.1
Searching for Python versions matching: Python 3.12.1
Installed Python 3.12.1 in 1.49s
 + cpython-3.12.1-macos-aarch64-none
$ uv pip compile requirements.txt --python-version 3.12.1 --universal
Resolved 34 packages in 19ms
# This file was autogenerated by uv via the following command:
#    uv pip compile requirements.txt --python-version 3.12.1 --universal
bleach==6.1.0
    # via panel
...

Sidenote - extra inconsistency

The behaviour is different when we do not install from a wheel link, but install from pypi. I.e. change the requirement.txt file to.

panel==1.5.2
$ uv python uninstall --all
Searching for Python installations
Uninstalled Python 3.12.1 in 168ms
 - cpython-3.12.1-macos-aarch64-none
$ uv pip compile requirements.txt --python-version 3.12.1 --universal                                        ✘ 1 
warning: The requested Python version 3.12.1 is not available; 3.9.16 will be used to build dependencies instead.
Resolved 34 packages in 23ms
# This file was autogenerated by uv via the following command:
#    uv pip compile requirements.txt --python-version 3.12.1 --universal
bleach==6.1.0
    # via panel
bokeh==3.6.0
    # via panel
...

So although here it does still complain about the Python version being used, it will resolve. Note that if we inspect https://pypi.org/pypi/panel/1.5.2/json we do find "requires_python": ">=3.10",. To summarize:

  1. uv pip compile with a wheel url will use the Python version of the system Python and fail to resolve if that Python versions does not match the constraints of the packages installed.
  2. uv pip compile with a pypi package will respect --python-version, despite using a system Python which does not match the constraints of the package installed.

This makes uv pip compile a bit inconsistent. Note that this 'sidenote' might be a unrelated/new issue, although for me as a user they feel related. Let me know if I should open a new issue for this not to derail this issue.

maartenbreddels avatar Oct 09 '24 08:10 maartenbreddels