tox-dev / tox-uv

Use https://github.com/astral-sh/uv with tox
MIT License
66 stars 14 forks source link

Python preference #70

Closed RomainBrault closed 1 month ago

RomainBrault commented 1 month ago

This PR enables the usage of the flag --python-preference to better control which Python interpreter is used.

See https://docs.astral.sh/uv/python-versions/#adjusting-python-version-preferences

It does so by exposing a uv_python_preference configuration field.

Note: this can be used to download missing Python interpreter. Use for example

[testenv]
uv_python_preference = only-managed
RomainBrault commented 1 month ago

tox-uv does not interact with uv python, only with uv venv. Doesn't the later only uses system pythons?

using python_preference = managed allows uv venv to use uv python toolchain if my understanding is correct.

I proposed this PR as it allows me to stop worrying about my python versions installed on my system and let tox-uv manage this through uv python.

By default no flag is passed to uv venv preserving the old behaviour. If python_preference is set, the flag --python-preference is passed, controlling wjether to use system python or some uv managed python.

gaborbernat commented 1 month ago

using python_preference = managed allows uv venv to use uv python toolchain if my understanding is correct.

Can you link to upstream docs of this?

RomainBrault commented 1 month ago

using python_preference = managed allows uv venv to use uv python toolchain if my understanding is correct.

Can you link to upstream docs of this?

https://docs.astral.sh/uv/python-versions/#adjusting-python-version-preferences

Should be in the README.md too.

gaborbernat commented 1 month ago

The CI is broken.

RomainBrault commented 1 month ago

Blocking now with the typing error. Optional or Union[Type, None] are not working. Investigating.

RomainBrault commented 1 month ago

At this point the CI pass locally

gaborbernat commented 1 month ago

Seem it is not. Note you can setup https://github.com/RomainBrault/tox-uv/actions to not need to wait for my approval.

RomainBrault commented 1 month ago

Here we go. I had to remove some type information to make it compatible with Python <3.10.

Thank you for your patience.

bluss commented 1 month ago

I guess this is why I reported https://github.com/tox-dev/tox-uv/issues/72

I thought tox-uv didn't "do this" because it was not advertised, and some open issues suggested otherwise. This is a feature that has just turned up, because uv venv already does it depending on configuration (that I already had).

Oh and it's a preview feature in uv so in that sense I guess it makes sense to not make any guarantees about it.