astral-sh / uv

An extremely fast Python package and project manager, written in Rust.
https://docs.astral.sh/uv
Apache License 2.0
20.75k stars 614 forks source link

Add `uv init --from-project <path>` to import from other tools #6277

Open zanieb opened 1 month ago

zanieb commented 1 month ago

As previously discussed for uv add -r pyproject.toml but without any of the controversy about what to do with extras. We can copy all of the dependencies as reported by the build backend.

charliermarsh commented 1 month ago

I'll look into this tonight unless someone beats me to it.

charliermarsh commented 1 month ago

I have no idea why I closed this.

charliermarsh commented 1 month ago

Related: https://github.com/astral-sh/uv/issues/6164

blueraft commented 1 month ago

Is this up for grabs?

charliermarsh commented 1 month ago

Yes!

charliermarsh commented 1 month ago

You can use SourceTreeResolver to get the metadata. But one challenge is... we probably need to preserve extras rather than resolving them. For example, if the user's pyproject.toml has:

[project.optional-dependencies]
foo = "bar"

Then in the project we create, we'd also want to create a foo extra with bar in it.

blueraft commented 1 month ago

I'll take a look soon.

we'd also want to create a foo extra with bar in it.

This makes sense, a similar PR would then resolve #6164 right?

charliermarsh commented 1 month ago

Yeah, it's possible that we want to skip #6164 for now since it brings up some confusing questions, like what does --extra mean in uv add --extra baz -r pyproject.toml. So let's start with support here in uv init.

mrijken commented 3 weeks ago

What is needed to get this merged/released? It will help converting a lot of users from Poetry to UV, at least for companies which have large number of repo's.

mrcljx commented 4 days ago

Shameless plug (in case someone stumbles over this issue here and --from-project is still WIP): I wrote a script to migrate our Poetry monorepo project to uv (keeping versions pinned). I doubt it will work immediately on other projects, but could be a good start.

https://gist.github.com/mrcljx/8e99a7f9fb924a573416f4365ee15873