uv icon indicating copy to clipboard operation
uv copied to clipboard

Request: A `uv init` command to generate a pyproject.toml

Open imbev opened this issue 1 year ago • 8 comments

A downside of the "pip-tools style" interface is that there is no way to automatically generate a compatible pyproject.toml with the necessary fields. For those using the modern pyproject.toml format, it can be difficult or tedious to create an appropriate pyproject.toml file manually.

I suggest that uv adopt behavior similar to Poetry's poetry init, so that uv would prompt or allow the user to specify the name, description, author, python version, and build backend (or no build backend) for the project.

imbev avatar Feb 15 '24 21:02 imbev

Hi! Thanks for the feedback. A poetry init experience is on our roadmap.

zanieb avatar Feb 15 '24 21:02 zanieb

The overall poetry experience is quite good and ergonomic (though perhaps not always ideal). By that I mean having the other poetry commands as well, not just poetry init, would be great:

  • poetry new
  • poetry add*
  • poetry shell
  • poetry run
  • poetry build
  • poetry publish
  • etc

There are of course other nice features of poetry, as well as downsides (picking Python versions seems to still be awkward) which I know uv is planning on addressing, but having uv versions of the above would be a big incentive to switch.

But perhaps the biggest incentive to switch would be poetry-like management of a pyproject.toml file and lock file.

Kudos on this effort, will be following closely and looking forward to what it can mean for (the unmitigated train wreck that is) Python dependency/environment management.

'* I know uv add might be controversial since it already offers uv pip install which is a minimal change from just pip install but having uv add instead of uv pip install as a higher level API would be nice as it would save us a few keystrokes (and we're a lazy bunch) but again, it keeps close to the poetry API that a lot of us appreciate.

DimitarVanguelov avatar Feb 18 '24 16:02 DimitarVanguelov

The full project management workflow provided is on our roadmap. We've put the pip compatibility commands in a separate namespace explicitly so we have room for things like uv install.

zanieb avatar Feb 18 '24 17:02 zanieb

Can you write an example of pyproject.toml for uv? Thank you

alelavelli avatar Feb 28 '24 15:02 alelavelli

Can you write an example of pyproject.toml for uv? Thank you

# pyproject.toml

[project]
name = "my-project"
version = "0.1.0"
description = "my description"
authors = [ {name = "My Name", email = "[email protected]"}, ]
requires-python = ">= 3.11"

[build-system]
requires = ["setuptools >= 61.0"]
build-backend = "setuptools.build_meta"

See https://packaging.python.org/en/latest/guides/writing-pyproject-toml/

imbev avatar Mar 02 '24 02:03 imbev

Following what are now accepted PEPs, would be great to ensure any project management features adheres to PEP-621 (which now refer to this KB doc) and PEP-518.

This means a project-central pattern for dependencies and other metadata (something poetry has yet to implement)

wsidl avatar Apr 04 '24 16:04 wsidl

Note we don't make use of any particular pyproject.toml extensions for uv at this time — we just follow the standards. In the future, we'll have a section for configuring uv and an init command will make more sense.

zanieb avatar Apr 04 '24 17:04 zanieb

[project] dependencies = [ "httpx", "gidgethub[httpx]>4.0.0", "django>2.1; os_name != 'nt'", "django>2.0; os_name == 'nt'", ]

[project.optional-dependencies] gui = ["PyQt5"] cli = [ "rich", "click", ]

[project] requires-python = ">= 3.8"

https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#dependencies-and-requirements

I think the dependencies and project.optional-dependencies syntax would ideal for a future "uv add", but requires-python is currently relevant for uv init. This syntax is already supported by uv for uv pip compile.

imbev avatar Apr 04 '24 23:04 imbev

@zanieb thanks alot for putting and working on this on your roadmap. My thought or noob advice on going in the direction of poetry is that I often find myself confused if I am within poetry's shell or not whenever i run the command poetry run, its just not obvious with poetry. And frankly I question if the shell is even needed. PDM on the other hand does not have this problem ( I believe it does not spawn a shell)

CruzanCaramele avatar Jul 14 '24 09:07 CruzanCaramele