Skip to content

Cannot prefer system python over uv managed python #2145

@hehaoqian

Description

@hehaoqian

Summary

prek always pass --python-preference managed to uv,
so the python version priority used by the uv created virtualenv is:

  • already downloaded uv managed python
  • system python (python inside PATH)
  • uv download the required python

This surprises me that a uv python installation can change the python used by prek.


Bug: prek does not handle language_version: system of python, in .pre-commit-config.yaml,
--python is not passed to uv, and --python-preference managed is still passed to uv


Also, for my usage, I would like to always prefer system python,
so there is more predicted behavior of the python chosen,
that I can ensure a specific python by controlling the PATH env var.

I have tried to set the env var UV_PYTHON, so it seems prek has intentionally cleared it.

I have also tried to set the env var UV_PYTHON_PREFERENCE, but it has no effect if --python-preference managed is specified.

I am not sure that if prek needs to specify --python-preference managed , because managed is the default of uv.
And I do not see any reference of --python-reference in the --help of uv and the doc of uv. It seems to be a hidden option. If prek` does not specify the preference, then it is possible for me to specify the preference in by env var, or by uv configuration file.

If there is concern to always remove --python-preference managed, may be it's better to add prek specific env var to control the preference.

Willing to submit a PR?

  • Yes — I’m willing to open a PR to fix this.

Platform

Linux 4.18.0-553.el8_10.x86_64 x86_64 GNU/Linux (RHEL8)

Version

0.4.3

.pre-commit-config.yaml

Log file


Metadata

Metadata

Assignees

No one assigned

    Labels

    thinkingI'm thinking on this

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions