uv icon indicating copy to clipboard operation
uv copied to clipboard

Use `uv init` to lock to a particular Python version

Open SamEdwardes opened this issue 1 year ago • 1 comments

First of all, awesome work uv team! I am really enjoying using uv :)

Background

I have one idea for the uv init command. Take this example:

uv init --app --python 3.12.5

It will generate the following:

[project]
name = "example-project"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.12.5"
dependencies = []

I would like to have a way to specify a specific Python version. E.g. requires-python = "==3.12.5".

[project]
name = "example-project"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = "==3.12.5"
dependencies = []

Why

Why do I think this would be helpful?

  • in --app mode I am not targeting to support a matrix of Python versions and package versions. I want to deploy my app in the most stable way possible. I should always get the same Python packages (uv.lock handles this) and the same Python version.

Possible solutions

  • Support adding version specifiers to uv init. E.g. uv init --app --python ==3.12.5
  • When using --app mode default to locking in a single version of Python (my guess is that this is what most people want, but I could be wrong!).

SamEdwardes avatar Aug 28 '24 22:08 SamEdwardes

Hi! Thanks for the clear description of what you're looking for.

It is specifically not recommended to pin a single Python version in the requires-python field — it's against the intent of the metadata. Instead, you should use uv python pin which creates a .python-version file. We could / should create one of those in uv init. There's a separate issue for storing Python version pins in the pyproject.toml #4970

zanieb avatar Aug 28 '24 23:08 zanieb

Thank you @zanieb! I think python pin fits my needs. I also like the idea of storing this in pyproject.toml so there is one less file floating around :)

SamEdwardes avatar Aug 29 '24 14:08 SamEdwardes

I also like the idea of creating the .python-version file when uv init is in "app" mode.

SamEdwardes avatar Aug 29 '24 14:08 SamEdwardes